summaryrefslogtreecommitdiffabout
path: root/lib/sitecing_parser.ll
Unidiff
Diffstat (limited to 'lib/sitecing_parser.ll') (more/less context) (ignore whitespace changes)
-rw-r--r--lib/sitecing_parser.ll49
1 files changed, 47 insertions, 2 deletions
diff --git a/lib/sitecing_parser.ll b/lib/sitecing_parser.ll
index 6cb78f3..8ba8673 100644
--- a/lib/sitecing_parser.ll
+++ b/lib/sitecing_parser.ll
@@ -10,32 +10,33 @@ using namespace std;
10#include "sitecing/sitecing_util.h" 10#include "sitecing/sitecing_util.h"
11#include "sitecing/sitecing_exception.h" 11#include "sitecing/sitecing_exception.h"
12using namespace sitecing; 12using namespace sitecing;
13#define sitecing_parser_flexlexer_once 13#define sitecing_parser_flexlexer_once
14#include "sitecing/sitecing_parser.h" 14#include "sitecing/sitecing_parser.h"
15#include "sitecing/sitecing_enflesher.h" 15#include "sitecing/sitecing_enflesher.h"
16#undef yyFlexLexer 16#undef yyFlexLexer
17#define yyFlexLexer sitecing_parserFlexLexer 17#define yyFlexLexer sitecing_parserFlexLexer
18%} 18%}
19%x SLASHSTAR_COMMENT SLASHSLASH_COMMENT STRING 19%x SLASHSTAR_COMMENT SLASHSLASH_COMMENT STRING
20%x CODELINE CLASSLINE DECLLINE IMPLLINE DECLBLOCK IMPLBLOCK VARLINE VARINIT 20%x CODELINE CLASSLINE DECLLINE IMPLLINE DECLBLOCK IMPLBLOCK VARLINE VARINIT
21%x IMPORTLINE IMPORTCOMPONENT 21%x IMPORTLINE IMPORTCOMPONENT
22%x IMPORTTYPELINE IMPORTTYPECOMPONENT 22%x IMPORTTYPELINE IMPORTTYPECOMPONENT
23%x DERIVELINE DERIVECOMPONENT 23%x DERIVELINE DERIVECOMPONENT
24%x CONSTRUCTOR DESTRUCTOR CODEMETHODLINE CODEMETHODARGS 24%x CONSTRUCTOR DESTRUCTOR CODEMETHODLINE CODEMETHODARGS
25%x CODEMETHODBLOCK INLINE METHODLINE METHODARGS METHODBLOCK CODEBLOCK OUTPUTBLOCK 25%x CODEMETHODBLOCK INLINE METHODLINE METHODARGS METHODBLOCK CODEBLOCK OUTPUTBLOCK
26%x PRAGMALINE
26%option 8bit c++ verbose noyywrap yyclass="sitecing_parser" prefix="sitecing_parser" stack yylineno 27%option 8bit c++ verbose noyywrap yyclass="sitecing_parser" prefix="sitecing_parser" stack yylineno
27 28
28 WHITESPACE[ \t] 29 WHITESPACE[ \t]
29 ID [A-Za-z_][A-Za-z0-9_]* 30 ID [A-Za-z_][A-Za-z0-9_]*
30 NOIDCHAR[^A-Za-z0-9_] 31 NOIDCHAR[^A-Za-z0-9_]
31 32
32%% 33%%
33 34
34<INITIAL>{ 35<INITIAL>{
35 ^\%\%class{WHITESPACE}+{ 36 ^\%\%class{WHITESPACE}+{
36 // TODO: signal error if we already have class name acquired from source. 37 // TODO: signal error if we already have class name acquired from source.
37 modi.push_front(modus_operandi(modus_operandi::flag_devour_comments|modus_operandi::flag_devour_whitespace)); 38 modi.push_front(modus_operandi(modus_operandi::flag_devour_comments|modus_operandi::flag_devour_whitespace));
38 BEGIN(CLASSLINE); 39 BEGIN(CLASSLINE);
39 } 40 }
40 ^\%\%decl{WHITESPACE}+{ 41 ^\%\%decl{WHITESPACE}+{
41 modi.push_front(modus_operandi(0)); 42 modi.push_front(modus_operandi(0));
@@ -81,48 +82,82 @@ NOIDCHAR [^A-Za-z0-9_]
81 } 82 }
82 \<\%destructor\>{ 83 \<\%destructor\>{
83 modi.push_front(modus_operandi()); 84 modi.push_front(modus_operandi());
84 anchor(); 85 anchor();
85 BEGIN(DESTRUCTOR); 86 BEGIN(DESTRUCTOR);
86 } 87 }
87 \<\%codemethod{WHITESPACE}+{ 88 \<\%codemethod{WHITESPACE}+{
88 modi.push_front(modus_operandi(modus_operandi::flag_devour_comments)); 89 modi.push_front(modus_operandi(modus_operandi::flag_devour_comments));
89 anchor(); 90 anchor();
90 BEGIN(CODEMETHODLINE); 91 BEGIN(CODEMETHODLINE);
91 } 92 }
92 \<\%method{WHITESPACE}+ { 93 \<\%method{WHITESPACE}+ {
93 modi.push_front(modus_operandi(modus_operandi::flag_devour_comments)); 94 modi.push_front(modus_operandi(modus_operandi::flag_devour_comments));
94 anchor(); 95 anchor();
95 BEGIN(METHODLINE); 96 BEGIN(METHODLINE);
96 } 97 }
98 ^\%\%pragma{WHITESPACE}+{
99 modi.push_front(modus_operandi(modus_operandi::flag_devour_comments));
100 BEGIN(PRAGMALINE);
101 }
97 <<EOF>>{ 102 <<EOF>>{
98 assert(modi.size()==1); 103 assert(modi.size()==1);
99 M().modify(modus_operandi::modus_preop); 104 M().modify(modus_operandi::modus_preop);
100 LexerOutput(";",1); 105 LexerOutput(";",1);
101 return 0; 106 return 0;
102 } 107 }
103} 108}
104 <<EOF>>throw preprocessor_error(CODEPOINT,"unexpected end of file",lineno()); 109 <<EOF>>throw preprocessor_error(CODEPOINT,"unexpected end of file",lineno());
105 110
106<CODEBLOCK,CODEMETHODBLOCK>{ 111<CODEBLOCK,CODEMETHODBLOCK>{
107 "<%output>"{ 112 "<%output>"{
108 anchor(); 113 anchor();
109 yy_push_state(OUTPUTBLOCK); 114 yy_push_state(OUTPUTBLOCK);
110 } 115 }
111} 116}
112 117
118<PRAGMALINE>{
119 {WHITESPACE}+{
120 modus_operandi& m = M();
121 if(!m.output.empty()) {
122 string::size_type eq = m.output.find('=');
123 if(eq==string::npos) {
124 pragmas[m.output]=m.output;
125 }else{
126 pragmas[m.output.substr(0,eq)] = m.output.substr(eq+1);
127 }
128 m.output.erase();
129 }
130 }
131 \n {
132 modus_operandi& m = M();
133 if(!m.output.empty()) {
134 string::size_type eq = m.output.find('=');
135 if(eq==string::npos) {
136 pragmas[m.output]=m.output;
137 }else{
138 pragmas[m.output.substr(0,eq)] = m.output.substr(eq+1);
139 }
140 m.output.erase();
141 }
142 modi.pop_front();
143 BEGIN(INITIAL);
144 anchor();
145 }
146}
147
113<METHODLINE>{ 148<METHODLINE>{
114 {WHITESPACE}+{ 149 {WHITESPACE}+{
115 modus_operandi& m = modi.front(); 150 modus_operandi& m = modi.front();
116 if(!m.output.empty()) { 151 if(!m.output.empty()) {
117 if(!m._lastid.empty()) { 152 if(!m._lastid.empty()) {
118 if(!m._type.empty()) m._type += ' '; 153 if(!m._type.empty()) m._type += ' ';
119 m._type += m._lastid; 154 m._type += m._lastid;
120 } 155 }
121 m._lastid = m.output; 156 m._lastid = m.output;
122 m.output.clear(); 157 m.output.clear();
123 } 158 }
124 } 159 }
125 \*{ 160 \*{
126 modus_operandi& m = modi.front(); 161 modus_operandi& m = modi.front();
127 ECHO; 162 ECHO;
128 if(!m._lastid.empty()) { 163 if(!m._lastid.empty()) {
@@ -393,33 +428,33 @@ NOIDCHAR [^A-Za-z0-9_]
393 ECHO; 428 ECHO;
394 decl += modi.front().output; 429 decl += modi.front().output;
395 modi.pop_front(); 430 modi.pop_front();
396 BEGIN(INITIAL); 431 BEGIN(INITIAL);
397} 432}
398 <IMPLLINE>\n{ 433 <IMPLLINE>\n{
399 ECHO; 434 ECHO;
400 impl += modi.front().output; 435 impl += modi.front().output;
401 modi.pop_front(); 436 modi.pop_front();
402 BEGIN(INITIAL); 437 BEGIN(INITIAL);
403} 438}
404 <CLASSLINE>\n{ 439 <CLASSLINE>\n{
405 class_name = modi.front().output; 440 class_name = modi.front().output;
406 modi.pop_front(); 441 modi.pop_front();
407 BEGIN(INITIAL); 442 BEGIN(INITIAL);
408} 443}
409<CLASSLINE,DECLLINE,IMPLLINE,VARLINE,VARINIT,IMPORTLINE,IMPORTCOMPONENT,CODEMETHODLINE,CODEMETHODARGS,INLINE,METHODLINE,METHODARGS,DECLBLOCK,IMPLBLOCK,CONSTRUCTOR,DESTRUCTOR,CODEMETHODBLOCK,CODELINE,CODEBLOCK>{ 444<CLASSLINE,DECLLINE,IMPLLINE,VARLINE,VARINIT,IMPORTLINE,IMPORTCOMPONENT,CODEMETHODLINE,CODEMETHODARGS,INLINE,METHODLINE,METHODARGS,DECLBLOCK,IMPLBLOCK,CONSTRUCTOR,DESTRUCTOR,CODEMETHODBLOCK,CODELINE,CODEBLOCK,PRAGMALINE>{
410 "/*"{ 445 "/*"{
411 yy_push_state(SLASHSTAR_COMMENT); 446 yy_push_state(SLASHSTAR_COMMENT);
412 if(!M().devour_comments()) { 447 if(!M().devour_comments()) {
413 ECHO; 448 ECHO;
414 } 449 }
415 } 450 }
416 "//"{ 451 "//"{
417 yy_push_state(SLASHSLASH_COMMENT); 452 yy_push_state(SLASHSLASH_COMMENT);
418 if(!M().devour_comments()) { 453 if(!M().devour_comments()) {
419 ECHO; 454 ECHO;
420 } 455 }
421 } 456 }
422 \" { 457 \" {
423 yy_push_state(STRING); 458 yy_push_state(STRING);
424 ECHO; 459 ECHO;
425 } 460 }
@@ -533,33 +568,43 @@ NOIDCHAR [^A-Za-z0-9_]
533sitecing_parser::sitecing_parser(component_factory& f) 568sitecing_parser::sitecing_parser(component_factory& f)
534 : factory(f), have_initializers(false), have_constructor(false), 569 : factory(f), have_initializers(false), have_constructor(false),
535 base_class("sitecing::cgi_component"), 570 base_class("sitecing::cgi_component"),
536 base_header("sitecing/cgi_component.h"), 571 base_header("sitecing/cgi_component.h"),
537 skeleton(__SC_DEFAULT_SKELETON) { 572 skeleton(__SC_DEFAULT_SKELETON) {
538 } 573 }
539 574
540void sitecing_parser::preprocess(const string& in) { 575void sitecing_parser::preprocess(const string& in) {
541 ifstream ifs(in.c_str(),ios::in); 576 ifstream ifs(in.c_str(),ios::in);
542 if(!ifs.good()) 577 if(!ifs.good())
543 throw preprocessor_error(CODEPOINT,"failed to open input file"); 578 throw preprocessor_error(CODEPOINT,"failed to open input file");
544 input_file = in; 579 input_file = in;
545 modi.push_front(modus_operandi(0)); 580 modi.push_front(modus_operandi(0));
546 switch_streams(&ifs,NULL); 581 switch_streams(&ifs,NULL);
547 if(yylex()) 582 if(yylex())
548 throw preprocessor_error(CODEPOINT,"unknown error"); 583 throw preprocessor_error(CODEPOINT,"unknown error");
549 member_functions.push_back(member_function("void","main","(int _magic,va_list _args)",M().output)); 584 pragmas_t::const_iterator mp = pragmas.find("main");
585 if(mp==pragmas.end()) {
586 member_functions.push_back(member_function("void","main","(int _magic,va_list _args)",M().output));
587 }else{
588 member_functions.push_back(
589 member_function(
590 "void","main","(int _magic,va_list _args)",
591 mp->second+"::main(_magic,_args);"
592 )
593 );
594 }
550 if(have_initializers && !have_constructor) 595 if(have_initializers && !have_constructor)
551 member_functions.push_back(member_function("","","","")); 596 member_functions.push_back(member_function("","","",""));
552 sitecing_enflesher enflesher(*this); 597 sitecing_enflesher enflesher(*this);
553 enflesher.enflesh(); 598 enflesher.enflesh();
554} 599}
555 600
556void sitecing_parser::LexerOutput(const char* buf,int size) { 601void sitecing_parser::LexerOutput(const char* buf,int size) {
557 assert(modi.size()); 602 assert(modi.size());
558 M().output.append(buf,size); 603 M().output.append(buf,size);
559} 604}
560 605
561static const char *modus_transitions 606static const char *modus_transitions
562 [sitecing_parser::modus_operandi::modi] 607 [sitecing_parser::modus_operandi::modi]
563 [sitecing_parser::modus_operandi::modi] = { 608 [sitecing_parser::modus_operandi::modi] = {
564// To: 609// To:
565// code preop postop text From: 610// code preop postop text From: