- Changed DocBook version to 4.3, 5.0 is not officially released yet and most
[supertux.git] / tools / miniswig / lexer.ll
1 %{
2 #include <math.h>
3 #include <stdlib.h>
4 #include <string.h>
5 #include <iostream>
6 #include "tree.h"
7 #include "parser.hpp"
8 #include "globals.h"
9
10 #define YY_DECL int yylex(YYSTYPE* yylval)
11
12 #define YY_INPUT(buf, result, max_size)                     \
13 {                                                           \
14     input->read(buf, max_size);                             \
15     result = input->gcount();                               \
16 }
17
18 std::string last_docucomment;
19 std::string original_file;
20 std::string current_file;
21 int offset_lnum;
22
23 int getCurrentLine()
24 {
25     return yylineno - offset_lnum;
26 }
27     
28 %}
29
30 %option noyywrap
31 %option yylineno
32 /* %option never-interactive */
33
34 %%
35
36 #[ \t]+[0-9]+[ \t]+.*                         {
37     int lnum;
38     char file[1024];
39     if(sscanf(yytext, "# %d \"%1023[^\"]\"", &lnum, file) == 2) {
40         offset_lnum = yylineno - lnum + 1;
41         current_file = file;
42         if(original_file == "")
43             original_file = file;
44     } else {
45         std::cerr << "Warning: Parse error in processor info directive.\n";
46     }
47 }
48 #.*                                     /* ignore preprocessor directives */
49 [[:space:]]+                            /* eat spaces */
50 \/\*.*\*\/                              {
51     if(yytext[2] == '*' && yytext[3] != '/') { // It's a docu comment...
52         last_docucomment = std::string(yytext+3, strlen(yytext)-5);
53     }
54 }
55 \/\/[^\n]*\n                            {
56     if(yytext[2] == '/') { // it's a docu comment...
57         last_docucomment = std::string(yytext+3, strlen(yytext)-4);
58     }
59 }
60 class                                   { return T_CLASS; }
61 struct                                  { return T_STRUCT; }
62 static                                  { return T_STATIC; }
63 virtual                                 { return T_VIRTUAL; }
64 const                                   { return T_CONST; }
65 unsigned                                { return T_UNSIGNED; }
66 signed                                  { return T_SIGNED; }
67 void                                    { return T_VOID; }
68 bool                                    { return T_BOOL; }
69 char                                    { return T_CHAR; }
70 short                                   { return T_SHORT; }
71 int                                     { return T_INT; }
72 long                                    { return T_LONG; }
73 float                                   { return T_FLOAT; }
74 double                                  { return T_DOUBLE; }
75 public                                  { return T_PUBLIC; }
76 protected                               { return T_PROTECTED; }
77 private                                 { return T_PRIVATE; }
78 namespace                               { return T_NAMESPACE; }
79 [a-zA-Z_][a-zA-Z_0-9]*                  {
80         Namespace* ns = search_namespace;
81         if(ns == 0)
82             ns = current_namespace;          
83         // is it a type?
84         yylval->atomic_type = ns->_findType(yytext, search_down);
85         if(yylval->atomic_type)
86             return T_ATOMIC_TYPE;
87         // or a namespace? (hack for now...)
88         yylval->_namespace = ns->_findNamespace(yytext, search_down);
89         if(yylval->_namespace) {
90             return T_NAMESPACEREF;
91         }
92         // a new ID
93         yylval->str = strdup(yytext);
94         return T_ID;
95 }
96 \:\:                                    { return T_DDCOL; }
97 [0-9]+                                  { 
98                                             yylval->ival = atoi(yytext);
99                                             return T_INT;
100                                         }
101 [0-9]*\.[0-9]+(e[0-9]+)?                { 
102                                             yylval->fval = atof(yytext);
103                                             return T_FLOAT;
104                                         }
105 \".*\"                                  {
106                                             yylval->str = strdup(yytext);
107                                             return T_STRING;
108                                         }
109 .                                       { return yytext[0]; }
110
111 %%
112