summaryrefslogtreecommitdiffabout
path: root/include/sitecing/sitecing_parser.h
Unidiff
Diffstat (limited to 'include/sitecing/sitecing_parser.h') (more/less context) (ignore whitespace changes)
-rw-r--r--include/sitecing/sitecing_parser.h326
1 files changed, 326 insertions, 0 deletions
diff --git a/include/sitecing/sitecing_parser.h b/include/sitecing/sitecing_parser.h
new file mode 100644
index 0000000..22d716f
--- a/dev/null
+++ b/include/sitecing/sitecing_parser.h
@@ -0,0 +1,326 @@
1#ifndef __SITECING_SITECING_PARSER_H
2#define __SITECING_SITECING_PARSER_H
3
4#include <string>
5#include <list>
6#include <map>
7#include <stdexcept>
8using namespace std;
9
10#include "sitecing/component_factory.h"
11using namespace sitecing;
12
13/**
14 * @file
15 * @brief The component source parser.
16 */
17
18#ifndef sitecing_parser_flexlexer_once
19#define sitecing_parser_flexlexer_once
20#undef yyFlexLexer
21#define yyFlexLexer sitecing_parserFlexLexer
22#include <FlexLexer.h>
23#undef yyFlexLexerOnce
24#endif
25
26/**
27 * The component source parser.
28 */
29class sitecing_parser : public sitecing_parserFlexLexer {
30 public:
31 /**
32 * The ancestor class definition.
33 */
34 class ancestor_class {
35 public:
36 /**
37 * The class name.
38 */
39 string name;
40 /**
41 * The source component path.
42 */
43 string path;
44
45 /**
46 * @param n the class name.
47 * @param p the component path.
48 */
49 ancestor_class(const string& n,const string& p)
50 : name(n), path(p) { }
51 };
52 /**
53 * The list of ancestor classes.
54 */
55 typedef list<ancestor_class> ancestor_classes_t;
56 /**
57 * The ancestor classes.
58 */
59 ancestor_classes_t ancestor_classes;
60 /**
61 * The member variable definition.
62 */
63 class member_variable {
64 public:
65 /**
66 * The member variable type.
67 */
68 string type;
69 /**
70 * The member variable name.
71 */
72 string name;
73 /**
74 * The member variable is a component.
75 */
76 bool bComponent;
77 /**
78 * The variable initializer.
79 */
80 string initializer;
81 /**
82 * @todo TODO: wish I could remember -- document me.
83 */
84 bool bTypeOnly;
85
86 /**
87 * @param t type.
88 * @param n name.
89 * @param i initializer.
90 * @param bc whether it is a component.
91 * @param bto @todo TODO: @see bTypeOnly.
92 */
93 member_variable(const string& t,const string& n,const string& i,bool bc = false,bool bto = false)
94 : type(t), name(n), initializer(i), bComponent(bc), bTypeOnly(bto) { }
95 };
96 /**
97 * The list of member variables.
98 */
99 typedef list<member_variable> member_variables_t;
100 /**
101 * Member variables.
102 */
103 member_variables_t member_variables;
104 /**
105 * @todo TODO: wish I could remember the details -- document me.
106 */
107 bool have_initializers;
108 /**
109 * Whether the component has a constructor defined.
110 */
111 bool have_constructor;
112 /**
113 * Member function definition.
114 */
115 class member_function {
116 public:
117 /**
118 * Return type.
119 */
120 string type;
121 /**
122 * Function name.
123 */
124 string name;
125 /**
126 * Arguments declaration.
127 */
128 string args;
129 /**
130 * Function body.
131 */
132 string body;
133
134 /**
135 * @param t type.
136 * @param n name.
137 * @param a arguments.
138 * @param b body.
139 */
140 member_function(const string& t,const string& n,const string& a,const string& b)
141 : type(t), name(n), args(a), body(b) { }
142 };
143 /**
144 * The list of member functions.
145 */
146 typedef list<member_function> member_functions_t;
147 /**
148 * Member functions.
149 */
150 member_functions_t member_functions;
151 /**
152 * Current mode of operation.
153 */
154 class modus_operandi {
155 public:
156 /**
157 * The state enumeration.
158 */
159 enum modus_t {
160 /**
161 * Building the code.
162 */
163 modus_code = 0,
164 /**
165 * Ready to do the '<<' thing.
166 */
167 modus_preop,
168 /**
169 * Just made a '<<'.
170 */
171 modus_postop,
172 /**
173 * Outputting raw output data.
174 */
175 modus_text,
176 /**
177 * The number of modes.
178 */
179 modi
180 };
181 /**
182 * Processing flags enumeration.
183 */
184 enum {
185 /**
186 * Eat the comments.
187 */
188 flag_devour_comments = 0x0001,
189 /**
190 * Eat whitespace.
191 */
192 flag_devour_whitespace = 0x0002
193 };
194 /**
195 * The processing mode.
196 */
197 modus_t modus;
198 /**
199 * The processing flags.
200 */
201 int flags;
202 /**
203 * Output being built.
204 */
205 string output;
206 /**
207 * The type for compound modes.
208 */
209 string _type;
210 /**
211 * The last id encountered.
212 */
213 string _lastid;
214 /**
215 * The name for compound modes.
216 */
217 string _name;
218 /**
219 * The argument declaration. Obviously for member functions.
220 */
221 string _args;
222
223 /**
224 * @param flags.
225 * @see flags
226 */
227 modus_operandi(int f = 0)
228 : modus(modus_code), flags(f) { }
229
230 /**
231 * Change the processing mode.
232 */
233 void modify(modus_t m);
234
235 /**
236 * See if we're eating up whitespaces.
237 */
238 bool devour_whitespace() { return flags&flag_devour_whitespace; }
239 /**
240 * See if we're eating up the comments.
241 */
242 bool devour_comments() { return flags&flag_devour_comments; }
243 };
244 /**
245 * The modes stack type.
246 */
247 typedef list<modus_operandi> modi_operandi;
248 /**
249 * The modes stack.
250 */
251 modi_operandi modi;
252 /**
253 * Input file name.
254 */
255 string input_file;
256 /**
257 * Base class name.
258 */
259 string base_class;
260 /**
261 * Base class header.
262 */
263 string base_header;
264 /**
265 * Component's basename.
266 * @todo TODO: wish I could remember the details -- document me.
267 */
268 string component_basename;
269 /**
270 * The skeleton file name.
271 */
272 string skeleton;
273 /**
274 * The component class name.
275 */
276 string class_name;
277 /**
278 * Output basename.
279 * @todo TODO: wish I could remember the details -- document me.
280 */
281 string output_basename;
282 /**
283 * Verbatim declaration part.
284 */
285 string decl;
286 /**
287 * Verbatim implementation part.
288 */
289 string impl;
290 /**
291 * The reference to the component factory object.
292 */
293 component_factory& factory;
294
295 /**
296 * @param f the component factory.
297 */
298 sitecing_parser(component_factory& f);
299
300 /**
301 * Preprocess file.
302 * @param in input file name.
303 */
304 void preprocess(const string& in);
305
306 virtual void LexerOutput(const char *buf,int size);
307 virtual int yylex();
308
309 /**
310 * Retrieve reference to the to of the modes stack.
311 * @return the reference in question.
312 */
313 modus_operandi& M() {
314 return modi.front();
315 }
316 /**
317 * Anchor the output with the #line, if we're not in the text output mode.
318 */
319 void soft_anchor();
320 /**
321 * Anchor the output with the #line directive, changing to the appropriate output mode if needed.
322 */
323 void anchor();
324};
325
326#endif /* __SITECING_SITECING_PARSER_H */