- Made miniswig support HSQUIRRELVM arguments (and realized it was not needed
[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         yylval->atomic_type = ns->_findType(yytext, search_down);
53         if(yylval->atomic_type)
54             return T_ATOMIC_TYPE;
55         // or a namespace? (hack for now...)
56         yylval->_namespace = ns->_findNamespace(yytext, search_down);
57         if(yylval->_namespace) {
58             return T_NAMESPACEREF;
59         }
60         // a new ID
61         yylval->str = strdup(yytext);
62         return T_ID;
63 }
64 \:\:                                    { return T_DDCOL; }
65 [0-9]+                                  { 
66                                             yylval->ival = atoi(yytext);
67                                             return T_INT;
68                                         }
69 [0-9]*\.[0-9]+(e[0-9]+)?                { 
70                                             yylval->fval = atof(yytext);
71                                             return T_FLOAT;
72                                         }
73 \".*\"                                  {
74                                             yylval->str = strdup(yytext);
75                                             return T_STRING;
76                                         }
77 .                                       { return yytext[0]; }
78
79 %%
80