change some LAYER_GUI to LAYER_HUD, update tinygettext, fix a warning in miniswig
[supertux.git] / tools / miniswig / parser.yy
index 0de8f6c..e609476 100644 (file)
@@ -1,4 +1,5 @@
 %{
+#include <config.h>
 
 #include <iostream>
 #include <sstream>
@@ -34,12 +35,13 @@ static Class* current_class = 0;
 static Function* current_function = 0;
 static Type* current_type = 0;
 static Field* current_field = 0;
-static ClassMember::Visbility current_visibility;
+static ClassMember::Visibility current_visibility;
 
 class ParseError : public std::exception
 {
 public:
-    ParseError(const std::string& message) throw()
+    ParseError(const std::string& message) throw() :
+         message()
     {
         std::ostringstream msg;
         msg << "Parse error in '" << current_file
@@ -69,6 +71,8 @@ private:
 %token T_CLASS
 %token T_STRUCT
 %token T_STATIC
+%token T_SUSPEND
+%token T_CUSTOM
 %token T_CONST
 %token T_UNSIGNED
 %token T_SIGNED
@@ -76,9 +80,7 @@ private:
 %token T_BOOL
 %token T_CHAR
 %token T_SHORT
-%token T_INT
 %token T_LONG
-%token T_FLOAT
 %token T_DOUBLE
 %token T_PUBLIC
 %token T_PROTECTED
@@ -141,7 +143,7 @@ namespace_member:
 ;  
 
 class_declaration:
-    T_CLASS T_ID '{' 
+    T_CLASS T_ID 
         {
             current_class = new Class();
             current_class->name = $2;
@@ -150,12 +152,39 @@ class_declaration:
             last_docucomment = "";
             current_visibility = ClassMember::PROTECTED;
         }
-    class_body '}' ';'
+    superclass_list '{' class_body '}' ';'
         {
             $$ = current_class;
         }
 ;
 
+superclass_list:
+    /* empty */
+    | ':' superclasses
+;
+
+superclasses:
+      superclass
+    | superclasses ',' superclass
+;
+
+superclass:
+    superclass_visibility type_identifier
+        {
+            Class* superclass = dynamic_cast<Class*> ($2);
+            if(superclass == 0)
+                throw ParseError("SuperClass is not a Class type");
+            current_class->super_classes.push_back(superclass);
+            superclass->sub_classes.push_back(current_class);
+        }
+;
+
+superclass_visibility:
+    T_PUBLIC
+    | T_PROTECTED
+    | T_PRIVATE
+;
+
 class_body: /* empty */
         | class_body class_body_element
 ;
@@ -225,6 +254,8 @@ field_declaration:
         {
             current_field = new Field();
             current_field->type = $1;
+            current_field->docu_comment = last_docucomment;
+            last_docucomment = "";
             current_field->name = $2;
             free($2);
         }
@@ -260,17 +291,6 @@ maybe_const_initialisation:
 function_declaration:
     type T_ID '(' 
         {
-            /*
-            current_function = new Function();
-            current_function->type = Function::FUNCTION;
-            current_function->return_type = *($2);
-            delete $2;
-            current_function->name = $3;
-            free($3);
-            current_function->docu_comment = last_docucomment;
-            last_docucomment = "";
-            */
-
             current_function = new Function();
             current_function->type = Function::FUNCTION;
             current_function->return_type = *($1);
@@ -280,12 +300,26 @@ function_declaration:
             current_function->docu_comment = last_docucomment;
             last_docucomment = "";
         }                           
-    parameter_list ')' abstract_declaration ';'
+    parameter_list ')' function_attributes abstract_declaration ';'
         {
             $$ = current_function;
         }
 ;
 
+function_attributes:
+    /* empty */
+    | T_CONST function_attributes
+    | T_CUSTOM '(' T_STRING ')' function_attributes
+      {
+        current_function->parameter_spec = $3;
+        current_function->custom = true;
+      }
+    | T_SUSPEND function_attributes
+      {
+        current_function->suspend = true;
+      }
+;
+
 abstract_declaration:
     /* empty */
     | '=' T_INT
@@ -384,7 +418,6 @@ atomic_type:
 type_identifier:
     T_ATOMIC_TYPE
         {
-            // search for type in current compilation unit...
             $$ = $1;
         }
     | namespace_refs "::" T_ATOMIC_TYPE
@@ -409,6 +442,7 @@ namespace_refs:
 
 %%
 
+__attribute__((noreturn))
 void yyerror(const char* error)
 {
     throw ParseError(error);