author | Michael Krelin <hacker@klever.net> | 2005-03-30 21:58:44 (UTC) |
---|---|---|
committer | Michael Krelin <hacker@klever.net> | 2005-03-30 21:58:44 (UTC) |
commit | 5c757590c7561f6d85b3f9011aa0695c4111b379 (patch) (unidiff) | |
tree | e0bf20ca58b3e7bd9cc4eda54db5674ba1d71db0 | |
parent | 3ddbfeafde93d1aab16a710498d86eef4e787406 (diff) | |
download | sitecing-5c757590c7561f6d85b3f9011aa0695c4111b379.zip sitecing-5c757590c7561f6d85b3f9011aa0695c4111b379.tar.gz sitecing-5c757590c7561f6d85b3f9011aa0695c4111b379.tar.bz2 |
1. fixed a bug just introduced, preventing the last skeleton-generated file
from being written.
2. introduced pragma directive and pragma main=class
3. minor changes of no importance
-rw-r--r-- | include/sitecing/sitecing_enflesher.h | 9 | ||||
-rw-r--r-- | include/sitecing/sitecing_parser.h | 8 | ||||
-rw-r--r-- | lib/component_factory.cc | 2 | ||||
-rw-r--r-- | lib/sitecing_enflesher.ll | 8 | ||||
-rw-r--r-- | lib/sitecing_parser.ll | 49 |
5 files changed, 72 insertions, 4 deletions
diff --git a/include/sitecing/sitecing_enflesher.h b/include/sitecing/sitecing_enflesher.h index 8bc43a0..db15bc3 100644 --- a/include/sitecing/sitecing_enflesher.h +++ b/include/sitecing/sitecing_enflesher.h | |||
@@ -69,11 +69,20 @@ class sitecing_enflesher : public sitecing_enflesherFlexLexer { | |||
69 | 69 | ||
70 | /** | 70 | /** |
71 | * Close previously opened output stream, rename to the 'correct' | 71 | * Close previously opened output stream, rename to the 'correct' |
72 | * destination filename, if needed, and open new file. | 72 | * destination filename, if needed, and open new file. |
73 | * @see outs | 73 | * @see outs |
74 | * @see outs_filename | 74 | * @see outs_filename |
75 | * @see outs_close | ||
75 | */ | 76 | */ |
76 | void outs_open(const string& nfile); | 77 | void outs_open(const string& nfile); |
78 | /** | ||
79 | * Close previously opened output stream, and rename to the 'correct' | ||
80 | * destination filename, if needed. | ||
81 | * @see outs_open | ||
82 | * @see outs | ||
83 | * @see outs_filename | ||
84 | */ | ||
85 | void outs_close(); | ||
77 | }; | 86 | }; |
78 | 87 | ||
79 | #endif /* __SITECING_SITECING_ENFLESHER_H */ | 88 | #endif /* __SITECING_SITECING_ENFLESHER_H */ |
diff --git a/include/sitecing/sitecing_parser.h b/include/sitecing/sitecing_parser.h index 22d716f..a8474f3 100644 --- a/include/sitecing/sitecing_parser.h +++ b/include/sitecing/sitecing_parser.h | |||
@@ -288,12 +288,20 @@ class sitecing_parser : public sitecing_parserFlexLexer { | |||
288 | */ | 288 | */ |
289 | string impl; | 289 | string impl; |
290 | /** | 290 | /** |
291 | * The reference to the component factory object. | 291 | * The reference to the component factory object. |
292 | */ | 292 | */ |
293 | component_factory& factory; | 293 | component_factory& factory; |
294 | /** | ||
295 | * Pragma map type. | ||
296 | */ | ||
297 | typedef map<string,string> pragmas_t; | ||
298 | /** | ||
299 | * Pragma's found in the component. | ||
300 | */ | ||
301 | pragmas_t pragmas; | ||
294 | 302 | ||
295 | /** | 303 | /** |
296 | * @param f the component factory. | 304 | * @param f the component factory. |
297 | */ | 305 | */ |
298 | sitecing_parser(component_factory& f); | 306 | sitecing_parser(component_factory& f); |
299 | 307 | ||
diff --git a/lib/component_factory.cc b/lib/component_factory.cc index b8f5a16..1253111 100644 --- a/lib/component_factory.cc +++ b/lib/component_factory.cc | |||
@@ -316,13 +316,13 @@ namespace sitecing { | |||
316 | 316 | ||
317 | void component_factory::get_ancestors(const string& component,file_list_t& rv) { | 317 | void component_factory::get_ancestors(const string& component,file_list_t& rv) { |
318 | string cn = root_intermediate+normalize_path(component,strip_trailing_slash|strip_leading_slash)+".ancestors"; | 318 | string cn = root_intermediate+normalize_path(component,strip_trailing_slash|strip_leading_slash)+".ancestors"; |
319 | make(cn); | 319 | make(cn); |
320 | ifstream ifs(cn.c_str()); | 320 | ifstream ifs(cn.c_str()); |
321 | if(!ifs.good()) | 321 | if(!ifs.good()) |
322 | throw konforka::exception(CODEPOINT,"filed to access component .ancestors"); | 322 | throw konforka::exception(CODEPOINT,string("failed to access component '")+component+"' .ancestors"); |
323 | rv.clear(); | 323 | rv.clear(); |
324 | while(!ifs.eof()) { | 324 | while(!ifs.eof()) { |
325 | string a; | 325 | string a; |
326 | ifs >> a; | 326 | ifs >> a; |
327 | if(!a.empty()) | 327 | if(!a.empty()) |
328 | rv.push_back(a); | 328 | rv.push_back(a); |
diff --git a/lib/sitecing_enflesher.ll b/lib/sitecing_enflesher.ll index 46489c7..bb667be 100644 --- a/lib/sitecing_enflesher.ll +++ b/lib/sitecing_enflesher.ll | |||
@@ -176,22 +176,23 @@ void sitecing_enflesher::LexerOutput(const char *buf,int size) { | |||
176 | void sitecing_enflesher::enflesh() { | 176 | void sitecing_enflesher::enflesh() { |
177 | ifstream ifs(parser.skeleton.c_str()); | 177 | ifstream ifs(parser.skeleton.c_str()); |
178 | if(!ifs.good()) | 178 | if(!ifs.good()) |
179 | throw preprocessor_error(CODEPOINT,"failed to open skeleton file"); | 179 | throw preprocessor_error(CODEPOINT,"failed to open skeleton file"); |
180 | switch_streams(&ifs,NULL); | 180 | switch_streams(&ifs,NULL); |
181 | yylex(); | 181 | yylex(); |
182 | outs_close(); | ||
182 | } | 183 | } |
183 | 184 | ||
184 | void sitecing_enflesher::anchor() { | 185 | void sitecing_enflesher::anchor() { |
185 | if(!anchoraged) | 186 | if(!anchoraged) |
186 | return; | 187 | return; |
187 | outs << "\n#line " << lineno() << " \"" << parser.skeleton << "\"\n"; | 188 | outs << "\n#line " << lineno() << " \"" << parser.skeleton << "\"\n"; |
188 | anchor_time = false; | 189 | anchor_time = false; |
189 | } | 190 | } |
190 | 191 | ||
191 | void sitecing_enflesher::outs_open(const string& nfile) { | 192 | void sitecing_enflesher::outs_close() { |
192 | if(!outs_filename.empty()) { | 193 | if(!outs_filename.empty()) { |
193 | outs.flush(); | 194 | outs.flush(); |
194 | outs.close(); | 195 | outs.close(); |
195 | outs.clear(); | 196 | outs.clear(); |
196 | /* | 197 | /* |
197 | * compare source and destination files. | 198 | * compare source and destination files. |
@@ -241,12 +242,17 @@ void sitecing_enflesher::outs_open(const string& nfile) { | |||
241 | if(overwrite) { | 242 | if(overwrite) { |
242 | cerr << "renaming '" << fn_s << "'" << endl; | 243 | cerr << "renaming '" << fn_s << "'" << endl; |
243 | if(rename(fn_s.c_str(),fn_d.c_str())) | 244 | if(rename(fn_s.c_str(),fn_d.c_str())) |
244 | throw preprocessor_error(CODEPOINT,"failed to rename() generated output"); | 245 | throw preprocessor_error(CODEPOINT,"failed to rename() generated output"); |
245 | } | 246 | } |
246 | } | 247 | } |
248 | outs_filename.erase(); | ||
249 | } | ||
250 | |||
251 | void sitecing_enflesher::outs_open(const string& nfile) { | ||
252 | outs_close(); | ||
247 | outs_filename = nfile; | 253 | outs_filename = nfile; |
248 | outs.open((nfile+".new").c_str(),ios::trunc); | 254 | outs.open((nfile+".new").c_str(),ios::trunc); |
249 | if(!outs.good()) | 255 | if(!outs.good()) |
250 | throw preprocessor_error(CODEPOINT,"failed to write preprocessor output"); | 256 | throw preprocessor_error(CODEPOINT,"failed to write preprocessor output"); |
251 | } | 257 | } |
252 | /* | 258 | /* |
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 | |||
@@ -20,12 +20,13 @@ using namespace sitecing; | |||
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 | ||
@@ -91,12 +92,16 @@ NOIDCHAR [^A-Za-z0-9_] | |||
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 | } |
@@ -107,12 +112,42 @@ NOIDCHAR [^A-Za-z0-9_] | |||
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 += ' '; |
@@ -403,13 +438,13 @@ NOIDCHAR [^A-Za-z0-9_] | |||
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 | } |
@@ -543,13 +578,23 @@ void sitecing_parser::preprocess(const string& in) { | |||
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 | ||