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 /lib | |
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-- | lib/component_factory.cc | 2 | ||||
-rw-r--r-- | lib/sitecing_enflesher.ll | 8 | ||||
-rw-r--r-- | lib/sitecing_parser.ll | 49 |
3 files changed, 55 insertions, 4 deletions
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 | |||
@@ -290,43 +290,43 @@ namespace sitecing { | |||
290 | // child | 290 | // child |
291 | if(dup2(stdo,1)!=1) | 291 | if(dup2(stdo,1)!=1) |
292 | _exit(-1); | 292 | _exit(-1); |
293 | if(dup2(stde,2)!=2) | 293 | if(dup2(stde,2)!=2) |
294 | _exit(-1); | 294 | _exit(-1); |
295 | close(0); | 295 | close(0); |
296 | execvp(cmd.c_str(),(char**)&argv.front()); | 296 | execvp(cmd.c_str(),(char**)&argv.front()); |
297 | _exit(-1); | 297 | _exit(-1); |
298 | } | 298 | } |
299 | // parent | 299 | // parent |
300 | close(stdo); close(stde); | 300 | close(stdo); close(stde); |
301 | int rv; | 301 | int rv; |
302 | if(waitpid(pid,&rv,0)<0) | 302 | if(waitpid(pid,&rv,0)<0) |
303 | throw konforka::exception(CODEPOINT,"failed to waitpid()"); | 303 | throw konforka::exception(CODEPOINT,"failed to waitpid()"); |
304 | return rv; | 304 | return rv; |
305 | } | 305 | } |
306 | 306 | ||
307 | string component_factory::get_classname(const string& component) { | 307 | string component_factory::get_classname(const string& component) { |
308 | string cn = root_intermediate+normalize_path(component,strip_trailing_slash|strip_leading_slash)+".classname"; | 308 | string cn = root_intermediate+normalize_path(component,strip_trailing_slash|strip_leading_slash)+".classname"; |
309 | make(cn); | 309 | make(cn); |
310 | ifstream ifs(cn.c_str()); | 310 | ifstream ifs(cn.c_str()); |
311 | if(!ifs.good()) | 311 | if(!ifs.good()) |
312 | throw konforka::exception(CODEPOINT,"failed to access component .classname"); | 312 | throw konforka::exception(CODEPOINT,"failed to access component .classname"); |
313 | ifs >> cn; | 313 | ifs >> cn; |
314 | return cn; | 314 | return cn; |
315 | } | 315 | } |
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); |
329 | } | 329 | } |
330 | } | 330 | } |
331 | 331 | ||
332 | } | 332 | } |
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 | |||
@@ -150,105 +150,111 @@ ID [A-Za-z_][A-Za-z0-9_]* | |||
150 | \<\%ancestors:typedefs\%\> { | 150 | \<\%ancestors:typedefs\%\> { |
151 | for(sitecing_parser::ancestor_classes_t::const_iterator i=parser.ancestor_classes.begin();i!=parser.ancestor_classes.end();++i) { | 151 | for(sitecing_parser::ancestor_classes_t::const_iterator i=parser.ancestor_classes.begin();i!=parser.ancestor_classes.end();++i) { |
152 | outs << "typedef class " << parser.factory.get_classname(i->path) << " " << i->name << ";\n"; | 152 | outs << "typedef class " << parser.factory.get_classname(i->path) << " " << i->name << ";\n"; |
153 | } | 153 | } |
154 | anchor_time = true; | 154 | anchor_time = true; |
155 | } | 155 | } |
156 | \<\%ancestors:import\%\> { | 156 | \<\%ancestors:import\%\> { |
157 | for(sitecing_parser::ancestor_classes_t::const_iterator i=parser.ancestor_classes.begin();i!=parser.ancestor_classes.end();++i) { | 157 | for(sitecing_parser::ancestor_classes_t::const_iterator i=parser.ancestor_classes.begin();i!=parser.ancestor_classes.end();++i) { |
158 | outs << i->name << "::__do_imports();\n"; | 158 | outs << i->name << "::__do_imports();\n"; |
159 | } | 159 | } |
160 | anchor_time = true; | 160 | anchor_time = true; |
161 | } | 161 | } |
162 | 162 | ||
163 | \n { | 163 | \n { |
164 | if(anchor_time) | 164 | if(anchor_time) |
165 | anchor(); | 165 | anchor(); |
166 | ECHO; | 166 | ECHO; |
167 | } | 167 | } |
168 | . ECHO; | 168 | . ECHO; |
169 | 169 | ||
170 | %% | 170 | %% |
171 | 171 | ||
172 | void sitecing_enflesher::LexerOutput(const char *buf,int size) { | 172 | void sitecing_enflesher::LexerOutput(const char *buf,int size) { |
173 | outs.write(buf,size); | 173 | outs.write(buf,size); |
174 | } | 174 | } |
175 | 175 | ||
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. |
198 | * | 199 | * |
199 | * one can also keep a hash for the old one and compute one for the | 200 | * one can also keep a hash for the old one and compute one for the |
200 | * output while writing, but I'm not sure if it's any better. Surely a | 201 | * output while writing, but I'm not sure if it's any better. Surely a |
201 | * bit less accurate, unless we're going to compare it in case of | 202 | * bit less accurate, unless we're going to compare it in case of |
202 | * difference, anyway. | 203 | * difference, anyway. |
203 | */ | 204 | */ |
204 | bool overwrite = false; | 205 | bool overwrite = false; |
205 | struct stat st_s, st_d; | 206 | struct stat st_s, st_d; |
206 | string fn_s = outs_filename+".new"; | 207 | string fn_s = outs_filename+".new"; |
207 | string fn_d = outs_filename; | 208 | string fn_d = outs_filename; |
208 | if(stat(fn_d.c_str(),&st_d)) { | 209 | if(stat(fn_d.c_str(),&st_d)) { |
209 | overwrite = true; | 210 | overwrite = true; |
210 | }else{ | 211 | }else{ |
211 | if(stat(fn_s.c_str(),&st_s)) | 212 | if(stat(fn_s.c_str(),&st_s)) |
212 | throw preprocessor_error(CODEPOINT,"failed to stat() supposedly created file"); | 213 | throw preprocessor_error(CODEPOINT,"failed to stat() supposedly created file"); |
213 | if(st_s.st_size!=st_d.st_size) { | 214 | if(st_s.st_size!=st_d.st_size) { |
214 | overwrite = true; | 215 | overwrite = true; |
215 | }else{ | 216 | }else{ |
216 | ifstream i_s(fn_s.c_str(),ios::in); | 217 | ifstream i_s(fn_s.c_str(),ios::in); |
217 | if(!i_s) | 218 | if(!i_s) |
218 | throw preprocessor_error(CODEPOINT,"failed to open supposedly created file"); | 219 | throw preprocessor_error(CODEPOINT,"failed to open supposedly created file"); |
219 | ifstream i_d(fn_d.c_str(),ios::in); | 220 | ifstream i_d(fn_d.c_str(),ios::in); |
220 | if(!i_d) | 221 | if(!i_d) |
221 | throw preprocessor_error(CODEPOINT,"failed to open the old preprocessed source"); | 222 | throw preprocessor_error(CODEPOINT,"failed to open the old preprocessed source"); |
222 | off_t remaining = st_s.st_size; | 223 | off_t remaining = st_s.st_size; |
223 | char t1[2048]; | 224 | char t1[2048]; |
224 | char t2[sizeof(t1)]; | 225 | char t2[sizeof(t1)]; |
225 | while(remaining) { | 226 | while(remaining) { |
226 | int rb = remaining; | 227 | int rb = remaining; |
227 | if(rb>sizeof(t1)) | 228 | if(rb>sizeof(t1)) |
228 | rb = sizeof(t1); | 229 | rb = sizeof(t1); |
229 | if(i_s.read(t1,rb).gcount()!=rb) | 230 | if(i_s.read(t1,rb).gcount()!=rb) |
230 | throw preprocessor_error(CODEPOINT,"error reading just created file"); | 231 | throw preprocessor_error(CODEPOINT,"error reading just created file"); |
231 | if(i_d.read(t2,rb).gcount()!=rb) | 232 | if(i_d.read(t2,rb).gcount()!=rb) |
232 | throw preprocessor_error(CODEPOINT,"error reading the old preprocessed source"); | 233 | throw preprocessor_error(CODEPOINT,"error reading the old preprocessed source"); |
233 | if(memcmp(t1,t2,rb)) { | 234 | if(memcmp(t1,t2,rb)) { |
234 | overwrite = true; | 235 | overwrite = true; |
235 | break; | 236 | break; |
236 | } | 237 | } |
237 | remaining -= rb; | 238 | remaining -= rb; |
238 | } | 239 | } |
239 | } | 240 | } |
240 | } | 241 | } |
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 | /* |
253 | * vim:set ft=lex: | 259 | * vim:set ft=lex: |
254 | */ | 260 | */ |
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 | |||
@@ -1,57 +1,58 @@ | |||
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 "sitecing/sitecing_util.h" | 10 | #include "sitecing/sitecing_util.h" |
11 | #include "sitecing/sitecing_exception.h" | 11 | #include "sitecing/sitecing_exception.h" |
12 | using namespace sitecing; | 12 | using 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)); |
42 | anchor(); | 43 | anchor(); |
43 | BEGIN(DECLLINE); | 44 | BEGIN(DECLLINE); |
44 | } | 45 | } |
45 | ^\%\%impl{WHITESPACE}+{ | 46 | ^\%\%impl{WHITESPACE}+{ |
46 | modi.push_front(modus_operandi(0)); | 47 | modi.push_front(modus_operandi(0)); |
47 | anchor(); | 48 | anchor(); |
48 | BEGIN(IMPLLINE); | 49 | BEGIN(IMPLLINE); |
49 | } | 50 | } |
50 | \<\%decl\> { | 51 | \<\%decl\> { |
51 | modi.push_front(modus_operandi(0)); | 52 | modi.push_front(modus_operandi(0)); |
52 | anchor(); | 53 | anchor(); |
53 | BEGIN(DECLBLOCK); | 54 | BEGIN(DECLBLOCK); |
54 | } | 55 | } |
55 | \<\%impl\> { | 56 | \<\%impl\> { |
56 | modi.push_front(modus_operandi(0)); | 57 | modi.push_front(modus_operandi(0)); |
57 | anchor(); | 58 | anchor(); |
@@ -65,80 +66,114 @@ NOIDCHAR [^A-Za-z0-9_] | |||
65 | ^\%\%import{WHITESPACE}+{ | 66 | ^\%\%import{WHITESPACE}+{ |
66 | modi.push_front(modus_operandi(modus_operandi::flag_devour_comments)); | 67 | modi.push_front(modus_operandi(modus_operandi::flag_devour_comments)); |
67 | BEGIN(IMPORTLINE); | 68 | BEGIN(IMPORTLINE); |
68 | } | 69 | } |
69 | ^\%\%import_type{WHITESPACE}+ { | 70 | ^\%\%import_type{WHITESPACE}+ { |
70 | modi.push_front(modus_operandi(modus_operandi::flag_devour_comments)); | 71 | modi.push_front(modus_operandi(modus_operandi::flag_devour_comments)); |
71 | BEGIN(IMPORTTYPELINE); | 72 | BEGIN(IMPORTTYPELINE); |
72 | } | 73 | } |
73 | ^\%\%derive{WHITESPACE}+{ | 74 | ^\%\%derive{WHITESPACE}+{ |
74 | modi.push_front(modus_operandi(modus_operandi::flag_devour_comments)); | 75 | modi.push_front(modus_operandi(modus_operandi::flag_devour_comments)); |
75 | BEGIN(DERIVELINE); | 76 | BEGIN(DERIVELINE); |
76 | } | 77 | } |
77 | \<\%constructor\>{ | 78 | \<\%constructor\>{ |
78 | modi.push_front(modus_operandi()); | 79 | modi.push_front(modus_operandi()); |
79 | anchor(); | 80 | anchor(); |
80 | BEGIN(CONSTRUCTOR); | 81 | BEGIN(CONSTRUCTOR); |
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()) { |
129 | if(!m._type.empty()) m._type += ' '; | 164 | if(!m._type.empty()) m._type += ' '; |
130 | m._type += m._lastid; | 165 | m._type += m._lastid; |
131 | } | 166 | } |
132 | m._lastid = m.output; | 167 | m._lastid = m.output; |
133 | m.output.clear(); | 168 | m.output.clear(); |
134 | } | 169 | } |
135 | \({ | 170 | \({ |
136 | modus_operandi& m = modi.front(); | 171 | modus_operandi& m = modi.front(); |
137 | if(m.output.empty()) { | 172 | if(m.output.empty()) { |
138 | m._name=m._lastid; | 173 | m._name=m._lastid; |
139 | }else{ | 174 | }else{ |
140 | if(!m._lastid.empty()) { // XXX: lastid, I believe should never be emtpy... | 175 | if(!m._lastid.empty()) { // XXX: lastid, I believe should never be emtpy... |
141 | if(!m._type.empty()) m._type += ' '; | 176 | if(!m._type.empty()) m._type += ' '; |
142 | m._type += m._lastid; | 177 | m._type += m._lastid; |
143 | } | 178 | } |
144 | m._name = m.output; | 179 | m._name = m.output; |
@@ -377,65 +412,65 @@ NOIDCHAR [^A-Za-z0-9_] | |||
377 | \n{ | 412 | \n{ |
378 | modus_operandi& m = modi.front(); | 413 | modus_operandi& m = modi.front(); |
379 | string::size_type t = m.output.find_first_not_of(" \t"); | 414 | string::size_type t = m.output.find_first_not_of(" \t"); |
380 | if(t!=string::npos) | 415 | if(t!=string::npos) |
381 | m.output.erase(0,t); | 416 | m.output.erase(0,t); |
382 | t = m.output.find_last_not_of(" \t;"); | 417 | t = m.output.find_last_not_of(" \t;"); |
383 | if(t!=string::npos) | 418 | if(t!=string::npos) |
384 | m.output.erase(t+1); | 419 | m.output.erase(t+1); |
385 | member_variables.push_back(member_variable(m._type,m._name,m.output)); | 420 | member_variables.push_back(member_variable(m._type,m._name,m.output)); |
386 | if(!m.output.empty()) | 421 | if(!m.output.empty()) |
387 | have_initializers=true; | 422 | have_initializers=true; |
388 | modi.pop_front(); | 423 | modi.pop_front(); |
389 | BEGIN(INITIAL); | 424 | BEGIN(INITIAL); |
390 | } | 425 | } |
391 | } | 426 | } |
392 | <DECLLINE>\n{ | 427 | <DECLLINE>\n{ |
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 | } |
426 | \'\\.\'{ | 461 | \'\\.\'{ |
427 | ECHO; | 462 | ECHO; |
428 | } | 463 | } |
429 | } | 464 | } |
430 | 465 | ||
431 | <INITIAL,METHODBLOCK,OUTPUTBLOCK>{ | 466 | <INITIAL,METHODBLOCK,OUTPUTBLOCK>{ |
432 | \"soft_anchor(); M().modify(modus_operandi::modus_text); LexerOutput("\\\"",2); | 467 | \"soft_anchor(); M().modify(modus_operandi::modus_text); LexerOutput("\\\"",2); |
433 | \nsoft_anchor(); M().modify(modus_operandi::modus_text); LexerOutput("\\n",2); | 468 | \nsoft_anchor(); M().modify(modus_operandi::modus_text); LexerOutput("\\n",2); |
434 | \rsoft_anchor(); M().modify(modus_operandi::modus_text); LexerOutput("\\r",2); | 469 | \rsoft_anchor(); M().modify(modus_operandi::modus_text); LexerOutput("\\r",2); |
435 | \tsoft_anchor(); M().modify(modus_operandi::modus_text); LexerOutput("\\t",2); | 470 | \tsoft_anchor(); M().modify(modus_operandi::modus_text); LexerOutput("\\t",2); |
436 | \bsoft_anchor(); M().modify(modus_operandi::modus_text); LexerOutput("\\b",2); | 471 | \bsoft_anchor(); M().modify(modus_operandi::modus_text); LexerOutput("\\b",2); |
437 | \asoft_anchor(); M().modify(modus_operandi::modus_text); LexerOutput("\\a",2); | 472 | \asoft_anchor(); M().modify(modus_operandi::modus_text); LexerOutput("\\a",2); |
438 | .soft_anchor(); M().modify(modus_operandi::modus_text); ECHO; | 473 | .soft_anchor(); M().modify(modus_operandi::modus_text); ECHO; |
439 | {WHITESPACE}+soft_anchor(); M().modify(modus_operandi::modus_text); ECHO; | 474 | {WHITESPACE}+soft_anchor(); M().modify(modus_operandi::modus_text); ECHO; |
440 | } | 475 | } |
441 | 476 | ||
@@ -517,65 +552,75 @@ NOIDCHAR [^A-Za-z0-9_] | |||
517 | } | 552 | } |
518 | } | 553 | } |
519 | <STRING>{ | 554 | <STRING>{ |
520 | \\.ECHO; | 555 | \\.ECHO; |
521 | \"ECHO; yy_pop_state(); | 556 | \"ECHO; yy_pop_state(); |
522 | .ECHO; | 557 | .ECHO; |
523 | } | 558 | } |
524 | 559 | ||
525 | {WHITESPACE}+{ | 560 | {WHITESPACE}+{ |
526 | if(!(M().flags&modus_operandi::flag_devour_whitespace)) { | 561 | if(!(M().flags&modus_operandi::flag_devour_whitespace)) { |
527 | ECHO; | 562 | ECHO; |
528 | } | 563 | } |
529 | } | 564 | } |
530 | 565 | ||
531 | %% | 566 | %% |
532 | 567 | ||
533 | sitecing_parser::sitecing_parser(component_factory& f) | 568 | sitecing_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 | ||
540 | void sitecing_parser::preprocess(const string& in) { | 575 | void 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 | ||
556 | void sitecing_parser::LexerOutput(const char* buf,int size) { | 601 | void 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 | ||
561 | static const char *modus_transitions | 606 | static 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: |
566 | { "", "(*(__SCIF->out))", "(*(__SCIF->out))<<", "(*(__SCIF->out))<<\"" }, // code | 611 | { "", "(*(__SCIF->out))", "(*(__SCIF->out))<<", "(*(__SCIF->out))<<\"" }, // code |
567 | { ";", "", "<<", "<<\"" }, // preop | 612 | { ";", "", "<<", "<<\"" }, // preop |
568 | { NULL, NULL, "", "\"" }, // postop | 613 | { NULL, NULL, "", "\"" }, // postop |
569 | { "\";", "\"", "\"<<", "" } // text | 614 | { "\";", "\"", "\"<<", "" } // text |
570 | }; | 615 | }; |
571 | 616 | ||
572 | void sitecing_parser::modus_operandi::modify(modus_t m) { | 617 | void sitecing_parser::modus_operandi::modify(modus_t m) { |
573 | const char * x = modus_transitions[modus][m]; | 618 | const char * x = modus_transitions[modus][m]; |
574 | assert(x); | 619 | assert(x); |
575 | output += x; | 620 | output += x; |
576 | modus = m; | 621 | modus = m; |
577 | } | 622 | } |
578 | 623 | ||
579 | void sitecing_parser::soft_anchor() { | 624 | void sitecing_parser::soft_anchor() { |
580 | if(M().modus!=modus_operandi::modus_text) | 625 | if(M().modus!=modus_operandi::modus_text) |
581 | anchor(); | 626 | anchor(); |