-rw-r--r-- | lib/sitecing_parser.ll | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/lib/sitecing_parser.ll b/lib/sitecing_parser.ll index 4fd6709..8dd8d5f 100644 --- a/lib/sitecing_parser.ll +++ b/lib/sitecing_parser.ll | |||
@@ -1,561 +1,562 @@ | |||
1 | %{ | 1 | %{ |
2 | /* | 2 | /* |
3 | * XXX: I have a strong feeling that this parser should be completely rewritten. | 3 | * XXX: I have a strong feeling that this parser should be completely rewritten. |
4 | */ | 4 | */ |
5 | #include <iostream> | 5 | #include <iostream> |
6 | #include <fstream> | 6 | #include <fstream> |
7 | #include <cassert> | 7 | #include <cassert> |
8 | #include <stdexcept> | 8 | #include <stdexcept> |
9 | using namespace std; | 9 | using namespace std; |
10 | #include <konforka/util.h> | ||
10 | #include "sitecing/sitecing_util.h" | 11 | #include "sitecing/sitecing_util.h" |
11 | #include "sitecing/sitecing_exception.h" | 12 | #include "sitecing/sitecing_exception.h" |
12 | using namespace sitecing; | 13 | using namespace sitecing; |
13 | #define sitecing_parser_flexlexer_once | 14 | #define sitecing_parser_flexlexer_once |
14 | #include "sitecing/sitecing_parser.h" | 15 | #include "sitecing/sitecing_parser.h" |
15 | #include "sitecing/sitecing_enflesher.h" | 16 | #include "sitecing/sitecing_enflesher.h" |
16 | #undef yyFlexLexer | 17 | #undef yyFlexLexer |
17 | #define yyFlexLexer sitecing_parserFlexLexer | 18 | #define yyFlexLexer sitecing_parserFlexLexer |
18 | %} | 19 | %} |
19 | %x SLASHSTAR_COMMENT SLASHSLASH_COMMENT STRING | 20 | %x SLASHSTAR_COMMENT SLASHSLASH_COMMENT STRING |
20 | %x CODELINE CLASSLINE DECLLINE IMPLLINE DECLBLOCK IMPLBLOCK VARLINE VARINIT | 21 | %x CODELINE CLASSLINE DECLLINE IMPLLINE DECLBLOCK IMPLBLOCK VARLINE VARINIT |
21 | %x IMPORTLINE IMPORTCOMPONENT | 22 | %x IMPORTLINE IMPORTCOMPONENT |
22 | %x IMPORTTYPELINE IMPORTTYPECOMPONENT | 23 | %x IMPORTTYPELINE IMPORTTYPECOMPONENT |
23 | %x DERIVELINE DERIVECOMPONENT | 24 | %x DERIVELINE DERIVECOMPONENT |
24 | %x CONSTRUCTOR DESTRUCTOR CODEMETHODLINE CODEMETHODARGS | 25 | %x CONSTRUCTOR DESTRUCTOR CODEMETHODLINE CODEMETHODARGS |
25 | %x CODEMETHODBLOCK INLINE METHODLINE METHODARGS METHODBLOCK CODEBLOCK OUTPUTBLOCK | 26 | %x CODEMETHODBLOCK INLINE METHODLINE METHODARGS METHODBLOCK CODEBLOCK OUTPUTBLOCK |
26 | %x PRAGMALINE | 27 | %x PRAGMALINE |
27 | %option 8bit c++ verbose noyywrap yyclass="sitecing_parser" prefix="sitecing_parser" stack yylineno | 28 | %option 8bit c++ verbose noyywrap yyclass="sitecing_parser" prefix="sitecing_parser" stack yylineno |
28 | 29 | ||
29 | WHITESPACE[ \t] | 30 | WHITESPACE[ \t] |
30 | ID [A-Za-z_][A-Za-z0-9_]* | 31 | ID [A-Za-z_][A-Za-z0-9_]* |
31 | NOIDCHAR[^A-Za-z0-9_] | 32 | NOIDCHAR[^A-Za-z0-9_] |
32 | 33 | ||
33 | %% | 34 | %% |
34 | 35 | ||
35 | <INITIAL>{ | 36 | <INITIAL>{ |
36 | ^\%\%class{WHITESPACE}+{ | 37 | ^\%\%class{WHITESPACE}+{ |
37 | // TODO: signal error if we already have class name acquired from source. | 38 | // TODO: signal error if we already have class name acquired from source. |
38 | modi.push_front(modus_operandi(modus_operandi::flag_devour_comments|modus_operandi::flag_devour_whitespace)); | 39 | modi.push_front(modus_operandi(modus_operandi::flag_devour_comments|modus_operandi::flag_devour_whitespace)); |
39 | BEGIN(CLASSLINE); | 40 | BEGIN(CLASSLINE); |
40 | } | 41 | } |
41 | ^\%\%decl{WHITESPACE}+{ | 42 | ^\%\%decl{WHITESPACE}+{ |
42 | modi.push_front(modus_operandi(0)); | 43 | modi.push_front(modus_operandi(0)); |
43 | anchor(); | 44 | anchor(); |
44 | BEGIN(DECLLINE); | 45 | BEGIN(DECLLINE); |
45 | } | 46 | } |
46 | ^\%\%impl{WHITESPACE}+{ | 47 | ^\%\%impl{WHITESPACE}+{ |
47 | modi.push_front(modus_operandi(0)); | 48 | modi.push_front(modus_operandi(0)); |
48 | anchor(); | 49 | anchor(); |
49 | BEGIN(IMPLLINE); | 50 | BEGIN(IMPLLINE); |
50 | } | 51 | } |
51 | \<\%decl\> { | 52 | \<\%decl\> { |
52 | modi.push_front(modus_operandi(0)); | 53 | modi.push_front(modus_operandi(0)); |
53 | anchor(); | 54 | anchor(); |
54 | BEGIN(DECLBLOCK); | 55 | BEGIN(DECLBLOCK); |
55 | } | 56 | } |
56 | \<\%impl\> { | 57 | \<\%impl\> { |
57 | modi.push_front(modus_operandi(0)); | 58 | modi.push_front(modus_operandi(0)); |
58 | anchor(); | 59 | anchor(); |
59 | BEGIN(IMPLBLOCK); | 60 | BEGIN(IMPLBLOCK); |
60 | } | 61 | } |
61 | ^\%\%var{WHITESPACE}+{ | 62 | ^\%\%var{WHITESPACE}+{ |
62 | modi.push_front(modus_operandi(modus_operandi::flag_devour_comments)); | 63 | modi.push_front(modus_operandi(modus_operandi::flag_devour_comments)); |
63 | anchor(); | 64 | anchor(); |
64 | BEGIN(VARLINE); | 65 | BEGIN(VARLINE); |
65 | } | 66 | } |
66 | ^\%\%import{WHITESPACE}+{ | 67 | ^\%\%import{WHITESPACE}+{ |
67 | modi.push_front(modus_operandi(modus_operandi::flag_devour_comments)); | 68 | modi.push_front(modus_operandi(modus_operandi::flag_devour_comments)); |
68 | BEGIN(IMPORTLINE); | 69 | BEGIN(IMPORTLINE); |
69 | } | 70 | } |
70 | ^\%\%import_type{WHITESPACE}+ { | 71 | ^\%\%import_type{WHITESPACE}+ { |
71 | modi.push_front(modus_operandi(modus_operandi::flag_devour_comments)); | 72 | modi.push_front(modus_operandi(modus_operandi::flag_devour_comments)); |
72 | BEGIN(IMPORTTYPELINE); | 73 | BEGIN(IMPORTTYPELINE); |
73 | } | 74 | } |
74 | ^\%\%derive{WHITESPACE}+{ | 75 | ^\%\%derive{WHITESPACE}+{ |
75 | modi.push_front(modus_operandi(modus_operandi::flag_devour_comments)); | 76 | modi.push_front(modus_operandi(modus_operandi::flag_devour_comments)); |
76 | BEGIN(DERIVELINE); | 77 | BEGIN(DERIVELINE); |
77 | } | 78 | } |
78 | \<\%constructor\>{ | 79 | \<\%constructor\>{ |
79 | modi.push_front(modus_operandi()); | 80 | modi.push_front(modus_operandi()); |
80 | anchor(); | 81 | anchor(); |
81 | BEGIN(CONSTRUCTOR); | 82 | BEGIN(CONSTRUCTOR); |
82 | } | 83 | } |
83 | \<\%destructor\>{ | 84 | \<\%destructor\>{ |
84 | modi.push_front(modus_operandi()); | 85 | modi.push_front(modus_operandi()); |
85 | anchor(); | 86 | anchor(); |
86 | BEGIN(DESTRUCTOR); | 87 | BEGIN(DESTRUCTOR); |
87 | } | 88 | } |
88 | \<\%codemethod{WHITESPACE}+{ | 89 | \<\%codemethod{WHITESPACE}+{ |
89 | modi.push_front(modus_operandi(modus_operandi::flag_devour_comments)); | 90 | modi.push_front(modus_operandi(modus_operandi::flag_devour_comments)); |
90 | anchor(); | 91 | anchor(); |
91 | BEGIN(CODEMETHODLINE); | 92 | BEGIN(CODEMETHODLINE); |
92 | } | 93 | } |
93 | \<\%method{WHITESPACE}+ { | 94 | \<\%method{WHITESPACE}+ { |
94 | modi.push_front(modus_operandi(modus_operandi::flag_devour_comments)); | 95 | modi.push_front(modus_operandi(modus_operandi::flag_devour_comments)); |
95 | anchor(); | 96 | anchor(); |
96 | BEGIN(METHODLINE); | 97 | BEGIN(METHODLINE); |
97 | } | 98 | } |
98 | ^\%\%pragma{WHITESPACE}+{ | 99 | ^\%\%pragma{WHITESPACE}+{ |
99 | modi.push_front(modus_operandi(modus_operandi::flag_devour_comments)); | 100 | modi.push_front(modus_operandi(modus_operandi::flag_devour_comments)); |
100 | BEGIN(PRAGMALINE); | 101 | BEGIN(PRAGMALINE); |
101 | } | 102 | } |
102 | <<EOF>>{ | 103 | <<EOF>>{ |
103 | assert(modi.size()==1); | 104 | assert(modi.size()==1); |
104 | M().modify(modus_operandi::modus_preop); | 105 | M().modify(modus_operandi::modus_preop); |
105 | LexerOutput(";",1); | 106 | LexerOutput(";",1); |
106 | return 0; | 107 | return 0; |
107 | } | 108 | } |
108 | } | 109 | } |
109 | <<EOF>>throw preprocessor_error(CODEPOINT,"unexpected end of file",lineno()); | 110 | <<EOF>>throw preprocessor_error(CODEPOINT,"unexpected end of file",lineno()); |
110 | 111 | ||
111 | <CODEBLOCK,CODEMETHODBLOCK>{ | 112 | <CODEBLOCK,CODEMETHODBLOCK>{ |
112 | "<%output>"{ | 113 | "<%output>"{ |
113 | anchor(); | 114 | anchor(); |
114 | yy_push_state(OUTPUTBLOCK); | 115 | yy_push_state(OUTPUTBLOCK); |
115 | } | 116 | } |
116 | } | 117 | } |
117 | 118 | ||
118 | <PRAGMALINE>{ | 119 | <PRAGMALINE>{ |
119 | {WHITESPACE}+{ | 120 | {WHITESPACE}+{ |
120 | modus_operandi& m = M(); | 121 | modus_operandi& m = M(); |
121 | if(!m.output.empty()) { | 122 | if(!m.output.empty()) { |
122 | string::size_type eq = m.output.find('='); | 123 | string::size_type eq = m.output.find('='); |
123 | if(eq==string::npos) { | 124 | if(eq==string::npos) { |
124 | pragmas[m.output]=m.output; | 125 | pragmas[m.output]=m.output; |
125 | }else{ | 126 | }else{ |
126 | pragmas[m.output.substr(0,eq)] = m.output.substr(eq+1); | 127 | pragmas[m.output.substr(0,eq)] = m.output.substr(eq+1); |
127 | } | 128 | } |
128 | m.output.erase(); | 129 | m.output.erase(); |
129 | } | 130 | } |
130 | } | 131 | } |
131 | \n { | 132 | \n { |
132 | modus_operandi& m = M(); | 133 | modus_operandi& m = M(); |
133 | if(!m.output.empty()) { | 134 | if(!m.output.empty()) { |
134 | string::size_type eq = m.output.find('='); | 135 | string::size_type eq = m.output.find('='); |
135 | if(eq==string::npos) { | 136 | if(eq==string::npos) { |
136 | pragmas[m.output]=m.output; | 137 | pragmas[m.output]=m.output; |
137 | }else{ | 138 | }else{ |
138 | pragmas[m.output.substr(0,eq)] = m.output.substr(eq+1); | 139 | pragmas[m.output.substr(0,eq)] = m.output.substr(eq+1); |
139 | } | 140 | } |
140 | m.output.erase(); | 141 | m.output.erase(); |
141 | } | 142 | } |
142 | modi.pop_front(); | 143 | modi.pop_front(); |
143 | BEGIN(INITIAL); | 144 | BEGIN(INITIAL); |
144 | anchor(); | 145 | anchor(); |
145 | } | 146 | } |
146 | } | 147 | } |
147 | 148 | ||
148 | <METHODLINE>{ | 149 | <METHODLINE>{ |
149 | {WHITESPACE}+{ | 150 | {WHITESPACE}+{ |
150 | modus_operandi& m = M(); | 151 | modus_operandi& m = M(); |
151 | if(!m.output.empty()) { | 152 | if(!m.output.empty()) { |
152 | if(!m._lastid.empty()) { | 153 | if(!m._lastid.empty()) { |
153 | if(!m._type.empty()) m._type += ' '; | 154 | if(!m._type.empty()) m._type += ' '; |
154 | m._type += m._lastid; | 155 | m._type += m._lastid; |
155 | } | 156 | } |
156 | m._lastid = m.output; | 157 | m._lastid = m.output; |
157 | m.output.clear(); | 158 | m.output.clear(); |
158 | } | 159 | } |
159 | } | 160 | } |
160 | \*{ | 161 | \*{ |
161 | modus_operandi& m = M(); | 162 | modus_operandi& m = M(); |
162 | ECHO; | 163 | ECHO; |
163 | if(!m._lastid.empty()) { | 164 | if(!m._lastid.empty()) { |
164 | if(!m._type.empty()) m._type += ' '; | 165 | if(!m._type.empty()) m._type += ' '; |
165 | m._type += m._lastid; | 166 | m._type += m._lastid; |
166 | } | 167 | } |
167 | m._lastid = m.output; | 168 | m._lastid = m.output; |
168 | m.output.clear(); | 169 | m.output.clear(); |
169 | } | 170 | } |
170 | \({ | 171 | \({ |
171 | modus_operandi& m = M(); | 172 | modus_operandi& m = M(); |
172 | if(m.output.empty()) { | 173 | if(m.output.empty()) { |
173 | m._name=m._lastid; | 174 | m._name=m._lastid; |
174 | }else{ | 175 | }else{ |
175 | if(!m._lastid.empty()) { // XXX: lastid, I believe should never be emtpy... | 176 | if(!m._lastid.empty()) { // XXX: lastid, I believe should never be emtpy... |
176 | if(!m._type.empty()) m._type += ' '; | 177 | if(!m._type.empty()) m._type += ' '; |
177 | m._type += m._lastid; | 178 | m._type += m._lastid; |
178 | } | 179 | } |
179 | m._name = m.output; | 180 | m._name = m.output; |
180 | m.output.clear(); | 181 | m.output.clear(); |
181 | } | 182 | } |
182 | ECHO; | 183 | ECHO; |
183 | BEGIN(METHODARGS); | 184 | BEGIN(METHODARGS); |
184 | } | 185 | } |
185 | } | 186 | } |
186 | <METHODARGS>{ | 187 | <METHODARGS>{ |
187 | \%\>{ | 188 | \%\>{ |
188 | modus_operandi& m = M(); | 189 | modus_operandi& m = M(); |
189 | m._args = m.output; | 190 | m._args = m.output; |
190 | m.output.clear(); | 191 | m.output.clear(); |
191 | anchor(); | 192 | anchor(); |
192 | BEGIN(METHODBLOCK); | 193 | BEGIN(METHODBLOCK); |
193 | } | 194 | } |
194 | } | 195 | } |
195 | 196 | ||
196 | <INITIAL,METHODBLOCK,OUTPUTBLOCK>{ | 197 | <INITIAL,METHODBLOCK,OUTPUTBLOCK>{ |
197 | \<\%{WHITESPACE}+{ | 198 | \<\%{WHITESPACE}+{ |
198 | M().modify(modus_operandi::modus_postop); | 199 | M().modify(modus_operandi::modus_postop); |
199 | anchor(); | 200 | anchor(); |
200 | LexerOutput("(",1); | 201 | LexerOutput("(",1); |
201 | yy_push_state(INLINE); | 202 | yy_push_state(INLINE); |
202 | } | 203 | } |
203 | ^\%{WHITESPACE}{ | 204 | ^\%{WHITESPACE}{ |
204 | M().modify(modus_operandi::modus_code); | 205 | M().modify(modus_operandi::modus_code); |
205 | anchor(); | 206 | anchor(); |
206 | yy_push_state(CODELINE); | 207 | yy_push_state(CODELINE); |
207 | } | 208 | } |
208 | \<\%code\>{ | 209 | \<\%code\>{ |
209 | M().modify(modus_operandi::modus_code); | 210 | M().modify(modus_operandi::modus_code); |
210 | anchor(); | 211 | anchor(); |
211 | yy_push_state(CODEBLOCK); | 212 | yy_push_state(CODEBLOCK); |
212 | } | 213 | } |
213 | "</%output>" { | 214 | "</%output>" { |
214 | if(YY_START!=OUTPUTBLOCK) throw preprocessor_error(CODEPOINT,"unexpected tag",lineno()); | 215 | if(YY_START!=OUTPUTBLOCK) throw preprocessor_error(CODEPOINT,"unexpected tag",lineno()); |
215 | M().modify(modus_operandi::modus_code); | 216 | M().modify(modus_operandi::modus_code); |
216 | anchor(); | 217 | anchor(); |
217 | yy_pop_state(); | 218 | yy_pop_state(); |
218 | } | 219 | } |
219 | } | 220 | } |
220 | 221 | ||
221 | <INLINE>\%\>LexerOutput(")",1); M().modus=modus_operandi::modus_preop; yy_pop_state(); | 222 | <INLINE>\%\>LexerOutput(")",1); M().modus=modus_operandi::modus_preop; yy_pop_state(); |
222 | <CODELINE>\nyy_pop_state(); | 223 | <CODELINE>\nyy_pop_state(); |
223 | 224 | ||
224 | <CODEMETHODLINE>{ | 225 | <CODEMETHODLINE>{ |
225 | {WHITESPACE}+{ | 226 | {WHITESPACE}+{ |
226 | modus_operandi& m = M(); | 227 | modus_operandi& m = M(); |
227 | if(!m.output.empty()) { | 228 | if(!m.output.empty()) { |
228 | if(!m._lastid.empty()) { | 229 | if(!m._lastid.empty()) { |
229 | if(!m._type.empty()) m._type += ' '; | 230 | if(!m._type.empty()) m._type += ' '; |
230 | m._type += m._lastid; | 231 | m._type += m._lastid; |
231 | } | 232 | } |
232 | m._lastid = m.output; | 233 | m._lastid = m.output; |
233 | m.output.clear(); | 234 | m.output.clear(); |
234 | } | 235 | } |
235 | } | 236 | } |
236 | \*{ | 237 | \*{ |
237 | modus_operandi& m = M(); | 238 | modus_operandi& m = M(); |
238 | ECHO; | 239 | ECHO; |
239 | if(!m._lastid.empty()) { | 240 | if(!m._lastid.empty()) { |
240 | if(!m._type.empty()) m._type += ' '; | 241 | if(!m._type.empty()) m._type += ' '; |
241 | m._type += m._lastid; | 242 | m._type += m._lastid; |
242 | } | 243 | } |
243 | m._lastid = m.output; | 244 | m._lastid = m.output; |
244 | m.output.clear(); | 245 | m.output.clear(); |
245 | } | 246 | } |
246 | \({ | 247 | \({ |
247 | modus_operandi& m = M(); | 248 | modus_operandi& m = M(); |
248 | if(m.output.empty()) { | 249 | if(m.output.empty()) { |
249 | m._name=m._lastid; | 250 | m._name=m._lastid; |
250 | }else{ | 251 | }else{ |
251 | if(!m._lastid.empty()) { // XXX: lastid, I believe should never be emtpy... | 252 | if(!m._lastid.empty()) { // XXX: lastid, I believe should never be emtpy... |
252 | if(!m._type.empty()) m._type += ' '; | 253 | if(!m._type.empty()) m._type += ' '; |
253 | m._type += m._lastid; | 254 | m._type += m._lastid; |
254 | } | 255 | } |
255 | m._name = m.output; | 256 | m._name = m.output; |
256 | m.output.clear(); | 257 | m.output.clear(); |
257 | } | 258 | } |
258 | ECHO; | 259 | ECHO; |
259 | BEGIN(CODEMETHODARGS); | 260 | BEGIN(CODEMETHODARGS); |
260 | } | 261 | } |
261 | } | 262 | } |
262 | <CODEMETHODARGS>{ | 263 | <CODEMETHODARGS>{ |
263 | \%\>{ | 264 | \%\>{ |
264 | modus_operandi& m = M(); | 265 | modus_operandi& m = M(); |
265 | m._args = m.output; | 266 | m._args = m.output; |
266 | m.output.clear(); | 267 | m.output.clear(); |
267 | m.flags=0; | 268 | m.flags=0; |
268 | anchor(); | 269 | anchor(); |
269 | BEGIN(CODEMETHODBLOCK); | 270 | BEGIN(CODEMETHODBLOCK); |
270 | } | 271 | } |
271 | } | 272 | } |
272 | 273 | ||
273 | <IMPORTLINE>{ | 274 | <IMPORTLINE>{ |
274 | {WHITESPACE}+{ } | 275 | {WHITESPACE}+{ } |
275 | {ID}{ | 276 | {ID}{ |
276 | modus_operandi& m = M(); | 277 | modus_operandi& m = M(); |
277 | if(!m._name.empty()) | 278 | if(!m._name.empty()) |
278 | throw preprocessor_error(CODEPOINT,"syntax error",lineno()); | 279 | throw preprocessor_error(CODEPOINT,"syntax error",lineno()); |
279 | m._name = yytext; | 280 | m._name = yytext; |
280 | } | 281 | } |
281 | \= { | 282 | \= { |
282 | M().output.clear(); | 283 | M().output.clear(); |
283 | BEGIN(IMPORTCOMPONENT); | 284 | BEGIN(IMPORTCOMPONENT); |
284 | } | 285 | } |
285 | } | 286 | } |
286 | <IMPORTCOMPONENT>{ | 287 | <IMPORTCOMPONENT>{ |
287 | {WHITESPACE}+{ } | 288 | {WHITESPACE}+{ } |
288 | \n{ | 289 | \n{ |
289 | modus_operandi& m = M(); | 290 | modus_operandi& m = M(); |
290 | string::size_type t = m.output.find_first_not_of(" \t"); | 291 | string::size_type t = m.output.find_first_not_of(" \t"); |
291 | if(t!=string::npos) | 292 | if(t!=string::npos) |
292 | m.output.erase(0,t); | 293 | m.output.erase(0,t); |
293 | t = m.output.find_last_not_of(" \t;"); | 294 | t = m.output.find_last_not_of(" \t;"); |
294 | if(t!=string::npos) | 295 | if(t!=string::npos) |
295 | m.output.erase(t+1); | 296 | m.output.erase(t+1); |
296 | if(m.output[0]=='"' && m.output[m.output.length()-1]=='"') { | 297 | if(m.output[0]=='"' && m.output[m.output.length()-1]=='"') { |
297 | m.output.erase(0,1); | 298 | m.output.erase(0,1); |
298 | m.output.erase(m.output.length()-1); | 299 | m.output.erase(m.output.length()-1); |
299 | } | 300 | } |
300 | string c = combine_path(component_basename,m.output); | 301 | string c = konforka::combine_path(component_basename,m.output); |
301 | member_variables.push_back(member_variable(m._type,m._name,normalize_path(c,strip_leading_slash),true)); | 302 | member_variables.push_back(member_variable(m._type,m._name,konforka::normalize_path(c,konforka::strip_leading_slash),true)); |
302 | modi.pop_front(); | 303 | modi.pop_front(); |
303 | BEGIN(INITIAL); | 304 | BEGIN(INITIAL); |
304 | } | 305 | } |
305 | } | 306 | } |
306 | 307 | ||
307 | <IMPORTTYPELINE>{ | 308 | <IMPORTTYPELINE>{ |
308 | {WHITESPACE}+{ } | 309 | {WHITESPACE}+{ } |
309 | {ID}{ | 310 | {ID}{ |
310 | modus_operandi& m = M(); | 311 | modus_operandi& m = M(); |
311 | if(!m._name.empty()) | 312 | if(!m._name.empty()) |
312 | throw preprocessor_error(CODEPOINT,"syntax error",lineno()); | 313 | throw preprocessor_error(CODEPOINT,"syntax error",lineno()); |
313 | m._name = yytext; | 314 | m._name = yytext; |
314 | } | 315 | } |
315 | \= { | 316 | \= { |
316 | M().output.clear(); | 317 | M().output.clear(); |
317 | BEGIN(IMPORTTYPECOMPONENT); | 318 | BEGIN(IMPORTTYPECOMPONENT); |
318 | } | 319 | } |
319 | } | 320 | } |
320 | <IMPORTTYPECOMPONENT>{ | 321 | <IMPORTTYPECOMPONENT>{ |
321 | {WHITESPACE}+{ } | 322 | {WHITESPACE}+{ } |
322 | \n{ | 323 | \n{ |
323 | modus_operandi& m = M(); | 324 | modus_operandi& m = M(); |
324 | string::size_type t = m.output.find_first_not_of(" \t"); | 325 | string::size_type t = m.output.find_first_not_of(" \t"); |
325 | if(t!=string::npos) | 326 | if(t!=string::npos) |
326 | m.output.erase(0,t); | 327 | m.output.erase(0,t); |
327 | t = m.output.find_last_not_of(" \t;"); | 328 | t = m.output.find_last_not_of(" \t;"); |
328 | if(t!=string::npos) | 329 | if(t!=string::npos) |
329 | m.output.erase(t+1); | 330 | m.output.erase(t+1); |
330 | if(m.output[0]=='"' && m.output[m.output.length()-1]=='"') { | 331 | if(m.output[0]=='"' && m.output[m.output.length()-1]=='"') { |
331 | m.output.erase(0,1); | 332 | m.output.erase(0,1); |
332 | m.output.erase(m.output.length()-1); | 333 | m.output.erase(m.output.length()-1); |
333 | } | 334 | } |
334 | string c = combine_path(component_basename,m.output); | 335 | string c = konforka::combine_path(component_basename,m.output); |
335 | member_variables.push_back(member_variable(m._type,m._name,normalize_path(c,strip_leading_slash),true,true)); | 336 | member_variables.push_back(member_variable(m._type,m._name,konforka::normalize_path(c,konforka::strip_leading_slash),true,true)); |
336 | modi.pop_front(); | 337 | modi.pop_front(); |
337 | BEGIN(INITIAL); | 338 | BEGIN(INITIAL); |
338 | } | 339 | } |
339 | } | 340 | } |
340 | 341 | ||
341 | <DERIVELINE>{ | 342 | <DERIVELINE>{ |
342 | {WHITESPACE}+{ } | 343 | {WHITESPACE}+{ } |
343 | {ID}{ | 344 | {ID}{ |
344 | modus_operandi& m = M(); | 345 | modus_operandi& m = M(); |
345 | if(!m._name.empty()) | 346 | if(!m._name.empty()) |
346 | throw preprocessor_error(CODEPOINT,"syntax_error",lineno()); | 347 | throw preprocessor_error(CODEPOINT,"syntax_error",lineno()); |
347 | m._name = yytext; | 348 | m._name = yytext; |
348 | } | 349 | } |
349 | \= { | 350 | \= { |
350 | M().output.clear(); | 351 | M().output.clear(); |
351 | BEGIN(DERIVECOMPONENT); | 352 | BEGIN(DERIVECOMPONENT); |
352 | } | 353 | } |
353 | } | 354 | } |
354 | <DERIVECOMPONENT>{ | 355 | <DERIVECOMPONENT>{ |
355 | {WHITESPACE}+{ } | 356 | {WHITESPACE}+{ } |
356 | \n { | 357 | \n { |
357 | modus_operandi& m = M(); | 358 | modus_operandi& m = M(); |
358 | string::size_type t = m.output.find_first_not_of(" \t"); | 359 | string::size_type t = m.output.find_first_not_of(" \t"); |
359 | if(t!=string::npos) | 360 | if(t!=string::npos) |
360 | m.output.erase(0,t); | 361 | m.output.erase(0,t); |
361 | t = m.output.find_last_not_of(" \t;"); | 362 | t = m.output.find_last_not_of(" \t;"); |
362 | if(t!=string::npos) | 363 | if(t!=string::npos) |
363 | m.output.erase(t+1); | 364 | m.output.erase(t+1); |
364 | if(m.output[0]=='"' && m.output[m.output.length()-1]=='"') { | 365 | if(m.output[0]=='"' && m.output[m.output.length()-1]=='"') { |
365 | m.output.erase(0,1); | 366 | m.output.erase(0,1); |
366 | m.output.erase(m.output.length()-1); | 367 | m.output.erase(m.output.length()-1); |
367 | } | 368 | } |
368 | string c = combine_path(component_basename,m.output); | 369 | string c = konforka::combine_path(component_basename,m.output); |
369 | ancestor_classes.push_back(ancestor_class(m._name,normalize_path(c,strip_leading_slash))); | 370 | ancestor_classes.push_back(ancestor_class(m._name,konforka::normalize_path(c,konforka::strip_leading_slash))); |
370 | modi.pop_front(); | 371 | modi.pop_front(); |
371 | BEGIN(INITIAL); | 372 | BEGIN(INITIAL); |
372 | } | 373 | } |
373 | } | 374 | } |
374 | 375 | ||
375 | <VARLINE>{ | 376 | <VARLINE>{ |
376 | {WHITESPACE}+{ | 377 | {WHITESPACE}+{ |
377 | modus_operandi& m = M(); | 378 | modus_operandi& m = M(); |
378 | if(!m.output.empty()) { | 379 | if(!m.output.empty()) { |
379 | if(!m._lastid.empty()) { | 380 | if(!m._lastid.empty()) { |
380 | if(!m._type.empty()) m._type += ' '; | 381 | if(!m._type.empty()) m._type += ' '; |
381 | m._type += m._lastid; | 382 | m._type += m._lastid; |
382 | } | 383 | } |
383 | m._lastid = m.output; | 384 | m._lastid = m.output; |
384 | m.output.clear(); | 385 | m.output.clear(); |
385 | } | 386 | } |
386 | } | 387 | } |
387 | \*{ | 388 | \*{ |
388 | modus_operandi& m = M(); | 389 | modus_operandi& m = M(); |
389 | ECHO; | 390 | ECHO; |
390 | if(!m._lastid.empty()) { | 391 | if(!m._lastid.empty()) { |
391 | if(!m._type.empty()) m._type += ' '; | 392 | if(!m._type.empty()) m._type += ' '; |
392 | m._type += m._lastid; | 393 | m._type += m._lastid; |
393 | } | 394 | } |
394 | m._lastid = m.output; | 395 | m._lastid = m.output; |
395 | m.output.clear(); | 396 | m.output.clear(); |
396 | } | 397 | } |
397 | \;|\n|\={ | 398 | \;|\n|\={ |
398 | modus_operandi& m = M(); | 399 | modus_operandi& m = M(); |
399 | if(m.output.empty()) { | 400 | if(m.output.empty()) { |
400 | m._name=m._lastid; | 401 | m._name=m._lastid; |
401 | }else{ | 402 | }else{ |
402 | if(!m._lastid.empty()) { // XXX: lastid should never be emtpy, I believe? | 403 | if(!m._lastid.empty()) { // XXX: lastid should never be emtpy, I believe? |
403 | if(!m._type.empty()) m._type += ' '; | 404 | if(!m._type.empty()) m._type += ' '; |
404 | m._type += m._lastid; | 405 | m._type += m._lastid; |
405 | } | 406 | } |
406 | m._name=m.output; | 407 | m._name=m.output; |
407 | m.output.clear(); | 408 | m.output.clear(); |
408 | } | 409 | } |
409 | BEGIN(VARINIT); | 410 | BEGIN(VARINIT); |
410 | if(*yytext!='=') | 411 | if(*yytext!='=') |
411 | unput('\n'); | 412 | unput('\n'); |
412 | } | 413 | } |
413 | } | 414 | } |
414 | <VARINIT>{ | 415 | <VARINIT>{ |
415 | \n{ | 416 | \n{ |
416 | modus_operandi& m = M(); | 417 | modus_operandi& m = M(); |
417 | string::size_type t = m.output.find_first_not_of(" \t"); | 418 | string::size_type t = m.output.find_first_not_of(" \t"); |
418 | if(t!=string::npos) | 419 | if(t!=string::npos) |
419 | m.output.erase(0,t); | 420 | m.output.erase(0,t); |
420 | t = m.output.find_last_not_of(" \t;"); | 421 | t = m.output.find_last_not_of(" \t;"); |
421 | if(t!=string::npos) | 422 | if(t!=string::npos) |
422 | m.output.erase(t+1); | 423 | m.output.erase(t+1); |
423 | member_variables.push_back(member_variable(m._type,m._name,m.output)); | 424 | member_variables.push_back(member_variable(m._type,m._name,m.output)); |
424 | if(!m.output.empty()) | 425 | if(!m.output.empty()) |
425 | have_initializers=true; | 426 | have_initializers=true; |
426 | modi.pop_front(); | 427 | modi.pop_front(); |
427 | BEGIN(INITIAL); | 428 | BEGIN(INITIAL); |
428 | } | 429 | } |
429 | } | 430 | } |
430 | <DECLLINE>\n{ | 431 | <DECLLINE>\n{ |
431 | ECHO; | 432 | ECHO; |
432 | decl += M().output; | 433 | decl += M().output; |
433 | modi.pop_front(); | 434 | modi.pop_front(); |
434 | BEGIN(INITIAL); | 435 | BEGIN(INITIAL); |
435 | } | 436 | } |
436 | <IMPLLINE>\n{ | 437 | <IMPLLINE>\n{ |
437 | ECHO; | 438 | ECHO; |
438 | impl += M().output; | 439 | impl += M().output; |
439 | modi.pop_front(); | 440 | modi.pop_front(); |
440 | BEGIN(INITIAL); | 441 | BEGIN(INITIAL); |
441 | } | 442 | } |
442 | <CLASSLINE>\n{ | 443 | <CLASSLINE>\n{ |
443 | class_name = M().output; | 444 | class_name = M().output; |
444 | modi.pop_front(); | 445 | modi.pop_front(); |
445 | BEGIN(INITIAL); | 446 | BEGIN(INITIAL); |
446 | } | 447 | } |
447 | <CLASSLINE,DECLLINE,IMPLLINE,VARLINE,VARINIT,IMPORTLINE,IMPORTCOMPONENT,CODEMETHODLINE,CODEMETHODARGS,INLINE,METHODLINE,METHODARGS,DECLBLOCK,IMPLBLOCK,CONSTRUCTOR,DESTRUCTOR,CODEMETHODBLOCK,CODELINE,CODEBLOCK,PRAGMALINE,DERIVELINE,DERIVECOMPONENT>{ | 448 | <CLASSLINE,DECLLINE,IMPLLINE,VARLINE,VARINIT,IMPORTLINE,IMPORTCOMPONENT,CODEMETHODLINE,CODEMETHODARGS,INLINE,METHODLINE,METHODARGS,DECLBLOCK,IMPLBLOCK,CONSTRUCTOR,DESTRUCTOR,CODEMETHODBLOCK,CODELINE,CODEBLOCK,PRAGMALINE,DERIVELINE,DERIVECOMPONENT>{ |
448 | "/*"{ | 449 | "/*"{ |
449 | yy_push_state(SLASHSTAR_COMMENT); | 450 | yy_push_state(SLASHSTAR_COMMENT); |
450 | if(!M().devour_comments()) { | 451 | if(!M().devour_comments()) { |
451 | ECHO; | 452 | ECHO; |
452 | } | 453 | } |
453 | } | 454 | } |
454 | "//"{ | 455 | "//"{ |
455 | yy_push_state(SLASHSLASH_COMMENT); | 456 | yy_push_state(SLASHSLASH_COMMENT); |
456 | if(!M().devour_comments()) { | 457 | if(!M().devour_comments()) { |
457 | ECHO; | 458 | ECHO; |
458 | } | 459 | } |
459 | } | 460 | } |
460 | \" { | 461 | \" { |
461 | yy_push_state(STRING); | 462 | yy_push_state(STRING); |
462 | ECHO; | 463 | ECHO; |
463 | } | 464 | } |
464 | \'\\.\'{ | 465 | \'\\.\'{ |
465 | ECHO; | 466 | ECHO; |
466 | } | 467 | } |
467 | } | 468 | } |
468 | 469 | ||
469 | <INITIAL,METHODBLOCK,OUTPUTBLOCK>{ | 470 | <INITIAL,METHODBLOCK,OUTPUTBLOCK>{ |
470 | \"soft_anchor(); M().modify(modus_operandi::modus_text); LexerOutput("\\\"",2); | 471 | \"soft_anchor(); M().modify(modus_operandi::modus_text); LexerOutput("\\\"",2); |
471 | \nsoft_anchor(); M().modify(modus_operandi::modus_text); LexerOutput("\\n",2); | 472 | \nsoft_anchor(); M().modify(modus_operandi::modus_text); LexerOutput("\\n",2); |
472 | \rsoft_anchor(); M().modify(modus_operandi::modus_text); LexerOutput("\\r",2); | 473 | \rsoft_anchor(); M().modify(modus_operandi::modus_text); LexerOutput("\\r",2); |
473 | \tsoft_anchor(); M().modify(modus_operandi::modus_text); LexerOutput("\\t",2); | 474 | \tsoft_anchor(); M().modify(modus_operandi::modus_text); LexerOutput("\\t",2); |
474 | \bsoft_anchor(); M().modify(modus_operandi::modus_text); LexerOutput("\\b",2); | 475 | \bsoft_anchor(); M().modify(modus_operandi::modus_text); LexerOutput("\\b",2); |
475 | \asoft_anchor(); M().modify(modus_operandi::modus_text); LexerOutput("\\a",2); | 476 | \asoft_anchor(); M().modify(modus_operandi::modus_text); LexerOutput("\\a",2); |
476 | .soft_anchor(); M().modify(modus_operandi::modus_text); ECHO; | 477 | .soft_anchor(); M().modify(modus_operandi::modus_text); ECHO; |
477 | {WHITESPACE}+soft_anchor(); M().modify(modus_operandi::modus_text); ECHO; | 478 | {WHITESPACE}+soft_anchor(); M().modify(modus_operandi::modus_text); ECHO; |
478 | } | 479 | } |
479 | 480 | ||
480 | <DECLBLOCK,IMPLBLOCK,CONSTRUCTOR,DESTRUCTOR,CODEMETHODBLOCK,METHODBLOCK,CODEBLOCK>{ | 481 | <DECLBLOCK,IMPLBLOCK,CONSTRUCTOR,DESTRUCTOR,CODEMETHODBLOCK,METHODBLOCK,CODEBLOCK>{ |
481 | \<\/\%decl\>{ | 482 | \<\/\%decl\>{ |
482 | if(YY_START!=DECLBLOCK) throw preprocessor_error(CODEPOINT,"tags mismatch",lineno()); | 483 | if(YY_START!=DECLBLOCK) throw preprocessor_error(CODEPOINT,"tags mismatch",lineno()); |
483 | decl += M().output; | 484 | decl += M().output; |
484 | modi.pop_front(); | 485 | modi.pop_front(); |
485 | BEGIN(INITIAL); | 486 | BEGIN(INITIAL); |
486 | } | 487 | } |
487 | \<\/\%impl\>{ | 488 | \<\/\%impl\>{ |
488 | if(YY_START!=IMPLBLOCK) throw preprocessor_error(CODEPOINT,"tags mismatch",lineno()); | 489 | if(YY_START!=IMPLBLOCK) throw preprocessor_error(CODEPOINT,"tags mismatch",lineno()); |
489 | impl += M().output; | 490 | impl += M().output; |
490 | modi.pop_front(); | 491 | modi.pop_front(); |
491 | BEGIN(INITIAL); | 492 | BEGIN(INITIAL); |
492 | } | 493 | } |
493 | \<\/\%constructor\>{ | 494 | \<\/\%constructor\>{ |
494 | if(YY_START!=CONSTRUCTOR) throw preprocessor_error(CODEPOINT,"tags mismatch",lineno()); | 495 | if(YY_START!=CONSTRUCTOR) throw preprocessor_error(CODEPOINT,"tags mismatch",lineno()); |
495 | member_functions.push_back(member_function("","","",M().output)); | 496 | member_functions.push_back(member_function("","","",M().output)); |
496 | have_constructor = true; | 497 | have_constructor = true; |
497 | modi.pop_front(); | 498 | modi.pop_front(); |
498 | BEGIN(INITIAL); | 499 | BEGIN(INITIAL); |
499 | } | 500 | } |
500 | \<\/\%destructor\>{ | 501 | \<\/\%destructor\>{ |
501 | if(YY_START!=DESTRUCTOR) throw preprocessor_error(CODEPOINT,"tags mismatch",lineno()); | 502 | if(YY_START!=DESTRUCTOR) throw preprocessor_error(CODEPOINT,"tags mismatch",lineno()); |
502 | member_functions.push_back(member_function("","~","",M().output)); | 503 | member_functions.push_back(member_function("","~","",M().output)); |
503 | modi.pop_front(); | 504 | modi.pop_front(); |
504 | BEGIN(INITIAL); | 505 | BEGIN(INITIAL); |
505 | } | 506 | } |
506 | \<\/\%codemethod\>{ | 507 | \<\/\%codemethod\>{ |
507 | if(YY_START!=CODEMETHODBLOCK) throw preprocessor_error(CODEPOINT,"tags mismatch",lineno()); | 508 | if(YY_START!=CODEMETHODBLOCK) throw preprocessor_error(CODEPOINT,"tags mismatch",lineno()); |
508 | modus_operandi& m = M(); | 509 | modus_operandi& m = M(); |
509 | member_functions.push_back(member_function(m._type,m._name,m._args,m.output)); | 510 | member_functions.push_back(member_function(m._type,m._name,m._args,m.output)); |
510 | modi.pop_front(); | 511 | modi.pop_front(); |
511 | BEGIN(INITIAL); | 512 | BEGIN(INITIAL); |
512 | } | 513 | } |
513 | \<\/%method\> { | 514 | \<\/%method\> { |
514 | if(YY_START!=METHODBLOCK) throw preprocessor_error(CODEPOINT,"tags mismatch",lineno()); | 515 | if(YY_START!=METHODBLOCK) throw preprocessor_error(CODEPOINT,"tags mismatch",lineno()); |
515 | modus_operandi& m = M(); | 516 | modus_operandi& m = M(); |
516 | m.modify(modus_operandi::modus_code); | 517 | m.modify(modus_operandi::modus_code); |
517 | member_functions.push_back(member_function(m._type,m._name,m._args,m.output)); | 518 | member_functions.push_back(member_function(m._type,m._name,m._args,m.output)); |
518 | modi.pop_front(); | 519 | modi.pop_front(); |
519 | BEGIN(INITIAL); | 520 | BEGIN(INITIAL); |
520 | } | 521 | } |
521 | \<\/%code\> { | 522 | \<\/%code\> { |
522 | if(YY_START!=CODEBLOCK) throw preprocessor_error(CODEPOINT,"tags mismatch",lineno()); | 523 | if(YY_START!=CODEBLOCK) throw preprocessor_error(CODEPOINT,"tags mismatch",lineno()); |
523 | yy_pop_state(); | 524 | yy_pop_state(); |
524 | } | 525 | } |
525 | \n ECHO; | 526 | \n ECHO; |
526 | } | 527 | } |
527 | 528 | ||
528 | <SLASHSTAR_COMMENT>{ | 529 | <SLASHSTAR_COMMENT>{ |
529 | "*/"{ | 530 | "*/"{ |
530 | if(!M().devour_comments()) { | 531 | if(!M().devour_comments()) { |
531 | ECHO; | 532 | ECHO; |
532 | } | 533 | } |
533 | yy_pop_state(); | 534 | yy_pop_state(); |
534 | unput(' '); | 535 | unput(' '); |
535 | } | 536 | } |
536 | \n{ | 537 | \n{ |
537 | if(!M().devour_comments()) { | 538 | if(!M().devour_comments()) { |
538 | ECHO; | 539 | ECHO; |
539 | } | 540 | } |
540 | } | 541 | } |
541 | } | 542 | } |
542 | <SLASHSLASH_COMMENT>{ | 543 | <SLASHSLASH_COMMENT>{ |
543 | \n{ | 544 | \n{ |
544 | if(!M().devour_comments()) { | 545 | if(!M().devour_comments()) { |
545 | ECHO; | 546 | ECHO; |
546 | } | 547 | } |
547 | yy_pop_state(); | 548 | yy_pop_state(); |
548 | if(YY_START!=CODEBLOCK && YY_START!=CODEMETHODBLOCK && YY_START!=IMPLBLOCK && YY_START!=DECLBLOCK) | 549 | if(YY_START!=CODEBLOCK && YY_START!=CODEMETHODBLOCK && YY_START!=IMPLBLOCK && YY_START!=DECLBLOCK) |
549 | unput('\n'); | 550 | unput('\n'); |
550 | } | 551 | } |
551 | } | 552 | } |
552 | <SLASHSTAR_COMMENT,SLASHSLASH_COMMENT>.{ | 553 | <SLASHSTAR_COMMENT,SLASHSLASH_COMMENT>.{ |
553 | if(!M().devour_comments()) { | 554 | if(!M().devour_comments()) { |
554 | ECHO; | 555 | ECHO; |
555 | } | 556 | } |
556 | } | 557 | } |
557 | <STRING>{ | 558 | <STRING>{ |
558 | \\.ECHO; | 559 | \\.ECHO; |
559 | \"ECHO; yy_pop_state(); | 560 | \"ECHO; yy_pop_state(); |
560 | .ECHO; | 561 | .ECHO; |
561 | } | 562 | } |