author | Michael Krelin <hacker@klever.net> | 2005-04-03 11:49:46 (UTC) |
---|---|---|
committer | Michael Krelin <hacker@klever.net> | 2005-04-03 11:49:46 (UTC) |
commit | f2ddc6833252f106cf9aa589bc13216ba25ee4e6 (patch) (unidiff) | |
tree | 70187b30b79a3c850e8017337d1d1dc4918a06e5 /lib | |
parent | 67b825ecb491066424b7e48f864c0b76b4156b28 (diff) | |
download | sitecing-f2ddc6833252f106cf9aa589bc13216ba25ee4e6.zip sitecing-f2ddc6833252f106cf9aa589bc13216ba25ee4e6.tar.gz sitecing-f2ddc6833252f106cf9aa589bc13216ba25ee4e6.tar.bz2 |
bugfix: comments weren't discarded in "derive" line
-rw-r--r-- | lib/sitecing_parser.ll | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/lib/sitecing_parser.ll b/lib/sitecing_parser.ll index 9514ce4..4fd6709 100644 --- a/lib/sitecing_parser.ll +++ b/lib/sitecing_parser.ll | |||
@@ -191,452 +191,452 @@ NOIDCHAR [^A-Za-z0-9_] | |||
191 | anchor(); | 191 | anchor(); |
192 | BEGIN(METHODBLOCK); | 192 | BEGIN(METHODBLOCK); |
193 | } | 193 | } |
194 | } | 194 | } |
195 | 195 | ||
196 | <INITIAL,METHODBLOCK,OUTPUTBLOCK>{ | 196 | <INITIAL,METHODBLOCK,OUTPUTBLOCK>{ |
197 | \<\%{WHITESPACE}+{ | 197 | \<\%{WHITESPACE}+{ |
198 | M().modify(modus_operandi::modus_postop); | 198 | M().modify(modus_operandi::modus_postop); |
199 | anchor(); | 199 | anchor(); |
200 | LexerOutput("(",1); | 200 | LexerOutput("(",1); |
201 | yy_push_state(INLINE); | 201 | yy_push_state(INLINE); |
202 | } | 202 | } |
203 | ^\%{WHITESPACE}{ | 203 | ^\%{WHITESPACE}{ |
204 | M().modify(modus_operandi::modus_code); | 204 | M().modify(modus_operandi::modus_code); |
205 | anchor(); | 205 | anchor(); |
206 | yy_push_state(CODELINE); | 206 | yy_push_state(CODELINE); |
207 | } | 207 | } |
208 | \<\%code\>{ | 208 | \<\%code\>{ |
209 | M().modify(modus_operandi::modus_code); | 209 | M().modify(modus_operandi::modus_code); |
210 | anchor(); | 210 | anchor(); |
211 | yy_push_state(CODEBLOCK); | 211 | yy_push_state(CODEBLOCK); |
212 | } | 212 | } |
213 | "</%output>" { | 213 | "</%output>" { |
214 | if(YY_START!=OUTPUTBLOCK) throw preprocessor_error(CODEPOINT,"unexpected tag",lineno()); | 214 | if(YY_START!=OUTPUTBLOCK) throw preprocessor_error(CODEPOINT,"unexpected tag",lineno()); |
215 | M().modify(modus_operandi::modus_code); | 215 | M().modify(modus_operandi::modus_code); |
216 | anchor(); | 216 | anchor(); |
217 | yy_pop_state(); | 217 | yy_pop_state(); |
218 | } | 218 | } |
219 | } | 219 | } |
220 | 220 | ||
221 | <INLINE>\%\>LexerOutput(")",1); M().modus=modus_operandi::modus_preop; yy_pop_state(); | 221 | <INLINE>\%\>LexerOutput(")",1); M().modus=modus_operandi::modus_preop; yy_pop_state(); |
222 | <CODELINE>\nyy_pop_state(); | 222 | <CODELINE>\nyy_pop_state(); |
223 | 223 | ||
224 | <CODEMETHODLINE>{ | 224 | <CODEMETHODLINE>{ |
225 | {WHITESPACE}+{ | 225 | {WHITESPACE}+{ |
226 | modus_operandi& m = M(); | 226 | modus_operandi& m = M(); |
227 | if(!m.output.empty()) { | 227 | if(!m.output.empty()) { |
228 | if(!m._lastid.empty()) { | 228 | if(!m._lastid.empty()) { |
229 | if(!m._type.empty()) m._type += ' '; | 229 | if(!m._type.empty()) m._type += ' '; |
230 | m._type += m._lastid; | 230 | m._type += m._lastid; |
231 | } | 231 | } |
232 | m._lastid = m.output; | 232 | m._lastid = m.output; |
233 | m.output.clear(); | 233 | m.output.clear(); |
234 | } | 234 | } |
235 | } | 235 | } |
236 | \*{ | 236 | \*{ |
237 | modus_operandi& m = M(); | 237 | modus_operandi& m = M(); |
238 | ECHO; | 238 | ECHO; |
239 | if(!m._lastid.empty()) { | 239 | if(!m._lastid.empty()) { |
240 | if(!m._type.empty()) m._type += ' '; | 240 | if(!m._type.empty()) m._type += ' '; |
241 | m._type += m._lastid; | 241 | m._type += m._lastid; |
242 | } | 242 | } |
243 | m._lastid = m.output; | 243 | m._lastid = m.output; |
244 | m.output.clear(); | 244 | m.output.clear(); |
245 | } | 245 | } |
246 | \({ | 246 | \({ |
247 | modus_operandi& m = M(); | 247 | modus_operandi& m = M(); |
248 | if(m.output.empty()) { | 248 | if(m.output.empty()) { |
249 | m._name=m._lastid; | 249 | m._name=m._lastid; |
250 | }else{ | 250 | }else{ |
251 | if(!m._lastid.empty()) { // XXX: lastid, I believe should never be emtpy... | 251 | if(!m._lastid.empty()) { // XXX: lastid, I believe should never be emtpy... |
252 | if(!m._type.empty()) m._type += ' '; | 252 | if(!m._type.empty()) m._type += ' '; |
253 | m._type += m._lastid; | 253 | m._type += m._lastid; |
254 | } | 254 | } |
255 | m._name = m.output; | 255 | m._name = m.output; |
256 | m.output.clear(); | 256 | m.output.clear(); |
257 | } | 257 | } |
258 | ECHO; | 258 | ECHO; |
259 | BEGIN(CODEMETHODARGS); | 259 | BEGIN(CODEMETHODARGS); |
260 | } | 260 | } |
261 | } | 261 | } |
262 | <CODEMETHODARGS>{ | 262 | <CODEMETHODARGS>{ |
263 | \%\>{ | 263 | \%\>{ |
264 | modus_operandi& m = M(); | 264 | modus_operandi& m = M(); |
265 | m._args = m.output; | 265 | m._args = m.output; |
266 | m.output.clear(); | 266 | m.output.clear(); |
267 | m.flags=0; | 267 | m.flags=0; |
268 | anchor(); | 268 | anchor(); |
269 | BEGIN(CODEMETHODBLOCK); | 269 | BEGIN(CODEMETHODBLOCK); |
270 | } | 270 | } |
271 | } | 271 | } |
272 | 272 | ||
273 | <IMPORTLINE>{ | 273 | <IMPORTLINE>{ |
274 | {WHITESPACE}+{ } | 274 | {WHITESPACE}+{ } |
275 | {ID}{ | 275 | {ID}{ |
276 | modus_operandi& m = M(); | 276 | modus_operandi& m = M(); |
277 | if(!m._name.empty()) | 277 | if(!m._name.empty()) |
278 | throw preprocessor_error(CODEPOINT,"syntax error",lineno()); | 278 | throw preprocessor_error(CODEPOINT,"syntax error",lineno()); |
279 | m._name = yytext; | 279 | m._name = yytext; |
280 | } | 280 | } |
281 | \= { | 281 | \= { |
282 | M().output.clear(); | 282 | M().output.clear(); |
283 | BEGIN(IMPORTCOMPONENT); | 283 | BEGIN(IMPORTCOMPONENT); |
284 | } | 284 | } |
285 | } | 285 | } |
286 | <IMPORTCOMPONENT>{ | 286 | <IMPORTCOMPONENT>{ |
287 | {WHITESPACE}+{ } | 287 | {WHITESPACE}+{ } |
288 | \n{ | 288 | \n{ |
289 | modus_operandi& m = M(); | 289 | modus_operandi& m = M(); |
290 | string::size_type t = m.output.find_first_not_of(" \t"); | 290 | string::size_type t = m.output.find_first_not_of(" \t"); |
291 | if(t!=string::npos) | 291 | if(t!=string::npos) |
292 | m.output.erase(0,t); | 292 | m.output.erase(0,t); |
293 | t = m.output.find_last_not_of(" \t;"); | 293 | t = m.output.find_last_not_of(" \t;"); |
294 | if(t!=string::npos) | 294 | if(t!=string::npos) |
295 | m.output.erase(t+1); | 295 | m.output.erase(t+1); |
296 | if(m.output[0]=='"' && m.output[m.output.length()-1]=='"') { | 296 | if(m.output[0]=='"' && m.output[m.output.length()-1]=='"') { |
297 | m.output.erase(0,1); | 297 | m.output.erase(0,1); |
298 | m.output.erase(m.output.length()-1); | 298 | m.output.erase(m.output.length()-1); |
299 | } | 299 | } |
300 | string c = combine_path(component_basename,m.output); | 300 | string c = combine_path(component_basename,m.output); |
301 | member_variables.push_back(member_variable(m._type,m._name,normalize_path(c,strip_leading_slash),true)); | 301 | member_variables.push_back(member_variable(m._type,m._name,normalize_path(c,strip_leading_slash),true)); |
302 | modi.pop_front(); | 302 | modi.pop_front(); |
303 | BEGIN(INITIAL); | 303 | BEGIN(INITIAL); |
304 | } | 304 | } |
305 | } | 305 | } |
306 | 306 | ||
307 | <IMPORTTYPELINE>{ | 307 | <IMPORTTYPELINE>{ |
308 | {WHITESPACE}+{ } | 308 | {WHITESPACE}+{ } |
309 | {ID}{ | 309 | {ID}{ |
310 | modus_operandi& m = M(); | 310 | modus_operandi& m = M(); |
311 | if(!m._name.empty()) | 311 | if(!m._name.empty()) |
312 | throw preprocessor_error(CODEPOINT,"syntax error",lineno()); | 312 | throw preprocessor_error(CODEPOINT,"syntax error",lineno()); |
313 | m._name = yytext; | 313 | m._name = yytext; |
314 | } | 314 | } |
315 | \= { | 315 | \= { |
316 | M().output.clear(); | 316 | M().output.clear(); |
317 | BEGIN(IMPORTTYPECOMPONENT); | 317 | BEGIN(IMPORTTYPECOMPONENT); |
318 | } | 318 | } |
319 | } | 319 | } |
320 | <IMPORTTYPECOMPONENT>{ | 320 | <IMPORTTYPECOMPONENT>{ |
321 | {WHITESPACE}+{ } | 321 | {WHITESPACE}+{ } |
322 | \n{ | 322 | \n{ |
323 | modus_operandi& m = M(); | 323 | modus_operandi& m = M(); |
324 | string::size_type t = m.output.find_first_not_of(" \t"); | 324 | string::size_type t = m.output.find_first_not_of(" \t"); |
325 | if(t!=string::npos) | 325 | if(t!=string::npos) |
326 | m.output.erase(0,t); | 326 | m.output.erase(0,t); |
327 | t = m.output.find_last_not_of(" \t;"); | 327 | t = m.output.find_last_not_of(" \t;"); |
328 | if(t!=string::npos) | 328 | if(t!=string::npos) |
329 | m.output.erase(t+1); | 329 | m.output.erase(t+1); |
330 | if(m.output[0]=='"' && m.output[m.output.length()-1]=='"') { | 330 | if(m.output[0]=='"' && m.output[m.output.length()-1]=='"') { |
331 | m.output.erase(0,1); | 331 | m.output.erase(0,1); |
332 | m.output.erase(m.output.length()-1); | 332 | m.output.erase(m.output.length()-1); |
333 | } | 333 | } |
334 | string c = combine_path(component_basename,m.output); | 334 | string c = 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)); | 335 | member_variables.push_back(member_variable(m._type,m._name,normalize_path(c,strip_leading_slash),true,true)); |
336 | modi.pop_front(); | 336 | modi.pop_front(); |
337 | BEGIN(INITIAL); | 337 | BEGIN(INITIAL); |
338 | } | 338 | } |
339 | } | 339 | } |
340 | 340 | ||
341 | <DERIVELINE>{ | 341 | <DERIVELINE>{ |
342 | {WHITESPACE}+{ } | 342 | {WHITESPACE}+{ } |
343 | {ID}{ | 343 | {ID}{ |
344 | modus_operandi& m = M(); | 344 | modus_operandi& m = M(); |
345 | if(!m._name.empty()) | 345 | if(!m._name.empty()) |
346 | throw preprocessor_error(CODEPOINT,"syntax_error",lineno()); | 346 | throw preprocessor_error(CODEPOINT,"syntax_error",lineno()); |
347 | m._name = yytext; | 347 | m._name = yytext; |
348 | } | 348 | } |
349 | \= { | 349 | \= { |
350 | M().output.clear(); | 350 | M().output.clear(); |
351 | BEGIN(DERIVECOMPONENT); | 351 | BEGIN(DERIVECOMPONENT); |
352 | } | 352 | } |
353 | } | 353 | } |
354 | <DERIVECOMPONENT>{ | 354 | <DERIVECOMPONENT>{ |
355 | {WHITESPACE}+{ } | 355 | {WHITESPACE}+{ } |
356 | \n { | 356 | \n { |
357 | modus_operandi& m = M(); | 357 | modus_operandi& m = M(); |
358 | string::size_type t = m.output.find_first_not_of(" \t"); | 358 | string::size_type t = m.output.find_first_not_of(" \t"); |
359 | if(t!=string::npos) | 359 | if(t!=string::npos) |
360 | m.output.erase(0,t); | 360 | m.output.erase(0,t); |
361 | t = m.output.find_last_not_of(" \t;"); | 361 | t = m.output.find_last_not_of(" \t;"); |
362 | if(t!=string::npos) | 362 | if(t!=string::npos) |
363 | m.output.erase(t+1); | 363 | m.output.erase(t+1); |
364 | if(m.output[0]=='"' && m.output[m.output.length()-1]=='"') { | 364 | if(m.output[0]=='"' && m.output[m.output.length()-1]=='"') { |
365 | m.output.erase(0,1); | 365 | m.output.erase(0,1); |
366 | m.output.erase(m.output.length()-1); | 366 | m.output.erase(m.output.length()-1); |
367 | } | 367 | } |
368 | string c = combine_path(component_basename,m.output); | 368 | string c = combine_path(component_basename,m.output); |
369 | ancestor_classes.push_back(ancestor_class(m._name,normalize_path(c,strip_leading_slash))); | 369 | ancestor_classes.push_back(ancestor_class(m._name,normalize_path(c,strip_leading_slash))); |
370 | modi.pop_front(); | 370 | modi.pop_front(); |
371 | BEGIN(INITIAL); | 371 | BEGIN(INITIAL); |
372 | } | 372 | } |
373 | } | 373 | } |
374 | 374 | ||
375 | <VARLINE>{ | 375 | <VARLINE>{ |
376 | {WHITESPACE}+{ | 376 | {WHITESPACE}+{ |
377 | modus_operandi& m = M(); | 377 | modus_operandi& m = M(); |
378 | if(!m.output.empty()) { | 378 | if(!m.output.empty()) { |
379 | if(!m._lastid.empty()) { | 379 | if(!m._lastid.empty()) { |
380 | if(!m._type.empty()) m._type += ' '; | 380 | if(!m._type.empty()) m._type += ' '; |
381 | m._type += m._lastid; | 381 | m._type += m._lastid; |
382 | } | 382 | } |
383 | m._lastid = m.output; | 383 | m._lastid = m.output; |
384 | m.output.clear(); | 384 | m.output.clear(); |
385 | } | 385 | } |
386 | } | 386 | } |
387 | \*{ | 387 | \*{ |
388 | modus_operandi& m = M(); | 388 | modus_operandi& m = M(); |
389 | ECHO; | 389 | ECHO; |
390 | if(!m._lastid.empty()) { | 390 | if(!m._lastid.empty()) { |
391 | if(!m._type.empty()) m._type += ' '; | 391 | if(!m._type.empty()) m._type += ' '; |
392 | m._type += m._lastid; | 392 | m._type += m._lastid; |
393 | } | 393 | } |
394 | m._lastid = m.output; | 394 | m._lastid = m.output; |
395 | m.output.clear(); | 395 | m.output.clear(); |
396 | } | 396 | } |
397 | \;|\n|\={ | 397 | \;|\n|\={ |
398 | modus_operandi& m = M(); | 398 | modus_operandi& m = M(); |
399 | if(m.output.empty()) { | 399 | if(m.output.empty()) { |
400 | m._name=m._lastid; | 400 | m._name=m._lastid; |
401 | }else{ | 401 | }else{ |
402 | if(!m._lastid.empty()) { // XXX: lastid should never be emtpy, I believe? | 402 | if(!m._lastid.empty()) { // XXX: lastid should never be emtpy, I believe? |
403 | if(!m._type.empty()) m._type += ' '; | 403 | if(!m._type.empty()) m._type += ' '; |
404 | m._type += m._lastid; | 404 | m._type += m._lastid; |
405 | } | 405 | } |
406 | m._name=m.output; | 406 | m._name=m.output; |
407 | m.output.clear(); | 407 | m.output.clear(); |
408 | } | 408 | } |
409 | BEGIN(VARINIT); | 409 | BEGIN(VARINIT); |
410 | if(*yytext!='=') | 410 | if(*yytext!='=') |
411 | unput('\n'); | 411 | unput('\n'); |
412 | } | 412 | } |
413 | } | 413 | } |
414 | <VARINIT>{ | 414 | <VARINIT>{ |
415 | \n{ | 415 | \n{ |
416 | modus_operandi& m = M(); | 416 | modus_operandi& m = M(); |
417 | string::size_type t = m.output.find_first_not_of(" \t"); | 417 | string::size_type t = m.output.find_first_not_of(" \t"); |
418 | if(t!=string::npos) | 418 | if(t!=string::npos) |
419 | m.output.erase(0,t); | 419 | m.output.erase(0,t); |
420 | t = m.output.find_last_not_of(" \t;"); | 420 | t = m.output.find_last_not_of(" \t;"); |
421 | if(t!=string::npos) | 421 | if(t!=string::npos) |
422 | m.output.erase(t+1); | 422 | m.output.erase(t+1); |
423 | member_variables.push_back(member_variable(m._type,m._name,m.output)); | 423 | member_variables.push_back(member_variable(m._type,m._name,m.output)); |
424 | if(!m.output.empty()) | 424 | if(!m.output.empty()) |
425 | have_initializers=true; | 425 | have_initializers=true; |
426 | modi.pop_front(); | 426 | modi.pop_front(); |
427 | BEGIN(INITIAL); | 427 | BEGIN(INITIAL); |
428 | } | 428 | } |
429 | } | 429 | } |
430 | <DECLLINE>\n{ | 430 | <DECLLINE>\n{ |
431 | ECHO; | 431 | ECHO; |
432 | decl += M().output; | 432 | decl += M().output; |
433 | modi.pop_front(); | 433 | modi.pop_front(); |
434 | BEGIN(INITIAL); | 434 | BEGIN(INITIAL); |
435 | } | 435 | } |
436 | <IMPLLINE>\n{ | 436 | <IMPLLINE>\n{ |
437 | ECHO; | 437 | ECHO; |
438 | impl += M().output; | 438 | impl += M().output; |
439 | modi.pop_front(); | 439 | modi.pop_front(); |
440 | BEGIN(INITIAL); | 440 | BEGIN(INITIAL); |
441 | } | 441 | } |
442 | <CLASSLINE>\n{ | 442 | <CLASSLINE>\n{ |
443 | class_name = M().output; | 443 | class_name = M().output; |
444 | modi.pop_front(); | 444 | modi.pop_front(); |
445 | BEGIN(INITIAL); | 445 | BEGIN(INITIAL); |
446 | } | 446 | } |
447 | <CLASSLINE,DECLLINE,IMPLLINE,VARLINE,VARINIT,IMPORTLINE,IMPORTCOMPONENT,CODEMETHODLINE,CODEMETHODARGS,INLINE,METHODLINE,METHODARGS,DECLBLOCK,IMPLBLOCK,CONSTRUCTOR,DESTRUCTOR,CODEMETHODBLOCK,CODELINE,CODEBLOCK,PRAGMALINE>{ | 447 | <CLASSLINE,DECLLINE,IMPLLINE,VARLINE,VARINIT,IMPORTLINE,IMPORTCOMPONENT,CODEMETHODLINE,CODEMETHODARGS,INLINE,METHODLINE,METHODARGS,DECLBLOCK,IMPLBLOCK,CONSTRUCTOR,DESTRUCTOR,CODEMETHODBLOCK,CODELINE,CODEBLOCK,PRAGMALINE,DERIVELINE,DERIVECOMPONENT>{ |
448 | "/*"{ | 448 | "/*"{ |
449 | yy_push_state(SLASHSTAR_COMMENT); | 449 | yy_push_state(SLASHSTAR_COMMENT); |
450 | if(!M().devour_comments()) { | 450 | if(!M().devour_comments()) { |
451 | ECHO; | 451 | ECHO; |
452 | } | 452 | } |
453 | } | 453 | } |
454 | "//"{ | 454 | "//"{ |
455 | yy_push_state(SLASHSLASH_COMMENT); | 455 | yy_push_state(SLASHSLASH_COMMENT); |
456 | if(!M().devour_comments()) { | 456 | if(!M().devour_comments()) { |
457 | ECHO; | 457 | ECHO; |
458 | } | 458 | } |
459 | } | 459 | } |
460 | \" { | 460 | \" { |
461 | yy_push_state(STRING); | 461 | yy_push_state(STRING); |
462 | ECHO; | 462 | ECHO; |
463 | } | 463 | } |
464 | \'\\.\'{ | 464 | \'\\.\'{ |
465 | ECHO; | 465 | ECHO; |
466 | } | 466 | } |
467 | } | 467 | } |
468 | 468 | ||
469 | <INITIAL,METHODBLOCK,OUTPUTBLOCK>{ | 469 | <INITIAL,METHODBLOCK,OUTPUTBLOCK>{ |
470 | \"soft_anchor(); M().modify(modus_operandi::modus_text); LexerOutput("\\\"",2); | 470 | \"soft_anchor(); M().modify(modus_operandi::modus_text); LexerOutput("\\\"",2); |
471 | \nsoft_anchor(); M().modify(modus_operandi::modus_text); LexerOutput("\\n",2); | 471 | \nsoft_anchor(); M().modify(modus_operandi::modus_text); LexerOutput("\\n",2); |
472 | \rsoft_anchor(); M().modify(modus_operandi::modus_text); LexerOutput("\\r",2); | 472 | \rsoft_anchor(); M().modify(modus_operandi::modus_text); LexerOutput("\\r",2); |
473 | \tsoft_anchor(); M().modify(modus_operandi::modus_text); LexerOutput("\\t",2); | 473 | \tsoft_anchor(); M().modify(modus_operandi::modus_text); LexerOutput("\\t",2); |
474 | \bsoft_anchor(); M().modify(modus_operandi::modus_text); LexerOutput("\\b",2); | 474 | \bsoft_anchor(); M().modify(modus_operandi::modus_text); LexerOutput("\\b",2); |
475 | \asoft_anchor(); M().modify(modus_operandi::modus_text); LexerOutput("\\a",2); | 475 | \asoft_anchor(); M().modify(modus_operandi::modus_text); LexerOutput("\\a",2); |
476 | .soft_anchor(); M().modify(modus_operandi::modus_text); ECHO; | 476 | .soft_anchor(); M().modify(modus_operandi::modus_text); ECHO; |
477 | {WHITESPACE}+soft_anchor(); M().modify(modus_operandi::modus_text); ECHO; | 477 | {WHITESPACE}+soft_anchor(); M().modify(modus_operandi::modus_text); ECHO; |
478 | } | 478 | } |
479 | 479 | ||
480 | <DECLBLOCK,IMPLBLOCK,CONSTRUCTOR,DESTRUCTOR,CODEMETHODBLOCK,METHODBLOCK,CODEBLOCK>{ | 480 | <DECLBLOCK,IMPLBLOCK,CONSTRUCTOR,DESTRUCTOR,CODEMETHODBLOCK,METHODBLOCK,CODEBLOCK>{ |
481 | \<\/\%decl\>{ | 481 | \<\/\%decl\>{ |
482 | if(YY_START!=DECLBLOCK) throw preprocessor_error(CODEPOINT,"tags mismatch",lineno()); | 482 | if(YY_START!=DECLBLOCK) throw preprocessor_error(CODEPOINT,"tags mismatch",lineno()); |
483 | decl += M().output; | 483 | decl += M().output; |
484 | modi.pop_front(); | 484 | modi.pop_front(); |
485 | BEGIN(INITIAL); | 485 | BEGIN(INITIAL); |
486 | } | 486 | } |
487 | \<\/\%impl\>{ | 487 | \<\/\%impl\>{ |
488 | if(YY_START!=IMPLBLOCK) throw preprocessor_error(CODEPOINT,"tags mismatch",lineno()); | 488 | if(YY_START!=IMPLBLOCK) throw preprocessor_error(CODEPOINT,"tags mismatch",lineno()); |
489 | impl += M().output; | 489 | impl += M().output; |
490 | modi.pop_front(); | 490 | modi.pop_front(); |
491 | BEGIN(INITIAL); | 491 | BEGIN(INITIAL); |
492 | } | 492 | } |
493 | \<\/\%constructor\>{ | 493 | \<\/\%constructor\>{ |
494 | if(YY_START!=CONSTRUCTOR) throw preprocessor_error(CODEPOINT,"tags mismatch",lineno()); | 494 | if(YY_START!=CONSTRUCTOR) throw preprocessor_error(CODEPOINT,"tags mismatch",lineno()); |
495 | member_functions.push_back(member_function("","","",M().output)); | 495 | member_functions.push_back(member_function("","","",M().output)); |
496 | have_constructor = true; | 496 | have_constructor = true; |
497 | modi.pop_front(); | 497 | modi.pop_front(); |
498 | BEGIN(INITIAL); | 498 | BEGIN(INITIAL); |
499 | } | 499 | } |
500 | \<\/\%destructor\>{ | 500 | \<\/\%destructor\>{ |
501 | if(YY_START!=DESTRUCTOR) throw preprocessor_error(CODEPOINT,"tags mismatch",lineno()); | 501 | if(YY_START!=DESTRUCTOR) throw preprocessor_error(CODEPOINT,"tags mismatch",lineno()); |
502 | member_functions.push_back(member_function("","~","",M().output)); | 502 | member_functions.push_back(member_function("","~","",M().output)); |
503 | modi.pop_front(); | 503 | modi.pop_front(); |
504 | BEGIN(INITIAL); | 504 | BEGIN(INITIAL); |
505 | } | 505 | } |
506 | \<\/\%codemethod\>{ | 506 | \<\/\%codemethod\>{ |
507 | if(YY_START!=CODEMETHODBLOCK) throw preprocessor_error(CODEPOINT,"tags mismatch",lineno()); | 507 | if(YY_START!=CODEMETHODBLOCK) throw preprocessor_error(CODEPOINT,"tags mismatch",lineno()); |
508 | modus_operandi& m = M(); | 508 | modus_operandi& m = M(); |
509 | member_functions.push_back(member_function(m._type,m._name,m._args,m.output)); | 509 | member_functions.push_back(member_function(m._type,m._name,m._args,m.output)); |
510 | modi.pop_front(); | 510 | modi.pop_front(); |
511 | BEGIN(INITIAL); | 511 | BEGIN(INITIAL); |
512 | } | 512 | } |
513 | \<\/%method\> { | 513 | \<\/%method\> { |
514 | if(YY_START!=METHODBLOCK) throw preprocessor_error(CODEPOINT,"tags mismatch",lineno()); | 514 | if(YY_START!=METHODBLOCK) throw preprocessor_error(CODEPOINT,"tags mismatch",lineno()); |
515 | modus_operandi& m = M(); | 515 | modus_operandi& m = M(); |
516 | m.modify(modus_operandi::modus_code); | 516 | m.modify(modus_operandi::modus_code); |
517 | member_functions.push_back(member_function(m._type,m._name,m._args,m.output)); | 517 | member_functions.push_back(member_function(m._type,m._name,m._args,m.output)); |
518 | modi.pop_front(); | 518 | modi.pop_front(); |
519 | BEGIN(INITIAL); | 519 | BEGIN(INITIAL); |
520 | } | 520 | } |
521 | \<\/%code\> { | 521 | \<\/%code\> { |
522 | if(YY_START!=CODEBLOCK) throw preprocessor_error(CODEPOINT,"tags mismatch",lineno()); | 522 | if(YY_START!=CODEBLOCK) throw preprocessor_error(CODEPOINT,"tags mismatch",lineno()); |
523 | yy_pop_state(); | 523 | yy_pop_state(); |
524 | } | 524 | } |
525 | \n ECHO; | 525 | \n ECHO; |
526 | } | 526 | } |
527 | 527 | ||
528 | <SLASHSTAR_COMMENT>{ | 528 | <SLASHSTAR_COMMENT>{ |
529 | "*/"{ | 529 | "*/"{ |
530 | if(!M().devour_comments()) { | 530 | if(!M().devour_comments()) { |
531 | ECHO; | 531 | ECHO; |
532 | } | 532 | } |
533 | yy_pop_state(); | 533 | yy_pop_state(); |
534 | unput(' '); | 534 | unput(' '); |
535 | } | 535 | } |
536 | \n{ | 536 | \n{ |
537 | if(!M().devour_comments()) { | 537 | if(!M().devour_comments()) { |
538 | ECHO; | 538 | ECHO; |
539 | } | 539 | } |
540 | } | 540 | } |
541 | } | 541 | } |
542 | <SLASHSLASH_COMMENT>{ | 542 | <SLASHSLASH_COMMENT>{ |
543 | \n{ | 543 | \n{ |
544 | if(!M().devour_comments()) { | 544 | if(!M().devour_comments()) { |
545 | ECHO; | 545 | ECHO; |
546 | } | 546 | } |
547 | yy_pop_state(); | 547 | yy_pop_state(); |
548 | if(YY_START!=CODEBLOCK && YY_START!=CODEMETHODBLOCK && YY_START!=IMPLBLOCK && YY_START!=DECLBLOCK) | 548 | if(YY_START!=CODEBLOCK && YY_START!=CODEMETHODBLOCK && YY_START!=IMPLBLOCK && YY_START!=DECLBLOCK) |
549 | unput('\n'); | 549 | unput('\n'); |
550 | } | 550 | } |
551 | } | 551 | } |
552 | <SLASHSTAR_COMMENT,SLASHSLASH_COMMENT>.{ | 552 | <SLASHSTAR_COMMENT,SLASHSLASH_COMMENT>.{ |
553 | if(!M().devour_comments()) { | 553 | if(!M().devour_comments()) { |
554 | ECHO; | 554 | ECHO; |
555 | } | 555 | } |
556 | } | 556 | } |
557 | <STRING>{ | 557 | <STRING>{ |
558 | \\.ECHO; | 558 | \\.ECHO; |
559 | \"ECHO; yy_pop_state(); | 559 | \"ECHO; yy_pop_state(); |
560 | .ECHO; | 560 | .ECHO; |
561 | } | 561 | } |
562 | 562 | ||
563 | {WHITESPACE}+{ | 563 | {WHITESPACE}+{ |
564 | if(!(M().flags&modus_operandi::flag_devour_whitespace)) { | 564 | if(!(M().flags&modus_operandi::flag_devour_whitespace)) { |
565 | ECHO; | 565 | ECHO; |
566 | } | 566 | } |
567 | } | 567 | } |
568 | 568 | ||
569 | %% | 569 | %% |
570 | 570 | ||
571 | sitecing_parser::sitecing_parser(component_factory& f) | 571 | sitecing_parser::sitecing_parser(component_factory& f) |
572 | : factory(f), have_initializers(false), have_constructor(false), | 572 | : factory(f), have_initializers(false), have_constructor(false), |
573 | base_class("sitecing::cgi_component"), | 573 | base_class("sitecing::cgi_component"), |
574 | base_header("sitecing/cgi_component.h"), | 574 | base_header("sitecing/cgi_component.h"), |
575 | skeleton(__SC_DEFAULT_SKELETON) { | 575 | skeleton(__SC_DEFAULT_SKELETON) { |
576 | } | 576 | } |
577 | 577 | ||
578 | void sitecing_parser::preprocess(const string& in) { | 578 | void sitecing_parser::preprocess(const string& in) { |
579 | ifstream ifs(in.c_str(),ios::in); | 579 | ifstream ifs(in.c_str(),ios::in); |
580 | if(!ifs.good()) | 580 | if(!ifs.good()) |
581 | throw preprocessor_error(CODEPOINT,"failed to open input file"); | 581 | throw preprocessor_error(CODEPOINT,"failed to open input file"); |
582 | input_file = in; | 582 | input_file = in; |
583 | modi.push_front(modus_operandi(0)); | 583 | modi.push_front(modus_operandi(0)); |
584 | switch_streams(&ifs,NULL); | 584 | switch_streams(&ifs,NULL); |
585 | if(yylex()) | 585 | if(yylex()) |
586 | throw preprocessor_error(CODEPOINT,"unknown error"); | 586 | throw preprocessor_error(CODEPOINT,"unknown error"); |
587 | pragmas_t::const_iterator mp = pragmas.find("main"); | 587 | pragmas_t::const_iterator mp = pragmas.find("main"); |
588 | if(mp==pragmas.end()) { | 588 | if(mp==pragmas.end()) { |
589 | member_functions.push_back(member_function("void","main","(int _magic,va_list _args)",M().output)); | 589 | member_functions.push_back(member_function("void","main","(int _magic,va_list _args)",M().output)); |
590 | }else{ | 590 | }else{ |
591 | member_functions.push_back( | 591 | member_functions.push_back( |
592 | member_function( | 592 | member_function( |
593 | "void","main","(int _magic,va_list _args)", | 593 | "void","main","(int _magic,va_list _args)", |
594 | mp->second+"::main(_magic,_args);" | 594 | mp->second+"::main(_magic,_args);" |
595 | ) | 595 | ) |
596 | ); | 596 | ); |
597 | } | 597 | } |
598 | if(have_initializers && !have_constructor) | 598 | if(have_initializers && !have_constructor) |
599 | member_functions.push_back(member_function("","","","")); | 599 | member_functions.push_back(member_function("","","","")); |
600 | sitecing_enflesher enflesher(*this); | 600 | sitecing_enflesher enflesher(*this); |
601 | enflesher.enflesh(); | 601 | enflesher.enflesh(); |
602 | } | 602 | } |
603 | 603 | ||
604 | void sitecing_parser::LexerOutput(const char* buf,int size) { | 604 | void sitecing_parser::LexerOutput(const char* buf,int size) { |
605 | assert(modi.size()); | 605 | assert(modi.size()); |
606 | M().output.append(buf,size); | 606 | M().output.append(buf,size); |
607 | } | 607 | } |
608 | 608 | ||
609 | static const char *modus_transitions | 609 | static const char *modus_transitions |
610 | [sitecing_parser::modus_operandi::modi] | 610 | [sitecing_parser::modus_operandi::modi] |
611 | [sitecing_parser::modus_operandi::modi] = { | 611 | [sitecing_parser::modus_operandi::modi] = { |
612 | // To: | 612 | // To: |
613 | // code preop postop text From: | 613 | // code preop postop text From: |
614 | { "", "(*(__SCIF->out))", "(*(__SCIF->out))<<", "(*(__SCIF->out))<<\"" }, // code | 614 | { "", "(*(__SCIF->out))", "(*(__SCIF->out))<<", "(*(__SCIF->out))<<\"" }, // code |
615 | { ";", "", "<<", "<<\"" }, // preop | 615 | { ";", "", "<<", "<<\"" }, // preop |
616 | { NULL, NULL, "", "\"" }, // postop | 616 | { NULL, NULL, "", "\"" }, // postop |
617 | { "\";", "\"", "\"<<", "" } // text | 617 | { "\";", "\"", "\"<<", "" } // text |
618 | }; | 618 | }; |
619 | 619 | ||
620 | void sitecing_parser::modus_operandi::modify(modus_t m) { | 620 | void sitecing_parser::modus_operandi::modify(modus_t m) { |
621 | const char * x = modus_transitions[modus][m]; | 621 | const char * x = modus_transitions[modus][m]; |
622 | assert(x); | 622 | assert(x); |
623 | output += x; | 623 | output += x; |
624 | modus = m; | 624 | modus = m; |
625 | } | 625 | } |
626 | 626 | ||
627 | void sitecing_parser::soft_anchor() { | 627 | void sitecing_parser::soft_anchor() { |
628 | if(M().modus!=modus_operandi::modus_text) | 628 | if(M().modus!=modus_operandi::modus_text) |
629 | anchor(); | 629 | anchor(); |
630 | } | 630 | } |
631 | void sitecing_parser::anchor() { | 631 | void sitecing_parser::anchor() { |
632 | if(M().modus==modus_operandi::modus_text) | 632 | if(M().modus==modus_operandi::modus_text) |
633 | M().modify(modus_operandi::modus_preop); | 633 | M().modify(modus_operandi::modus_preop); |
634 | M().output += "\n#line "; | 634 | M().output += "\n#line "; |
635 | char tmp[7]; | 635 | char tmp[7]; |
636 | snprintf(tmp,sizeof(tmp),"%d",lineno()); | 636 | snprintf(tmp,sizeof(tmp),"%d",lineno()); |
637 | M().output += tmp; | 637 | M().output += tmp; |
638 | M().output += " \""; | 638 | M().output += " \""; |
639 | M().output += input_file; | 639 | M().output += input_file; |
640 | M().output += "\"\n"; | 640 | M().output += "\"\n"; |
641 | } | 641 | } |
642 | /* vim:set ft=lex: */ | 642 | /* vim:set ft=lex: */ |