Support mixed type registrations and enum definitions in codegen, needed for enums.h.
[qtgstreamer:qtgstreamer.git] / codegen / analyzer.l
1 /*
2     Copyright (C) 2010  George Kiagiadakis <kiagiadakis.george@gmail.com>
3
4     This library is free software; you can redistribute it and/or modify
5     it under the terms of the GNU Lesser General Public License as published
6     by the Free Software Foundation; either version 2.1 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU Lesser General Public License
15     along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 */
17 %{
18 #include "yystype.h"
19 #include "generator.h"
20
21 #define YY_DECL int yylex(CodeGen *codegen)
22 void yyerror(CodeGen *codegen, const char *msg);
23
24 %}
25 %option noyywrap
26 %option yylineno
27 %option stack
28
29 id      [a-zA-Z][a-zA-Z_0-9]*
30
31 %x REGISTER_TYPE
32 %x ENUM
33 %x ENUM_EAT_ASSIGNMENT
34 %x INSTRUCTION
35 %x LINE_COMMENT
36 %x C_STYLE_COMMENT
37 %x NAMESPACE
38 %x CLASS
39 %x EAT_TEMPLATE
40
41 %%
42
43 <REGISTER_TYPE,ENUM,INSTRUCTION>{id} { yylval.Id = new QByteArray(yytext); return IDENTIFIER;  }
44
45 QGLIB_REGISTER_TYPE\(    { yy_push_state(REGISTER_TYPE); return REGISTER_TYPE_BEGIN; }
46 <REGISTER_TYPE>{
47     ::                   { return SCOPE_RESOLUTION_OPERATOR; }
48     \)                   { yy_pop_state(); return REGISTER_TYPE_END; }
49     [[:space:]]*
50     .                    { yyerror(codegen, "Syntax error in QGLIB_REGISTER_TYPE"); }
51 }
52
53 enum                     { yy_push_state(ENUM); return ENUM_KEYWORD; }
54 <ENUM>{
55     \{                   { return LEFT_BRACE; }
56     \}                   { return RIGHT_BRACE; }
57     ,                    { return COMMA; }
58     =                    { yy_push_state(ENUM_EAT_ASSIGNMENT); }
59     ;                    { yy_pop_state(); return SEMICOLON; }
60     [[:space:]]*
61     .                    { yyerror(codegen, "Syntax error in enum definition"); }
62 }
63
64 <ENUM_EAT_ASSIGNMENT>{
65     ,                    { unput(','); yy_pop_state(); }
66     \}                   { unput('}'); yy_pop_state(); }
67     \n
68     .
69 }
70
71 <*>\/\/                  { yy_push_state(LINE_COMMENT); }
72 <LINE_COMMENT>{
73     \n                   { yy_pop_state(); }
74     codegen:             { yy_push_state(INSTRUCTION); return INSTRUCTIONS_BEGIN; }
75     .
76 }
77
78 <INSTRUCTION>{
79     \n                   { unput('\n'); yy_pop_state(); return INSTRUCTIONS_END; }
80     =                    { return INSTRUCTIONS_ASSIGN_OPERATOR; }
81     ,                    { return INSTRUCTIONS_SEPARATOR; }
82     [[:space:]]
83     .                    { yyerror(codegen, "Syntax error in instruction comment"); }
84 }
85
86 <*>\/\*                  { yy_push_state(C_STYLE_COMMENT); }
87 <C_STYLE_COMMENT>{
88     \*\/                 { yy_pop_state(); }
89     \n
90     .
91 }
92
93 namespace                { yy_push_state(NAMESPACE); }
94 <NAMESPACE>{
95     {id}                 { codegen->setCurrentNameSpace(yytext); yy_pop_state(); }
96     [[:space:]]*
97     .                    { yyerror(codegen, "Expected identifier after namespace keyword"); }
98 }
99
100 class                    { yy_push_state(CLASS); }
101 <CLASS>{
102     {id}                 { codegen->setCurrentClass(yytext); yy_pop_state(); }
103     [[:space:]]*
104     .                    { yyerror(codegen, "Expected identifier after class keyword"); }
105 }
106
107 template[[:space:]]*\<   { yy_push_state(EAT_TEMPLATE); }
108 <EAT_TEMPLATE>{
109     \<                   { yy_push_state(EAT_TEMPLATE); };
110     \>                   { yy_pop_state(); }
111     \n
112     .
113 }
114
115 <*><<EOF>>               { return EOF; }
116 \n
117 .
118
119 %%
120