author | Michael Krelin <hacker@klever.net> | 2006-12-06 16:58:21 (UTC) |
---|---|---|
committer | Michael Krelin <hacker@klever.net> | 2006-12-06 16:58:21 (UTC) |
commit | a22cf56603ca89efb73429fd3797a775ca908cff (patch) (unidiff) | |
tree | 3f1e2c2f2a7640da48ec4e9576f19e63528ec60f /lib/sitecing_parser.ll | |
parent | d2bac550faab6e8ffbf3f3d43fdf7cd862cf0a72 (diff) | |
download | sitecing-a22cf56603ca89efb73429fd3797a775ca908cff.zip sitecing-a22cf56603ca89efb73429fd3797a775ca908cff.tar.gz sitecing-a22cf56603ca89efb73429fd3797a775ca908cff.tar.bz2 |
fix for escaping backslash in output
-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 | |||
@@ -1,643 +1,644 @@ | |||
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 <konforka/util.h> | 10 | #include <konforka/util.h> |
11 | #include "sitecing/sitecing_util.h" | 11 | #include "sitecing/sitecing_util.h" |
12 | #include "sitecing/sitecing_exception.h" | 12 | #include "sitecing/sitecing_exception.h" |
13 | using namespace sitecing; | 13 | using namespace sitecing; |
14 | #define sitecing_parser_flexlexer_once | 14 | #define sitecing_parser_flexlexer_once |
15 | #include "sitecing/sitecing_parser.h" | 15 | #include "sitecing/sitecing_parser.h" |
16 | #include "sitecing/sitecing_enflesher.h" | 16 | #include "sitecing/sitecing_enflesher.h" |
17 | #undef yyFlexLexer | 17 | #undef yyFlexLexer |
18 | #define yyFlexLexer sitecing_parserFlexLexer | 18 | #define yyFlexLexer sitecing_parserFlexLexer |
19 | %} | 19 | %} |
20 | %x SLASHSTAR_COMMENT SLASHSLASH_COMMENT STRING | 20 | %x SLASHSTAR_COMMENT SLASHSLASH_COMMENT STRING |
21 | %x CODELINE CLASSLINE DECLLINE IMPLLINE DECLBLOCK IMPLBLOCK VARLINE VARINIT | 21 | %x CODELINE CLASSLINE DECLLINE IMPLLINE DECLBLOCK IMPLBLOCK VARLINE VARINIT |
22 | %x IMPORTLINE IMPORTCOMPONENT | 22 | %x IMPORTLINE IMPORTCOMPONENT |
23 | %x IMPORTTYPELINE IMPORTTYPECOMPONENT | 23 | %x IMPORTTYPELINE IMPORTTYPECOMPONENT |
24 | %x DERIVELINE DERIVECOMPONENT | 24 | %x DERIVELINE DERIVECOMPONENT |
25 | %x CONSTRUCTOR DESTRUCTOR CODEMETHODLINE CODEMETHODARGS | 25 | %x CONSTRUCTOR DESTRUCTOR CODEMETHODLINE CODEMETHODARGS |
26 | %x CODEMETHODBLOCK INLINE METHODLINE METHODARGS METHODBLOCK CODEBLOCK OUTPUTBLOCK | 26 | %x CODEMETHODBLOCK INLINE METHODLINE METHODARGS METHODBLOCK CODEBLOCK OUTPUTBLOCK |
27 | %x PRAGMALINE | 27 | %x PRAGMALINE |
28 | %option 8bit c++ verbose noyywrap yyclass="sitecing_parser" prefix="sitecing_parser" stack yylineno | 28 | %option 8bit c++ verbose noyywrap yyclass="sitecing_parser" prefix="sitecing_parser" stack yylineno |
29 | 29 | ||
30 | WHITESPACE[ \t] | 30 | WHITESPACE[ \t] |
31 | ID [A-Za-z_][A-Za-z0-9_]* | 31 | ID [A-Za-z_][A-Za-z0-9_]* |
32 | NOIDCHAR[^A-Za-z0-9_] | 32 | NOIDCHAR[^A-Za-z0-9_] |
33 | 33 | ||
34 | %% | 34 | %% |
35 | 35 | ||
36 | <INITIAL>{ | 36 | <INITIAL>{ |
37 | ^\%\%class{WHITESPACE}+{ | 37 | ^\%\%class{WHITESPACE}+{ |
38 | // TODO: signal error if we already have class name acquired from source. | 38 | // TODO: signal error if we already have class name acquired from source. |
39 | modi.push_front(modus_operandi(modus_operandi::flag_devour_comments|modus_operandi::flag_devour_whitespace)); | 39 | modi.push_front(modus_operandi(modus_operandi::flag_devour_comments|modus_operandi::flag_devour_whitespace)); |
40 | BEGIN(CLASSLINE); | 40 | BEGIN(CLASSLINE); |
41 | } | 41 | } |
42 | ^\%\%decl{WHITESPACE}+{ | 42 | ^\%\%decl{WHITESPACE}+{ |
43 | modi.push_front(modus_operandi(0)); | 43 | modi.push_front(modus_operandi(0)); |
44 | anchor(); | 44 | anchor(); |
45 | BEGIN(DECLLINE); | 45 | BEGIN(DECLLINE); |
46 | } | 46 | } |
47 | ^\%\%impl{WHITESPACE}+{ | 47 | ^\%\%impl{WHITESPACE}+{ |
48 | modi.push_front(modus_operandi(0)); | 48 | modi.push_front(modus_operandi(0)); |
49 | anchor(); | 49 | anchor(); |
50 | BEGIN(IMPLLINE); | 50 | BEGIN(IMPLLINE); |
51 | } | 51 | } |
52 | \<\%decl\> { | 52 | \<\%decl\> { |
53 | modi.push_front(modus_operandi(0)); | 53 | modi.push_front(modus_operandi(0)); |
54 | anchor(); | 54 | anchor(); |
55 | BEGIN(DECLBLOCK); | 55 | BEGIN(DECLBLOCK); |
56 | } | 56 | } |
57 | \<\%impl\> { | 57 | \<\%impl\> { |
58 | modi.push_front(modus_operandi(0)); | 58 | modi.push_front(modus_operandi(0)); |
59 | anchor(); | 59 | anchor(); |
60 | BEGIN(IMPLBLOCK); | 60 | BEGIN(IMPLBLOCK); |
61 | } | 61 | } |
62 | ^\%\%var{WHITESPACE}+{ | 62 | ^\%\%var{WHITESPACE}+{ |
63 | modi.push_front(modus_operandi(modus_operandi::flag_devour_comments)); | 63 | modi.push_front(modus_operandi(modus_operandi::flag_devour_comments)); |
64 | anchor(); | 64 | anchor(); |
65 | BEGIN(VARLINE); | 65 | BEGIN(VARLINE); |
66 | } | 66 | } |
67 | ^\%\%import{WHITESPACE}+{ | 67 | ^\%\%import{WHITESPACE}+{ |
68 | modi.push_front(modus_operandi(modus_operandi::flag_devour_comments)); | 68 | modi.push_front(modus_operandi(modus_operandi::flag_devour_comments)); |
69 | BEGIN(IMPORTLINE); | 69 | BEGIN(IMPORTLINE); |
70 | } | 70 | } |
71 | ^\%\%import_type{WHITESPACE}+ { | 71 | ^\%\%import_type{WHITESPACE}+ { |
72 | modi.push_front(modus_operandi(modus_operandi::flag_devour_comments)); | 72 | modi.push_front(modus_operandi(modus_operandi::flag_devour_comments)); |
73 | BEGIN(IMPORTTYPELINE); | 73 | BEGIN(IMPORTTYPELINE); |
74 | } | 74 | } |
75 | ^\%\%derive{WHITESPACE}+{ | 75 | ^\%\%derive{WHITESPACE}+{ |
76 | modi.push_front(modus_operandi(modus_operandi::flag_devour_comments)); | 76 | modi.push_front(modus_operandi(modus_operandi::flag_devour_comments)); |
77 | BEGIN(DERIVELINE); | 77 | BEGIN(DERIVELINE); |
78 | } | 78 | } |
79 | \<\%constructor\>{ | 79 | \<\%constructor\>{ |
80 | modi.push_front(modus_operandi()); | 80 | modi.push_front(modus_operandi()); |
81 | anchor(); | 81 | anchor(); |
82 | BEGIN(CONSTRUCTOR); | 82 | BEGIN(CONSTRUCTOR); |
83 | } | 83 | } |
84 | \<\%destructor\>{ | 84 | \<\%destructor\>{ |
85 | modi.push_front(modus_operandi()); | 85 | modi.push_front(modus_operandi()); |
86 | anchor(); | 86 | anchor(); |
87 | BEGIN(DESTRUCTOR); | 87 | BEGIN(DESTRUCTOR); |
88 | } | 88 | } |
89 | \<\%codemethod{WHITESPACE}+{ | 89 | \<\%codemethod{WHITESPACE}+{ |
90 | modi.push_front(modus_operandi(modus_operandi::flag_devour_comments)); | 90 | modi.push_front(modus_operandi(modus_operandi::flag_devour_comments)); |
91 | anchor(); | 91 | anchor(); |
92 | BEGIN(CODEMETHODLINE); | 92 | BEGIN(CODEMETHODLINE); |
93 | } | 93 | } |
94 | \<\%method{WHITESPACE}+ { | 94 | \<\%method{WHITESPACE}+ { |
95 | modi.push_front(modus_operandi(modus_operandi::flag_devour_comments)); | 95 | modi.push_front(modus_operandi(modus_operandi::flag_devour_comments)); |
96 | anchor(); | 96 | anchor(); |
97 | BEGIN(METHODLINE); | 97 | BEGIN(METHODLINE); |
98 | } | 98 | } |
99 | ^\%\%pragma{WHITESPACE}+{ | 99 | ^\%\%pragma{WHITESPACE}+{ |
100 | modi.push_front(modus_operandi(modus_operandi::flag_devour_comments)); | 100 | modi.push_front(modus_operandi(modus_operandi::flag_devour_comments)); |
101 | BEGIN(PRAGMALINE); | 101 | BEGIN(PRAGMALINE); |
102 | } | 102 | } |
103 | <<EOF>>{ | 103 | <<EOF>>{ |
104 | assert(modi.size()==1); | 104 | assert(modi.size()==1); |
105 | M().modify(modus_operandi::modus_preop); | 105 | M().modify(modus_operandi::modus_preop); |
106 | LexerOutput(";",1); | 106 | LexerOutput(";",1); |
107 | return 0; | 107 | return 0; |
108 | } | 108 | } |
109 | } | 109 | } |
110 | <<EOF>>throw preprocessor_error(CODEPOINT,"unexpected end of file",lineno()); | 110 | <<EOF>>throw preprocessor_error(CODEPOINT,"unexpected end of file",lineno()); |
111 | 111 | ||
112 | <CODEBLOCK,CODEMETHODBLOCK>{ | 112 | <CODEBLOCK,CODEMETHODBLOCK>{ |
113 | "<%output>"{ | 113 | "<%output>"{ |
114 | anchor(); | 114 | anchor(); |
115 | yy_push_state(OUTPUTBLOCK); | 115 | yy_push_state(OUTPUTBLOCK); |
116 | } | 116 | } |
117 | } | 117 | } |
118 | 118 | ||
119 | <PRAGMALINE>{ | 119 | <PRAGMALINE>{ |
120 | {WHITESPACE}+{ | 120 | {WHITESPACE}+{ |
121 | modus_operandi& m = M(); | 121 | modus_operandi& m = M(); |
122 | if(!m.output.empty()) { | 122 | if(!m.output.empty()) { |
123 | string::size_type eq = m.output.find('='); | 123 | string::size_type eq = m.output.find('='); |
124 | if(eq==string::npos) { | 124 | if(eq==string::npos) { |
125 | pragmas[m.output]=m.output; | 125 | pragmas[m.output]=m.output; |
126 | }else{ | 126 | }else{ |
127 | pragmas[m.output.substr(0,eq)] = m.output.substr(eq+1); | 127 | pragmas[m.output.substr(0,eq)] = m.output.substr(eq+1); |
128 | } | 128 | } |
129 | m.output.erase(); | 129 | m.output.erase(); |
130 | } | 130 | } |
131 | } | 131 | } |
132 | \n { | 132 | \n { |
133 | modus_operandi& m = M(); | 133 | modus_operandi& m = M(); |
134 | if(!m.output.empty()) { | 134 | if(!m.output.empty()) { |
135 | string::size_type eq = m.output.find('='); | 135 | string::size_type eq = m.output.find('='); |
136 | if(eq==string::npos) { | 136 | if(eq==string::npos) { |
137 | pragmas[m.output]=m.output; | 137 | pragmas[m.output]=m.output; |
138 | }else{ | 138 | }else{ |
139 | pragmas[m.output.substr(0,eq)] = m.output.substr(eq+1); | 139 | pragmas[m.output.substr(0,eq)] = m.output.substr(eq+1); |
140 | } | 140 | } |
141 | m.output.erase(); | 141 | m.output.erase(); |
142 | } | 142 | } |
143 | modi.pop_front(); | 143 | modi.pop_front(); |
144 | BEGIN(INITIAL); | 144 | BEGIN(INITIAL); |
145 | anchor(); | 145 | anchor(); |
146 | } | 146 | } |
147 | } | 147 | } |
148 | 148 | ||
149 | <METHODLINE>{ | 149 | <METHODLINE>{ |
150 | {WHITESPACE}+{ | 150 | {WHITESPACE}+{ |
151 | modus_operandi& m = M(); | 151 | modus_operandi& m = M(); |
152 | if(!m.output.empty()) { | 152 | if(!m.output.empty()) { |
153 | if(!m._lastid.empty()) { | 153 | if(!m._lastid.empty()) { |
154 | if(!m._type.empty()) m._type += ' '; | 154 | if(!m._type.empty()) m._type += ' '; |
155 | m._type += m._lastid; | 155 | m._type += m._lastid; |
156 | } | 156 | } |
157 | m._lastid = m.output; | 157 | m._lastid = m.output; |
158 | m.output.clear(); | 158 | m.output.clear(); |
159 | } | 159 | } |
160 | } | 160 | } |
161 | \*{ | 161 | \*{ |
162 | modus_operandi& m = M(); | 162 | modus_operandi& m = M(); |
163 | ECHO; | 163 | ECHO; |
164 | if(!m._lastid.empty()) { | 164 | if(!m._lastid.empty()) { |
165 | if(!m._type.empty()) m._type += ' '; | 165 | if(!m._type.empty()) m._type += ' '; |
166 | m._type += m._lastid; | 166 | m._type += m._lastid; |
167 | } | 167 | } |
168 | m._lastid = m.output; | 168 | m._lastid = m.output; |
169 | m.output.clear(); | 169 | m.output.clear(); |
170 | } | 170 | } |
171 | \({ | 171 | \({ |
172 | modus_operandi& m = M(); | 172 | modus_operandi& m = M(); |
173 | if(m.output.empty()) { | 173 | if(m.output.empty()) { |
174 | m._name=m._lastid; | 174 | m._name=m._lastid; |
175 | }else{ | 175 | }else{ |
176 | if(!m._lastid.empty()) { // XXX: lastid, I believe should never be emtpy... | 176 | if(!m._lastid.empty()) { // XXX: lastid, I believe should never be emtpy... |
177 | if(!m._type.empty()) m._type += ' '; | 177 | if(!m._type.empty()) m._type += ' '; |
178 | m._type += m._lastid; | 178 | m._type += m._lastid; |
179 | } | 179 | } |
180 | m._name = m.output; | 180 | m._name = m.output; |
181 | m.output.clear(); | 181 | m.output.clear(); |
182 | } | 182 | } |
183 | ECHO; | 183 | ECHO; |
184 | BEGIN(METHODARGS); | 184 | BEGIN(METHODARGS); |
185 | } | 185 | } |
186 | } | 186 | } |
187 | <METHODARGS>{ | 187 | <METHODARGS>{ |
188 | \%\>{ | 188 | \%\>{ |
189 | modus_operandi& m = M(); | 189 | modus_operandi& m = M(); |
190 | m._args = m.output; | 190 | m._args = m.output; |
191 | m.output.clear(); | 191 | m.output.clear(); |
192 | anchor(); | 192 | anchor(); |
193 | BEGIN(METHODBLOCK); | 193 | BEGIN(METHODBLOCK); |
194 | } | 194 | } |
195 | } | 195 | } |
196 | 196 | ||
197 | <INITIAL,METHODBLOCK,OUTPUTBLOCK>{ | 197 | <INITIAL,METHODBLOCK,OUTPUTBLOCK>{ |
198 | \<\%{WHITESPACE}+{ | 198 | \<\%{WHITESPACE}+{ |
199 | M().modify(modus_operandi::modus_postop); | 199 | M().modify(modus_operandi::modus_postop); |
200 | anchor(); | 200 | anchor(); |
201 | LexerOutput("(",1); | 201 | LexerOutput("(",1); |
202 | yy_push_state(INLINE); | 202 | yy_push_state(INLINE); |
203 | } | 203 | } |
204 | ^\%{WHITESPACE}{ | 204 | ^\%{WHITESPACE}{ |
205 | M().modify(modus_operandi::modus_code); | 205 | M().modify(modus_operandi::modus_code); |
206 | anchor(); | 206 | anchor(); |
207 | yy_push_state(CODELINE); | 207 | yy_push_state(CODELINE); |
208 | } | 208 | } |
209 | \<\%code\>{ | 209 | \<\%code\>{ |
210 | M().modify(modus_operandi::modus_code); | 210 | M().modify(modus_operandi::modus_code); |
211 | anchor(); | 211 | anchor(); |
212 | yy_push_state(CODEBLOCK); | 212 | yy_push_state(CODEBLOCK); |
213 | } | 213 | } |
214 | "</%output>" { | 214 | "</%output>" { |
215 | if(YY_START!=OUTPUTBLOCK) throw preprocessor_error(CODEPOINT,"unexpected tag",lineno()); | 215 | if(YY_START!=OUTPUTBLOCK) throw preprocessor_error(CODEPOINT,"unexpected tag",lineno()); |
216 | M().modify(modus_operandi::modus_code); | 216 | M().modify(modus_operandi::modus_code); |
217 | anchor(); | 217 | anchor(); |
218 | yy_pop_state(); | 218 | yy_pop_state(); |
219 | } | 219 | } |
220 | } | 220 | } |
221 | 221 | ||
222 | <INLINE>\%\>LexerOutput(")",1); M().modus=modus_operandi::modus_preop; yy_pop_state(); | 222 | <INLINE>\%\>LexerOutput(")",1); M().modus=modus_operandi::modus_preop; yy_pop_state(); |
223 | <CODELINE>\nyy_pop_state(); | 223 | <CODELINE>\nyy_pop_state(); |
224 | 224 | ||
225 | <CODEMETHODLINE>{ | 225 | <CODEMETHODLINE>{ |
226 | {WHITESPACE}+{ | 226 | {WHITESPACE}+{ |
227 | modus_operandi& m = M(); | 227 | modus_operandi& m = M(); |
228 | if(!m.output.empty()) { | 228 | if(!m.output.empty()) { |
229 | if(!m._lastid.empty()) { | 229 | if(!m._lastid.empty()) { |
230 | if(!m._type.empty()) m._type += ' '; | 230 | if(!m._type.empty()) m._type += ' '; |
231 | m._type += m._lastid; | 231 | m._type += m._lastid; |
232 | } | 232 | } |
233 | m._lastid = m.output; | 233 | m._lastid = m.output; |
234 | m.output.clear(); | 234 | m.output.clear(); |
235 | } | 235 | } |
236 | } | 236 | } |
237 | \*{ | 237 | \*{ |
238 | modus_operandi& m = M(); | 238 | modus_operandi& m = M(); |
239 | ECHO; | 239 | ECHO; |
240 | if(!m._lastid.empty()) { | 240 | if(!m._lastid.empty()) { |
241 | if(!m._type.empty()) m._type += ' '; | 241 | if(!m._type.empty()) m._type += ' '; |
242 | m._type += m._lastid; | 242 | m._type += m._lastid; |
243 | } | 243 | } |
244 | m._lastid = m.output; | 244 | m._lastid = m.output; |
245 | m.output.clear(); | 245 | m.output.clear(); |
246 | } | 246 | } |
247 | \({ | 247 | \({ |
248 | modus_operandi& m = M(); | 248 | modus_operandi& m = M(); |
249 | if(m.output.empty()) { | 249 | if(m.output.empty()) { |
250 | m._name=m._lastid; | 250 | m._name=m._lastid; |
251 | }else{ | 251 | }else{ |
252 | if(!m._lastid.empty()) { // XXX: lastid, I believe should never be emtpy... | 252 | if(!m._lastid.empty()) { // XXX: lastid, I believe should never be emtpy... |
253 | if(!m._type.empty()) m._type += ' '; | 253 | if(!m._type.empty()) m._type += ' '; |
254 | m._type += m._lastid; | 254 | m._type += m._lastid; |
255 | } | 255 | } |
256 | m._name = m.output; | 256 | m._name = m.output; |
257 | m.output.clear(); | 257 | m.output.clear(); |
258 | } | 258 | } |
259 | ECHO; | 259 | ECHO; |
260 | BEGIN(CODEMETHODARGS); | 260 | BEGIN(CODEMETHODARGS); |
261 | } | 261 | } |
262 | } | 262 | } |
263 | <CODEMETHODARGS>{ | 263 | <CODEMETHODARGS>{ |
264 | \%\>{ | 264 | \%\>{ |
265 | modus_operandi& m = M(); | 265 | modus_operandi& m = M(); |
266 | m._args = m.output; | 266 | m._args = m.output; |
267 | m.output.clear(); | 267 | m.output.clear(); |
268 | m.flags=0; | 268 | m.flags=0; |
269 | anchor(); | 269 | anchor(); |
270 | BEGIN(CODEMETHODBLOCK); | 270 | BEGIN(CODEMETHODBLOCK); |
271 | } | 271 | } |
272 | } | 272 | } |
273 | 273 | ||
274 | <IMPORTLINE>{ | 274 | <IMPORTLINE>{ |
275 | {WHITESPACE}+{ } | 275 | {WHITESPACE}+{ } |
276 | {ID}{ | 276 | {ID}{ |
277 | modus_operandi& m = M(); | 277 | modus_operandi& m = M(); |
278 | if(!m._name.empty()) | 278 | if(!m._name.empty()) |
279 | throw preprocessor_error(CODEPOINT,"syntax error",lineno()); | 279 | throw preprocessor_error(CODEPOINT,"syntax error",lineno()); |
280 | m._name = yytext; | 280 | m._name = yytext; |
281 | } | 281 | } |
282 | \= { | 282 | \= { |
283 | M().output.clear(); | 283 | M().output.clear(); |
284 | BEGIN(IMPORTCOMPONENT); | 284 | BEGIN(IMPORTCOMPONENT); |
285 | } | 285 | } |
286 | } | 286 | } |
287 | <IMPORTCOMPONENT>{ | 287 | <IMPORTCOMPONENT>{ |
288 | {WHITESPACE}+{ } | 288 | {WHITESPACE}+{ } |
289 | \n{ | 289 | \n{ |
290 | modus_operandi& m = M(); | 290 | modus_operandi& m = M(); |
291 | string::size_type t = m.output.find_first_not_of(" \t"); | 291 | string::size_type t = m.output.find_first_not_of(" \t"); |
292 | if(t!=string::npos) | 292 | if(t!=string::npos) |
293 | m.output.erase(0,t); | 293 | m.output.erase(0,t); |
294 | t = m.output.find_last_not_of(" \t;"); | 294 | t = m.output.find_last_not_of(" \t;"); |
295 | if(t!=string::npos) | 295 | if(t!=string::npos) |
296 | m.output.erase(t+1); | 296 | m.output.erase(t+1); |
297 | if(m.output[0]=='"' && m.output[m.output.length()-1]=='"') { | 297 | if(m.output[0]=='"' && m.output[m.output.length()-1]=='"') { |
298 | m.output.erase(0,1); | 298 | m.output.erase(0,1); |
299 | m.output.erase(m.output.length()-1); | 299 | m.output.erase(m.output.length()-1); |
300 | } | 300 | } |
301 | string c = konforka::combine_path(component_basename,m.output); | 301 | string c = konforka::combine_path(component_basename,m.output); |
302 | member_variables.push_back(member_variable(m._type,m._name,konforka::normalize_path(c,konforka::strip_leading_slash),true)); | 302 | member_variables.push_back(member_variable(m._type,m._name,konforka::normalize_path(c,konforka::strip_leading_slash),true)); |
303 | modi.pop_front(); | 303 | modi.pop_front(); |
304 | BEGIN(INITIAL); | 304 | BEGIN(INITIAL); |
305 | } | 305 | } |
306 | } | 306 | } |
307 | 307 | ||
308 | <IMPORTTYPELINE>{ | 308 | <IMPORTTYPELINE>{ |
309 | {WHITESPACE}+{ } | 309 | {WHITESPACE}+{ } |
310 | {ID}{ | 310 | {ID}{ |
311 | modus_operandi& m = M(); | 311 | modus_operandi& m = M(); |
312 | if(!m._name.empty()) | 312 | if(!m._name.empty()) |
313 | throw preprocessor_error(CODEPOINT,"syntax error",lineno()); | 313 | throw preprocessor_error(CODEPOINT,"syntax error",lineno()); |
314 | m._name = yytext; | 314 | m._name = yytext; |
315 | } | 315 | } |
316 | \= { | 316 | \= { |
317 | M().output.clear(); | 317 | M().output.clear(); |
318 | BEGIN(IMPORTTYPECOMPONENT); | 318 | BEGIN(IMPORTTYPECOMPONENT); |
319 | } | 319 | } |
320 | } | 320 | } |
321 | <IMPORTTYPECOMPONENT>{ | 321 | <IMPORTTYPECOMPONENT>{ |
322 | {WHITESPACE}+{ } | 322 | {WHITESPACE}+{ } |
323 | \n{ | 323 | \n{ |
324 | modus_operandi& m = M(); | 324 | modus_operandi& m = M(); |
325 | string::size_type t = m.output.find_first_not_of(" \t"); | 325 | string::size_type t = m.output.find_first_not_of(" \t"); |
326 | if(t!=string::npos) | 326 | if(t!=string::npos) |
327 | m.output.erase(0,t); | 327 | m.output.erase(0,t); |
328 | t = m.output.find_last_not_of(" \t;"); | 328 | t = m.output.find_last_not_of(" \t;"); |
329 | if(t!=string::npos) | 329 | if(t!=string::npos) |
330 | m.output.erase(t+1); | 330 | m.output.erase(t+1); |
331 | if(m.output[0]=='"' && m.output[m.output.length()-1]=='"') { | 331 | if(m.output[0]=='"' && m.output[m.output.length()-1]=='"') { |
332 | m.output.erase(0,1); | 332 | m.output.erase(0,1); |
333 | m.output.erase(m.output.length()-1); | 333 | m.output.erase(m.output.length()-1); |
334 | } | 334 | } |
335 | string c = konforka::combine_path(component_basename,m.output); | 335 | string c = konforka::combine_path(component_basename,m.output); |
336 | member_variables.push_back(member_variable(m._type,m._name,konforka::normalize_path(c,konforka::strip_leading_slash),true,true)); | 336 | member_variables.push_back(member_variable(m._type,m._name,konforka::normalize_path(c,konforka::strip_leading_slash),true,true)); |
337 | modi.pop_front(); | 337 | modi.pop_front(); |
338 | BEGIN(INITIAL); | 338 | BEGIN(INITIAL); |
339 | } | 339 | } |
340 | } | 340 | } |
341 | 341 | ||
342 | <DERIVELINE>{ | 342 | <DERIVELINE>{ |
343 | {WHITESPACE}+{ } | 343 | {WHITESPACE}+{ } |
344 | {ID}{ | 344 | {ID}{ |
345 | modus_operandi& m = M(); | 345 | modus_operandi& m = M(); |
346 | if(!m._name.empty()) | 346 | if(!m._name.empty()) |
347 | throw preprocessor_error(CODEPOINT,"syntax_error",lineno()); | 347 | throw preprocessor_error(CODEPOINT,"syntax_error",lineno()); |
348 | m._name = yytext; | 348 | m._name = yytext; |
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 | ||
605 | void sitecing_parser::LexerOutput(const char* buf,int size) { | 606 | void sitecing_parser::LexerOutput(const char* buf,int size) { |
606 | assert(modi.size()); | 607 | assert(modi.size()); |
607 | M().output.append(buf,size); | 608 | M().output.append(buf,size); |
608 | } | 609 | } |
609 | 610 | ||
610 | static const char *modus_transitions | 611 | static const char *modus_transitions |
611 | [sitecing_parser::modus_operandi::modi] | 612 | [sitecing_parser::modus_operandi::modi] |
612 | [sitecing_parser::modus_operandi::modi] = { | 613 | [sitecing_parser::modus_operandi::modi] = { |
613 | // To: | 614 | // To: |
614 | // code preop postop text From: | 615 | // code preop postop text From: |
615 | { "", "(*(__SCIF->out))", "(*(__SCIF->out))<<", "(*(__SCIF->out))<<\"" }, // code | 616 | { "", "(*(__SCIF->out))", "(*(__SCIF->out))<<", "(*(__SCIF->out))<<\"" }, // code |
616 | { ";", "", "<<", "<<\"" }, // preop | 617 | { ";", "", "<<", "<<\"" }, // preop |
617 | { NULL, NULL, "", "\"" }, // postop | 618 | { NULL, NULL, "", "\"" }, // postop |
618 | { "\";", "\"", "\"<<", "" } // text | 619 | { "\";", "\"", "\"<<", "" } // text |
619 | }; | 620 | }; |
620 | 621 | ||
621 | void sitecing_parser::modus_operandi::modify(modus_t m) { | 622 | void sitecing_parser::modus_operandi::modify(modus_t m) { |
622 | const char * x = modus_transitions[modus][m]; | 623 | const char * x = modus_transitions[modus][m]; |
623 | assert(x); | 624 | assert(x); |
624 | output += x; | 625 | output += x; |
625 | modus = m; | 626 | modus = m; |
626 | } | 627 | } |
627 | 628 | ||
628 | void sitecing_parser::soft_anchor() { | 629 | void sitecing_parser::soft_anchor() { |
629 | if(M().modus!=modus_operandi::modus_text) | 630 | if(M().modus!=modus_operandi::modus_text) |
630 | anchor(); | 631 | anchor(); |
631 | } | 632 | } |
632 | void sitecing_parser::anchor() { | 633 | void sitecing_parser::anchor() { |
633 | if(M().modus==modus_operandi::modus_text) | 634 | if(M().modus==modus_operandi::modus_text) |
634 | M().modify(modus_operandi::modus_preop); | 635 | M().modify(modus_operandi::modus_preop); |
635 | M().output += "\n#line "; | 636 | M().output += "\n#line "; |
636 | char tmp[7]; | 637 | char tmp[7]; |
637 | snprintf(tmp,sizeof(tmp),"%d",lineno()); | 638 | snprintf(tmp,sizeof(tmp),"%d",lineno()); |
638 | M().output += tmp; | 639 | M().output += tmp; |
639 | M().output += " \""; | 640 | M().output += " \""; |
640 | M().output += input_file; | 641 | M().output += input_file; |
641 | M().output += "\"\n"; | 642 | M().output += "\"\n"; |
642 | } | 643 | } |
643 | /* vim:set ft=lex: */ | 644 | /* vim:set ft=lex: */ |