- More work on scripting interface
[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 const                                   { return T_CONST; }
32 unsigned                                { return T_UNSIGNED; }
33 signed                                  { return T_SIGNED; }
34 void                                    { return T_VOID; }
35 bool                                    { return T_BOOL; }
36 char                                    { return T_CHAR; }
37 short                                   { return T_SHORT; }
38 int                                     { return T_INT; }
39 long                                    { return T_LONG; }
40 float                                   { return T_FLOAT; }
41 double                                  { return T_DOUBLE; }
42 public                                  { return T_PUBLIC; }
43 protected                               { return T_PROTECTED; }
44 private                                 { return T_PRIVATE; }
45 namespace                               { return T_NAMESPACE; }
46 [a-zA-Z_][a-zA-Z_0-9]*                  {
47         Namespace* ns = search_namespace;
48         if(ns == 0)
49             ns = current_namespace;          
50         // is it a type?
51         for(std::vector<AtomicType*>::iterator i = ns->types.begin();
52                 i != ns->types.end(); ++i) {
53             AtomicType* type = *i;
54             if(type->name == yytext) {
55                 yylval->atomic_type = type;
56                 return T_ATOMIC_TYPE;
57             }
58         }
59         // or a namespace? (hack for now...)
60         yylval->_namespace = ns->_findNamespace(yytext, search_down);
61         if(yylval->_namespace) {
62             return T_NAMESPACEREF;
63         }
64         // a new ID
65         yylval->str = strdup(yytext);
66         return T_ID;
67 }
68 \:\:                                    { return T_DDCOL; }
69 [0-9]+                                  { 
70                                             yylval->ival = atoi(yytext);
71                                             return T_INT;
72                                         }
73 [0-9]*\.[0-9]+(e[0-9]+)?                { 
74                                             yylval->fval = atof(yytext);
75                                             return T_FLOAT;
76                                         }
77 \".*\"                                  {
78                                             yylval->str = strdup(yytext);
79                                             return T_STRING;
80                                         }
81 .                                       { return yytext[0]; }
82
83 %%
84