-rw-r--r-- | lib/sitecing_parser.ll | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/lib/sitecing_parser.ll b/lib/sitecing_parser.ll index 8dd8d5f..53df9a0 100644 --- a/lib/sitecing_parser.ll +++ b/lib/sitecing_parser.ll | |||
@@ -349,256 +349,257 @@ NOIDCHAR [^A-Za-z0-9_] | |||
349 | } | 349 | } |
350 | \= { | 350 | \= { |
351 | M().output.clear(); | 351 | M().output.clear(); |
352 | BEGIN(DERIVECOMPONENT); | 352 | BEGIN(DERIVECOMPONENT); |
353 | } | 353 | } |
354 | } | 354 | } |
355 | <DERIVECOMPONENT>{ | 355 | <DERIVECOMPONENT>{ |
356 | {WHITESPACE}+{ } | 356 | {WHITESPACE}+{ } |
357 | \n { | 357 | \n { |
358 | modus_operandi& m = M(); | 358 | modus_operandi& m = M(); |
359 | string::size_type t = m.output.find_first_not_of(" \t"); | 359 | string::size_type t = m.output.find_first_not_of(" \t"); |
360 | if(t!=string::npos) | 360 | if(t!=string::npos) |
361 | m.output.erase(0,t); | 361 | m.output.erase(0,t); |
362 | t = m.output.find_last_not_of(" \t;"); | 362 | t = m.output.find_last_not_of(" \t;"); |
363 | if(t!=string::npos) | 363 | if(t!=string::npos) |
364 | m.output.erase(t+1); | 364 | m.output.erase(t+1); |
365 | if(m.output[0]=='"' && m.output[m.output.length()-1]=='"') { | 365 | if(m.output[0]=='"' && m.output[m.output.length()-1]=='"') { |
366 | m.output.erase(0,1); | 366 | m.output.erase(0,1); |
367 | m.output.erase(m.output.length()-1); | 367 | m.output.erase(m.output.length()-1); |
368 | } | 368 | } |
369 | string c = konforka::combine_path(component_basename,m.output); | 369 | string c = konforka::combine_path(component_basename,m.output); |
370 | ancestor_classes.push_back(ancestor_class(m._name,konforka::normalize_path(c,konforka::strip_leading_slash))); | 370 | ancestor_classes.push_back(ancestor_class(m._name,konforka::normalize_path(c,konforka::strip_leading_slash))); |
371 | modi.pop_front(); | 371 | modi.pop_front(); |
372 | BEGIN(INITIAL); | 372 | BEGIN(INITIAL); |
373 | } | 373 | } |
374 | } | 374 | } |
375 | 375 | ||
376 | <VARLINE>{ | 376 | <VARLINE>{ |
377 | {WHITESPACE}+{ | 377 | {WHITESPACE}+{ |
378 | modus_operandi& m = M(); | 378 | modus_operandi& m = M(); |
379 | if(!m.output.empty()) { | 379 | if(!m.output.empty()) { |
380 | if(!m._lastid.empty()) { | 380 | if(!m._lastid.empty()) { |
381 | if(!m._type.empty()) m._type += ' '; | 381 | if(!m._type.empty()) m._type += ' '; |
382 | m._type += m._lastid; | 382 | m._type += m._lastid; |
383 | } | 383 | } |
384 | m._lastid = m.output; | 384 | m._lastid = m.output; |
385 | m.output.clear(); | 385 | m.output.clear(); |
386 | } | 386 | } |
387 | } | 387 | } |
388 | \*{ | 388 | \*{ |
389 | modus_operandi& m = M(); | 389 | modus_operandi& m = M(); |
390 | ECHO; | 390 | ECHO; |
391 | if(!m._lastid.empty()) { | 391 | if(!m._lastid.empty()) { |
392 | if(!m._type.empty()) m._type += ' '; | 392 | if(!m._type.empty()) m._type += ' '; |
393 | m._type += m._lastid; | 393 | m._type += m._lastid; |
394 | } | 394 | } |
395 | m._lastid = m.output; | 395 | m._lastid = m.output; |
396 | m.output.clear(); | 396 | m.output.clear(); |
397 | } | 397 | } |
398 | \;|\n|\={ | 398 | \;|\n|\={ |
399 | modus_operandi& m = M(); | 399 | modus_operandi& m = M(); |
400 | if(m.output.empty()) { | 400 | if(m.output.empty()) { |
401 | m._name=m._lastid; | 401 | m._name=m._lastid; |
402 | }else{ | 402 | }else{ |
403 | 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? |
404 | if(!m._type.empty()) m._type += ' '; | 404 | if(!m._type.empty()) m._type += ' '; |
405 | m._type += m._lastid; | 405 | m._type += m._lastid; |
406 | } | 406 | } |
407 | m._name=m.output; | 407 | m._name=m.output; |
408 | m.output.clear(); | 408 | m.output.clear(); |
409 | } | 409 | } |
410 | BEGIN(VARINIT); | 410 | BEGIN(VARINIT); |
411 | if(*yytext!='=') | 411 | if(*yytext!='=') |
412 | unput('\n'); | 412 | unput('\n'); |
413 | } | 413 | } |
414 | } | 414 | } |
415 | <VARINIT>{ | 415 | <VARINIT>{ |
416 | \n{ | 416 | \n{ |
417 | modus_operandi& m = M(); | 417 | modus_operandi& m = M(); |
418 | string::size_type t = m.output.find_first_not_of(" \t"); | 418 | string::size_type t = m.output.find_first_not_of(" \t"); |
419 | if(t!=string::npos) | 419 | if(t!=string::npos) |
420 | m.output.erase(0,t); | 420 | m.output.erase(0,t); |
421 | t = m.output.find_last_not_of(" \t;"); | 421 | t = m.output.find_last_not_of(" \t;"); |
422 | if(t!=string::npos) | 422 | if(t!=string::npos) |
423 | m.output.erase(t+1); | 423 | m.output.erase(t+1); |
424 | 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)); |
425 | if(!m.output.empty()) | 425 | if(!m.output.empty()) |
426 | have_initializers=true; | 426 | have_initializers=true; |
427 | modi.pop_front(); | 427 | modi.pop_front(); |
428 | BEGIN(INITIAL); | 428 | BEGIN(INITIAL); |
429 | } | 429 | } |
430 | } | 430 | } |
431 | <DECLLINE>\n{ | 431 | <DECLLINE>\n{ |
432 | ECHO; | 432 | ECHO; |
433 | decl += M().output; | 433 | decl += M().output; |
434 | modi.pop_front(); | 434 | modi.pop_front(); |
435 | BEGIN(INITIAL); | 435 | BEGIN(INITIAL); |
436 | } | 436 | } |
437 | <IMPLLINE>\n{ | 437 | <IMPLLINE>\n{ |
438 | ECHO; | 438 | ECHO; |
439 | impl += M().output; | 439 | impl += M().output; |
440 | modi.pop_front(); | 440 | modi.pop_front(); |
441 | BEGIN(INITIAL); | 441 | BEGIN(INITIAL); |
442 | } | 442 | } |
443 | <CLASSLINE>\n{ | 443 | <CLASSLINE>\n{ |
444 | class_name = M().output; | 444 | class_name = M().output; |
445 | modi.pop_front(); | 445 | modi.pop_front(); |
446 | BEGIN(INITIAL); | 446 | BEGIN(INITIAL); |
447 | } | 447 | } |
448 | <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>{ |
449 | "/*"{ | 449 | "/*"{ |
450 | yy_push_state(SLASHSTAR_COMMENT); | 450 | yy_push_state(SLASHSTAR_COMMENT); |
451 | if(!M().devour_comments()) { | 451 | if(!M().devour_comments()) { |
452 | ECHO; | 452 | ECHO; |
453 | } | 453 | } |
454 | } | 454 | } |
455 | "//"{ | 455 | "//"{ |
456 | yy_push_state(SLASHSLASH_COMMENT); | 456 | yy_push_state(SLASHSLASH_COMMENT); |
457 | if(!M().devour_comments()) { | 457 | if(!M().devour_comments()) { |
458 | ECHO; | 458 | ECHO; |
459 | } | 459 | } |
460 | } | 460 | } |
461 | \" { | 461 | \" { |
462 | yy_push_state(STRING); | 462 | yy_push_state(STRING); |
463 | ECHO; | 463 | ECHO; |
464 | } | 464 | } |
465 | \'\\.\'{ | 465 | \'\\.\'{ |
466 | ECHO; | 466 | ECHO; |
467 | } | 467 | } |
468 | } | 468 | } |
469 | 469 | ||
470 | <INITIAL,METHODBLOCK,OUTPUTBLOCK>{ | 470 | <INITIAL,METHODBLOCK,OUTPUTBLOCK>{ |
471 | \"soft_anchor(); M().modify(modus_operandi::modus_text); LexerOutput("\\\"",2); | 471 | \"soft_anchor(); M().modify(modus_operandi::modus_text); LexerOutput("\\\"",2); |
472 | \nsoft_anchor(); M().modify(modus_operandi::modus_text); LexerOutput("\\n",2); | 472 | \nsoft_anchor(); M().modify(modus_operandi::modus_text); LexerOutput("\\n",2); |
473 | \rsoft_anchor(); M().modify(modus_operandi::modus_text); LexerOutput("\\r",2); | 473 | \rsoft_anchor(); M().modify(modus_operandi::modus_text); LexerOutput("\\r",2); |
474 | \tsoft_anchor(); M().modify(modus_operandi::modus_text); LexerOutput("\\t",2); | 474 | \tsoft_anchor(); M().modify(modus_operandi::modus_text); LexerOutput("\\t",2); |
475 | \bsoft_anchor(); M().modify(modus_operandi::modus_text); LexerOutput("\\b",2); | 475 | \bsoft_anchor(); M().modify(modus_operandi::modus_text); LexerOutput("\\b",2); |
476 | \asoft_anchor(); M().modify(modus_operandi::modus_text); LexerOutput("\\a",2); | 476 | \asoft_anchor(); M().modify(modus_operandi::modus_text); LexerOutput("\\a",2); |
477 | \\soft_anchor(); M().modify(modus_operandi::modus_text); LexerOutput("\\\\",2); | ||
477 | .soft_anchor(); M().modify(modus_operandi::modus_text); ECHO; | 478 | .soft_anchor(); M().modify(modus_operandi::modus_text); ECHO; |
478 | {WHITESPACE}+soft_anchor(); M().modify(modus_operandi::modus_text); ECHO; | 479 | {WHITESPACE}+soft_anchor(); M().modify(modus_operandi::modus_text); ECHO; |
479 | } | 480 | } |
480 | 481 | ||
481 | <DECLBLOCK,IMPLBLOCK,CONSTRUCTOR,DESTRUCTOR,CODEMETHODBLOCK,METHODBLOCK,CODEBLOCK>{ | 482 | <DECLBLOCK,IMPLBLOCK,CONSTRUCTOR,DESTRUCTOR,CODEMETHODBLOCK,METHODBLOCK,CODEBLOCK>{ |
482 | \<\/\%decl\>{ | 483 | \<\/\%decl\>{ |
483 | if(YY_START!=DECLBLOCK) throw preprocessor_error(CODEPOINT,"tags mismatch",lineno()); | 484 | if(YY_START!=DECLBLOCK) throw preprocessor_error(CODEPOINT,"tags mismatch",lineno()); |
484 | decl += M().output; | 485 | decl += M().output; |
485 | modi.pop_front(); | 486 | modi.pop_front(); |
486 | BEGIN(INITIAL); | 487 | BEGIN(INITIAL); |
487 | } | 488 | } |
488 | \<\/\%impl\>{ | 489 | \<\/\%impl\>{ |
489 | if(YY_START!=IMPLBLOCK) throw preprocessor_error(CODEPOINT,"tags mismatch",lineno()); | 490 | if(YY_START!=IMPLBLOCK) throw preprocessor_error(CODEPOINT,"tags mismatch",lineno()); |
490 | impl += M().output; | 491 | impl += M().output; |
491 | modi.pop_front(); | 492 | modi.pop_front(); |
492 | BEGIN(INITIAL); | 493 | BEGIN(INITIAL); |
493 | } | 494 | } |
494 | \<\/\%constructor\>{ | 495 | \<\/\%constructor\>{ |
495 | if(YY_START!=CONSTRUCTOR) throw preprocessor_error(CODEPOINT,"tags mismatch",lineno()); | 496 | if(YY_START!=CONSTRUCTOR) throw preprocessor_error(CODEPOINT,"tags mismatch",lineno()); |
496 | member_functions.push_back(member_function("","","",M().output)); | 497 | member_functions.push_back(member_function("","","",M().output)); |
497 | have_constructor = true; | 498 | have_constructor = true; |
498 | modi.pop_front(); | 499 | modi.pop_front(); |
499 | BEGIN(INITIAL); | 500 | BEGIN(INITIAL); |
500 | } | 501 | } |
501 | \<\/\%destructor\>{ | 502 | \<\/\%destructor\>{ |
502 | if(YY_START!=DESTRUCTOR) throw preprocessor_error(CODEPOINT,"tags mismatch",lineno()); | 503 | if(YY_START!=DESTRUCTOR) throw preprocessor_error(CODEPOINT,"tags mismatch",lineno()); |
503 | member_functions.push_back(member_function("","~","",M().output)); | 504 | member_functions.push_back(member_function("","~","",M().output)); |
504 | modi.pop_front(); | 505 | modi.pop_front(); |
505 | BEGIN(INITIAL); | 506 | BEGIN(INITIAL); |
506 | } | 507 | } |
507 | \<\/\%codemethod\>{ | 508 | \<\/\%codemethod\>{ |
508 | if(YY_START!=CODEMETHODBLOCK) throw preprocessor_error(CODEPOINT,"tags mismatch",lineno()); | 509 | if(YY_START!=CODEMETHODBLOCK) throw preprocessor_error(CODEPOINT,"tags mismatch",lineno()); |
509 | modus_operandi& m = M(); | 510 | modus_operandi& m = M(); |
510 | member_functions.push_back(member_function(m._type,m._name,m._args,m.output)); | 511 | member_functions.push_back(member_function(m._type,m._name,m._args,m.output)); |
511 | modi.pop_front(); | 512 | modi.pop_front(); |
512 | BEGIN(INITIAL); | 513 | BEGIN(INITIAL); |
513 | } | 514 | } |
514 | \<\/%method\> { | 515 | \<\/%method\> { |
515 | if(YY_START!=METHODBLOCK) throw preprocessor_error(CODEPOINT,"tags mismatch",lineno()); | 516 | if(YY_START!=METHODBLOCK) throw preprocessor_error(CODEPOINT,"tags mismatch",lineno()); |
516 | modus_operandi& m = M(); | 517 | modus_operandi& m = M(); |
517 | m.modify(modus_operandi::modus_code); | 518 | m.modify(modus_operandi::modus_code); |
518 | member_functions.push_back(member_function(m._type,m._name,m._args,m.output)); | 519 | member_functions.push_back(member_function(m._type,m._name,m._args,m.output)); |
519 | modi.pop_front(); | 520 | modi.pop_front(); |
520 | BEGIN(INITIAL); | 521 | BEGIN(INITIAL); |
521 | } | 522 | } |
522 | \<\/%code\> { | 523 | \<\/%code\> { |
523 | if(YY_START!=CODEBLOCK) throw preprocessor_error(CODEPOINT,"tags mismatch",lineno()); | 524 | if(YY_START!=CODEBLOCK) throw preprocessor_error(CODEPOINT,"tags mismatch",lineno()); |
524 | yy_pop_state(); | 525 | yy_pop_state(); |
525 | } | 526 | } |
526 | \n ECHO; | 527 | \n ECHO; |
527 | } | 528 | } |
528 | 529 | ||
529 | <SLASHSTAR_COMMENT>{ | 530 | <SLASHSTAR_COMMENT>{ |
530 | "*/"{ | 531 | "*/"{ |
531 | if(!M().devour_comments()) { | 532 | if(!M().devour_comments()) { |
532 | ECHO; | 533 | ECHO; |
533 | } | 534 | } |
534 | yy_pop_state(); | 535 | yy_pop_state(); |
535 | unput(' '); | 536 | unput(' '); |
536 | } | 537 | } |
537 | \n{ | 538 | \n{ |
538 | if(!M().devour_comments()) { | 539 | if(!M().devour_comments()) { |
539 | ECHO; | 540 | ECHO; |
540 | } | 541 | } |
541 | } | 542 | } |
542 | } | 543 | } |
543 | <SLASHSLASH_COMMENT>{ | 544 | <SLASHSLASH_COMMENT>{ |
544 | \n{ | 545 | \n{ |
545 | if(!M().devour_comments()) { | 546 | if(!M().devour_comments()) { |
546 | ECHO; | 547 | ECHO; |
547 | } | 548 | } |
548 | yy_pop_state(); | 549 | yy_pop_state(); |
549 | if(YY_START!=CODEBLOCK && YY_START!=CODEMETHODBLOCK && YY_START!=IMPLBLOCK && YY_START!=DECLBLOCK) | 550 | if(YY_START!=CODEBLOCK && YY_START!=CODEMETHODBLOCK && YY_START!=IMPLBLOCK && YY_START!=DECLBLOCK) |
550 | unput('\n'); | 551 | unput('\n'); |
551 | } | 552 | } |
552 | } | 553 | } |
553 | <SLASHSTAR_COMMENT,SLASHSLASH_COMMENT>.{ | 554 | <SLASHSTAR_COMMENT,SLASHSLASH_COMMENT>.{ |
554 | if(!M().devour_comments()) { | 555 | if(!M().devour_comments()) { |
555 | ECHO; | 556 | ECHO; |
556 | } | 557 | } |
557 | } | 558 | } |
558 | <STRING>{ | 559 | <STRING>{ |
559 | \\.ECHO; | 560 | \\.ECHO; |
560 | \"ECHO; yy_pop_state(); | 561 | \"ECHO; yy_pop_state(); |
561 | .ECHO; | 562 | .ECHO; |
562 | } | 563 | } |
563 | 564 | ||
564 | {WHITESPACE}+{ | 565 | {WHITESPACE}+{ |
565 | if(!(M().flags&modus_operandi::flag_devour_whitespace)) { | 566 | if(!(M().flags&modus_operandi::flag_devour_whitespace)) { |
566 | ECHO; | 567 | ECHO; |
567 | } | 568 | } |
568 | } | 569 | } |
569 | 570 | ||
570 | %% | 571 | %% |
571 | 572 | ||
572 | sitecing_parser::sitecing_parser(component_factory& f) | 573 | sitecing_parser::sitecing_parser(component_factory& f) |
573 | : factory(f), have_initializers(false), have_constructor(false), | 574 | : factory(f), have_initializers(false), have_constructor(false), |
574 | base_class("sitecing::cgi_component"), | 575 | base_class("sitecing::cgi_component"), |
575 | base_header("sitecing/cgi_component.h"), | 576 | base_header("sitecing/cgi_component.h"), |
576 | skeleton(__SC_DEFAULT_SKELETON) { | 577 | skeleton(__SC_DEFAULT_SKELETON) { |
577 | } | 578 | } |
578 | 579 | ||
579 | void sitecing_parser::preprocess(const string& in) { | 580 | void sitecing_parser::preprocess(const string& in) { |
580 | ifstream ifs(in.c_str(),ios::in); | 581 | ifstream ifs(in.c_str(),ios::in); |
581 | if(!ifs.good()) | 582 | if(!ifs.good()) |
582 | throw preprocessor_error(CODEPOINT,"failed to open input file"); | 583 | throw preprocessor_error(CODEPOINT,"failed to open input file"); |
583 | input_file = in; | 584 | input_file = in; |
584 | modi.push_front(modus_operandi(0)); | 585 | modi.push_front(modus_operandi(0)); |
585 | switch_streams(&ifs,NULL); | 586 | switch_streams(&ifs,NULL); |
586 | if(yylex()) | 587 | if(yylex()) |
587 | throw preprocessor_error(CODEPOINT,"unknown error"); | 588 | throw preprocessor_error(CODEPOINT,"unknown error"); |
588 | pragmas_t::const_iterator mp = pragmas.find("main"); | 589 | pragmas_t::const_iterator mp = pragmas.find("main"); |
589 | if(mp==pragmas.end()) { | 590 | if(mp==pragmas.end()) { |
590 | member_functions.push_back(member_function("void","main","(int _magic,va_list _args)",M().output)); | 591 | member_functions.push_back(member_function("void","main","(int _magic,va_list _args)",M().output)); |
591 | }else{ | 592 | }else{ |
592 | member_functions.push_back( | 593 | member_functions.push_back( |
593 | member_function( | 594 | member_function( |
594 | "void","main","(int _magic,va_list _args)", | 595 | "void","main","(int _magic,va_list _args)", |
595 | mp->second+"::main(_magic,_args);" | 596 | mp->second+"::main(_magic,_args);" |
596 | ) | 597 | ) |
597 | ); | 598 | ); |
598 | } | 599 | } |
599 | if(have_initializers && !have_constructor) | 600 | if(have_initializers && !have_constructor) |
600 | member_functions.push_back(member_function("","","","")); | 601 | member_functions.push_back(member_function("","","","")); |
601 | sitecing_enflesher enflesher(*this); | 602 | sitecing_enflesher enflesher(*this); |
602 | enflesher.enflesh(); | 603 | enflesher.enflesh(); |
603 | } | 604 | } |
604 | 605 | ||