don't leave classname lyingf around on stack
[supertux.git] / tools / miniswig / lexer.ll
index 8a2e9a6..ac699ab 100644 (file)
@@ -3,10 +3,11 @@
 #include <stdlib.h>
 #include <string.h>
 #include <iostream>
-#include "tree.h"
+#include "tree.hpp"
 #include "parser.hpp"
-#include "globals.h"
+#include "globals.hpp"
 
+#define YY_NEVER_INTERACTIVE 1
 #define YY_DECL int yylex(YYSTYPE* yylval)
 
 #define YY_INPUT(buf, result, max_size)                     \
@@ -18,6 +19,7 @@
 std::string last_docucomment;
 std::string original_file;
 std::string current_file;
+std::string comm;
 int offset_lnum;
 
 int getCurrentLine()
@@ -31,6 +33,7 @@ int getCurrentLine()
 %option yylineno
 /* %option never-interactive */
 
+%x comment
 %%
 
 #[ \t]+[0-9]+[ \t]+.*                         {
@@ -47,9 +50,24 @@ int getCurrentLine()
 }
 #.*                                     /* ignore preprocessor directives */
 [[:space:]]+                            /* eat spaces */
-\/\*.*\*\/                              {
-    if(yytext[2] == '*' && yytext[3] != '/') { // It's a docu comment...
-        last_docucomment = std::string(yytext+3, strlen(yytext)-5);
+"/*"                                    { BEGIN(comment); comm = ""; }
+<comment>[^*\n]*                        { comm += yytext; }
+<comment>"*"+[^*/]*                     { comm += yytext; }
+<comment>"*/"                    {
+    BEGIN(INITIAL);
+    if(comm[0] == '*') { // It's a docu comment...
+        last_docucomment = "";
+        bool linestart = true;
+        for(size_t i = 1; i < comm.size(); ++i) {
+            if(linestart && (comm[i] == '*' || isspace(comm[i]))) {
+                continue;
+            } else if(comm[i] == '\n') {
+                linestart = true;
+            } else {
+                linestart = false;
+            }
+            last_docucomment += comm[i];
+        }
     }
 }
 \/\/[^\n]*\n                            {
@@ -60,7 +78,7 @@ int getCurrentLine()
 class                                   { return T_CLASS; }
 struct                                  { return T_STRUCT; }
 static                                  { return T_STATIC; }
-virtual                                 { return T_VIRTUAL; }
+virtual                                 { }
 const                                   { return T_CONST; }
 unsigned                                { return T_UNSIGNED; }
 signed                                  { return T_SIGNED; }
@@ -82,8 +100,9 @@ namespace                               { return T_NAMESPACE; }
             ns = current_namespace;          
         // is it a type?
         yylval->atomic_type = ns->_findType(yytext, search_down);
-        if(yylval->atomic_type)
+        if(yylval->atomic_type) {
             return T_ATOMIC_TYPE;
+        }
         // or a namespace? (hack for now...)
         yylval->_namespace = ns->_findNamespace(yytext, search_down);
         if(yylval->_namespace) {
@@ -94,18 +113,18 @@ namespace                               { return T_NAMESPACE; }
         return T_ID;
 }
 \:\:                                    { return T_DDCOL; }
-[0-9]+                                  { 
-                                            yylval->ival = atoi(yytext);
-                                            return T_INT;
-                                        }
-[0-9]*\.[0-9]+(e[0-9]+)?                
-                                            yylval->fval = atof(yytext);
-                                            return T_FLOAT;
-                                        }
-\".*\"                                  {
-                                            yylval->str = strdup(yytext);
-                                            return T_STRING;
-                                        }
+(0x)?[0-9]+ {
+        sscanf(yytext, "%i", &(yylval->ival));
+        return T_INT;
+}
+[0-9]*\.[0-9]+(e[0-9]+)? { 
+        sscanf(yytext, "%f", &(yylval->fval));
+        return T_FLOAT;
+}
+\".*\" {
+        yylval->str = strdup(yytext);
+        return T_STRING;
+}
 .                                       { return yytext[0]; }
 
 %%