reworked miniswig a bit to support virtual functions and to only emit constructors...
[supertux.git] / tools / miniswig / lexer.ll
1 %{
2 #include <math.h>
3 #include <stdlib.h>
4 #include "tree.h"
5 #include "parser.hpp"
6 #include "globals.h"
7
8 #define YY_DECL int yylex YY_PROTO(( YYSTYPE* yylval ))
9
10 #define YY_INPUT(buf, result, max_size)                     \
11 {                                                           \
12     input->read(buf, max_size);                             \
13     result = input->gcount();                               \
14 }
15     
16 %}
17
18 %option noyywrap
19 %option yylineno
20 /* %option never-interactive */
21
22 %%
23
24 #.*                                     /* ignore preprocessor directives */
25 [[:space:]]+                            /* eat spaces */
26 \/\*.*\*\/                              /* eat comment */
27 \/\/[^\n]*\n                            /* eat comment */        
28 class                                   { return T_CLASS; }
29 struct                                  { return T_STRUCT; }
30 static                                  { return T_STATIC; }
31 virtual                                 { return T_VIRTUAL; }
32 const                                   { return T_CONST; }
33 unsigned                                { return T_UNSIGNED; }
34 signed                                  { return T_SIGNED; }
35 void                                    { return T_VOID; }
36 bool                                    { return T_BOOL; }
37 char                                    { return T_CHAR; }
38 short                                   { return T_SHORT; }
39 int                                     { return T_INT; }
40 long                                    { return T_LONG; }
41 float                                   { return T_FLOAT; }
42 double                                  { return T_DOUBLE; }
43 public                                  { return T_PUBLIC; }
44 protected                               { return T_PROTECTED; }
45 private                                 { return T_PRIVATE; }
46 namespace                               { return T_NAMESPACE; }
47 [a-zA-Z_][a-zA-Z_0-9]*                  {
48         Namespace* ns = search_namespace;
49         if(ns == 0)
50             ns = current_namespace;          
51         // is it a type?
52         for(std::vector<AtomicType*>::iterator i = ns->types.begin();
53                 i != ns->types.end(); ++i) {
54             AtomicType* type = *i;
55             if(type->name == yytext) {
56                 yylval->atomic_type = type;
57                 return T_ATOMIC_TYPE;
58             }
59         }
60         // or a namespace? (hack for now...)
61         yylval->_namespace = ns->_findNamespace(yytext, search_down);
62         if(yylval->_namespace) {
63             return T_NAMESPACEREF;
64         }
65         // a new ID
66         yylval->str = strdup(yytext);
67         return T_ID;
68 }
69 \:\:                                    { return T_DDCOL; }
70 [0-9]+                                  { 
71                                             yylval->ival = atoi(yytext);
72                                             return T_INT;
73                                         }
74 [0-9]*\.[0-9]+(e[0-9]+)?                { 
75                                             yylval->fval = atof(yytext);
76                                             return T_FLOAT;
77                                         }
78 \".*\"                                  {
79                                             yylval->str = strdup(yytext);
80                                             return T_STRING;
81                                         }
82 .                                       { return yytext[0]; }
83
84 %%
85