1 #include "Delegate.hpp"
2 #include <soulng/util/Unicode.hpp>
3 #include <sngcm/cmparser/Specifier.hpp>
4 #include <sngcm/cmparser/TypeExpr.hpp>
5 #include <sngcm/cmparser/Identifier.hpp>
6 #include <sngcm/cmparser/Parameter.hpp>
7 #include <sngcm/cmlexer/CmajorLexer.hpp>
8 #include <sngcm/cmlexer/CmajorTokens.hpp>
9
10
11
12 using namespace soulng::unicode;
13 using namespace sngcm::ast;
14 using namespace CmajorTokens;
15
16 soulng::parser::Match DelegateParser::Delegate(CmajorLexer& lexer, boost::uuids::uuid* moduleId, ParsingContext* ctx)
17 {
18 #ifdef SOULNG_PARSER_DEBUG_SUPPORT
19
20
21
22
23
24
25
26 #endif // SOULNG_PARSER_DEBUG_SUPPORT
27 Span s = Span();
28 std::unique_ptr<DelegateNode> dlg = std::unique_ptr<DelegateNode>();
29 std::unique_ptr<soulng::parser::soulng::parser::Value<sngcm::ast::Specifiers>>specifiers;
30 std::unique_ptr<sngcm::ast::Node> type;
31 std::unique_ptr<IdentifierNode> id;
32 soulng::parser::Match match(false);
33 soulng::parser::Match* parentMatch0 = &match;
34 {
35 soulng::parser::Match match(false);
36 soulng::parser::Match* parentMatch1 = &match;
37 {
38 soulng::parser::Match match(false);
39 soulng::parser::Match* parentMatch2 = &match;
40 {
41 soulng::parser::Match match(false);
42 soulng::parser::Match* parentMatch3 = &match;
43 {
44 soulng::parser::Match match(false);
45 soulng::parser::Match* parentMatch4 = &match;
46 {
47 soulng::parser::Match match(false);
48 soulng::parser::Match* parentMatch5 = &match;
49 {
50 int64_t pos = lexer.GetPos();
51 soulng::lexer::Span span = lexer.GetSpan();
52 soulng::parser::Match match = SpecifierParser::Specifiers(lexer);
53 specifiers.reset(static_cast<soulng::parser::soulng::parser::Value<sngcm::ast::Specifiers>*>(match.value));
54 if (match.hit)
55 {
56 s = span;
57 }
58 *parentMatch5 = match;
59 }
60 *parentMatch4 = match;
61 }
62 if (match.hit)
63 {
64 soulng::parser::Match match(false);
65 soulng::parser::Match* parentMatch6 = &match;
66 {
67 soulng::parser::Match match(false);
68 if (*lexer == DELEGATE)
69 {
70 ++lexer;
71 match.hit = true;
72 }
73 *parentMatch6 = match;
74 }
75 *parentMatch4 = match;
76 }
77 *parentMatch3 = match;
78 }
79 if (match.hit)
80 {
81 soulng::parser::Match match(false);
82 soulng::parser::Match* parentMatch7 = &match;
83 {
84 soulng::parser::Match match(true);
85 soulng::parser::Match* parentMatch8 = &match;
86 {
87 soulng::lexer::Span span = lexer.GetSpan();
88 soulng::parser::Match match = TypeExprParser::TypeExpr(lexer, moduleId, ctx);
89 type.reset(static_cast<sngcm::ast::Node*>(match.value));
90 if (match.hit)
91 {
92 *parentMatch8 = match;
93 }
94 else
95 {
96 lexer.ThrowExpectationFailure(span, U"type expression");
97 }
98 }
99 *parentMatch7 = match;
100 }
101 *parentMatch3 = match;
102 }
103 *parentMatch2 = match;
104 }
105 if (match.hit)
106 {
107 soulng::parser::Match match(false);
108 soulng::parser::Match* parentMatch9 = &match;
109 {
110 soulng::parser::Match match(false);
111 soulng::parser::Match* parentMatch10 = &match;
112 {
113 int64_t pos = lexer.GetPos();
114 soulng::parser::Match match(true);
115 soulng::parser::Match* parentMatch11 = &match;
116 {
117 soulng::lexer::Span span = lexer.GetSpan();
118 soulng::parser::Match match = IdentifierParser::Identifier(lexer, moduleId);
119 id.reset(static_cast<IdentifierNode*>(match.value));
120 if (match.hit)
121 {
122 *parentMatch11 = match;
123 }
124 else
125 {
126 lexer.ThrowExpectationFailure(span, U"identifier");
127 }
128 }
129 if (match.hit)
130 {
131 dlg.reset(new DelegateNode(s, *moduleId, specifiers->value, type.release(), id.release()));
132 }
133 *parentMatch10 = match;
134 }
135 *parentMatch9 = match;
136 }
137 *parentMatch2 = match;
138 }
139 *parentMatch1 = match;
140 }
141 if (match.hit)
142 {
143 soulng::parser::Match match(false);
144 soulng::parser::Match* parentMatch12 = &match;
145 {
146 soulng::parser::Match match(true);
147 soulng::parser::Match* parentMatch13 = &match;
148 {
149 soulng::lexer::Span span = lexer.GetSpan();
150 soulng::parser::Match match = ParameterParser::ParameterList(lexer, moduleId, ctx, dlg.get());
151 if (match.hit)
152 {
153 *parentMatch13 = match;
154 }
155 else
156 {
157 lexer.ThrowExpectationFailure(span, U"parameter list");
158 }
159 }
160 *parentMatch12 = match;
161 }
162 *parentMatch1 = match;
163 }
164 *parentMatch0 = match;
165 }
166 if (match.hit)
167 {
168 soulng::parser::Match match(false);
169 soulng::parser::Match* parentMatch14 = &match;
170 {
171 soulng::parser::Match match(false);
172 soulng::parser::Match* parentMatch15 = &match;
173 {
174 int64_t pos = lexer.GetPos();
175 soulng::lexer::Span span = lexer.GetSpan();
176 soulng::parser::Match match(true);
177 soulng::parser::Match* parentMatch16 = &match;
178 {
179 soulng::lexer::Span span = lexer.GetSpan();
180 soulng::parser::Match match(false);
181 if (*lexer == SEMICOLON)
182 {
183 ++lexer;
184 match.hit = true;
185 }
186 if (match.hit)
187 {
188 *parentMatch16 = match;
189 }
190 else
191 {
192 lexer.ThrowExpectationFailure(span, ToUtf32(GetTokenInfo(SEMICOLON)));
193 }
194 }
195 if (match.hit)
196 {
197 dlg->SetSpanEnd(span.end);
198 {
199 #ifdef SOULNG_PARSER_DEBUG_SUPPORT
200
201 #endif // SOULNG_PARSER_DEBUG_SUPPORT
202 return soulng::parser::Match(true, dlg.release());
203 }
204 }
205 *parentMatch15 = match;
206 }
207 *parentMatch14 = match;
208 }
209 *parentMatch0 = match;
210 }
211 #ifdef SOULNG_PARSER_DEBUG_SUPPORT
212
213
214
215
216
217 #endif // SOULNG_PARSER_DEBUG_SUPPORT
218 if (!match.hit)
219 {
220 match.value = nullptr;
221 }
222 return match;
223 }
224
225 soulng::parser::Match DelegateParser::ClassDelegate(CmajorLexer& lexer, boost::uuids::uuid* moduleId, ParsingContext* ctx)
226 {
227 #ifdef SOULNG_PARSER_DEBUG_SUPPORT
228
229
230
231
232
233
234
235 #endif // SOULNG_PARSER_DEBUG_SUPPORT
236 Span s = Span();
237 std::unique_ptr<ClassDelegateNode> clsDlg = std::unique_ptr<ClassDelegateNode>();
238 std::unique_ptr<soulng::parser::soulng::parser::Value<sngcm::ast::Specifiers>>specifiers;
239 std::unique_ptr<sngcm::ast::Node> type;
240 std::unique_ptr<IdentifierNode> id;
241 soulng::parser::Match match(false);
242 soulng::parser::Match* parentMatch0 = &match;
243 {
244 soulng::parser::Match match(false);
245 soulng::parser::Match* parentMatch1 = &match;
246 {
247 soulng::parser::Match match(false);
248 soulng::parser::Match* parentMatch2 = &match;
249 {
250 soulng::parser::Match match(false);
251 soulng::parser::Match* parentMatch3 = &match;
252 {
253 soulng::parser::Match match(false);
254 soulng::parser::Match* parentMatch4 = &match;
255 {
256 soulng::parser::Match match(false);
257 soulng::parser::Match* parentMatch5 = &match;
258 {
259 soulng::parser::Match match(false);
260 soulng::parser::Match* parentMatch6 = &match;
261 {
262 int64_t pos = lexer.GetPos();
263 soulng::lexer::Span span = lexer.GetSpan();
264 soulng::parser::Match match = SpecifierParser::Specifiers(lexer);
265 specifiers.reset(static_cast<soulng::parser::soulng::parser::Value<sngcm::ast::Specifiers>*>(match.value));
266 if (match.hit)
267 {
268 s = span;
269 }
270 *parentMatch6 = match;
271 }
272 *parentMatch5 = match;
273 }
274 if (match.hit)
275 {
276 soulng::parser::Match match(false);
277 soulng::parser::Match* parentMatch7 = &match;
278 {
279 soulng::parser::Match match(false);
280 if (*lexer == CLASS)
281 {
282 ++lexer;
283 match.hit = true;
284 }
285 *parentMatch7 = match;
286 }
287 *parentMatch5 = match;
288 }
289 *parentMatch4 = match;
290 }
291 if (match.hit)
292 {
293 soulng::parser::Match match(false);
294 soulng::parser::Match* parentMatch8 = &match;
295 {
296 soulng::parser::Match match(false);
297 if (*lexer == DELEGATE)
298 {
299 ++lexer;
300 match.hit = true;
301 }
302 *parentMatch8 = match;
303 }
304 *parentMatch4 = match;
305 }
306 *parentMatch3 = match;
307 }
308 if (match.hit)
309 {
310 soulng::parser::Match match(false);
311 soulng::parser::Match* parentMatch9 = &match;
312 {
313 soulng::parser::Match match(true);
314 soulng::parser::Match* parentMatch10 = &match;
315 {
316 soulng::lexer::Span span = lexer.GetSpan();
317 soulng::parser::Match match = TypeExprParser::TypeExpr(lexer, moduleId, ctx);
318 type.reset(static_cast<sngcm::ast::Node*>(match.value));
319 if (match.hit)
320 {
321 *parentMatch10 = match;
322 }
323 else
324 {
325 lexer.ThrowExpectationFailure(span, U"type expression");
326 }
327 }
328 *parentMatch9 = match;
329 }
330 *parentMatch3 = match;
331 }
332 *parentMatch2 = match;
333 }
334 if (match.hit)
335 {
336 soulng::parser::Match match(false);
337 soulng::parser::Match* parentMatch11 = &match;
338 {
339 soulng::parser::Match match(false);
340 soulng::parser::Match* parentMatch12 = &match;
341 {
342 int64_t pos = lexer.GetPos();
343 soulng::parser::Match match(true);
344 soulng::parser::Match* parentMatch13 = &match;
345 {
346 soulng::lexer::Span span = lexer.GetSpan();
347 soulng::parser::Match match = IdentifierParser::Identifier(lexer, moduleId);
348 id.reset(static_cast<IdentifierNode*>(match.value));
349 if (match.hit)
350 {
351 *parentMatch13 = match;
352 }
353 else
354 {
355 lexer.ThrowExpectationFailure(span, U"identifier");
356 }
357 }
358 if (match.hit)
359 {
360 clsDlg.reset(new ClassDelegateNode(s, *moduleId, specifiers->value, type.release(), id.release()));
361 }
362 *parentMatch12 = match;
363 }
364 *parentMatch11 = match;
365 }
366 *parentMatch2 = match;
367 }
368 *parentMatch1 = match;
369 }
370 if (match.hit)
371 {
372 soulng::parser::Match match(false);
373 soulng::parser::Match* parentMatch14 = &match;
374 {
375 soulng::parser::Match match(true);
376 soulng::parser::Match* parentMatch15 = &match;
377 {
378 soulng::lexer::Span span = lexer.GetSpan();
379 soulng::parser::Match match = ParameterParser::ParameterList(lexer, moduleId, ctx, clsDlg.get());
380 if (match.hit)
381 {
382 *parentMatch15 = match;
383 }
384 else
385 {
386 lexer.ThrowExpectationFailure(span, U"parameter list");
387 }
388 }
389 *parentMatch14 = match;
390 }
391 *parentMatch1 = match;
392 }
393 *parentMatch0 = match;
394 }
395 if (match.hit)
396 {
397 soulng::parser::Match match(false);
398 soulng::parser::Match* parentMatch16 = &match;
399 {
400 soulng::parser::Match match(false);
401 soulng::parser::Match* parentMatch17 = &match;
402 {
403 int64_t pos = lexer.GetPos();
404 soulng::lexer::Span span = lexer.GetSpan();
405 soulng::parser::Match match(true);
406 soulng::parser::Match* parentMatch18 = &match;
407 {
408 soulng::lexer::Span span = lexer.GetSpan();
409 soulng::parser::Match match(false);
410 if (*lexer == SEMICOLON)
411 {
412 ++lexer;
413 match.hit = true;
414 }
415 if (match.hit)
416 {
417 *parentMatch18 = match;
418 }
419 else
420 {
421 lexer.ThrowExpectationFailure(span, ToUtf32(GetTokenInfo(SEMICOLON)));
422 }
423 }
424 if (match.hit)
425 {
426 clsDlg->SetSpanEnd(span.end);
427 {
428 #ifdef SOULNG_PARSER_DEBUG_SUPPORT
429
430 #endif // SOULNG_PARSER_DEBUG_SUPPORT
431 return soulng::parser::Match(true, clsDlg.release());
432 }
433 }
434 *parentMatch17 = match;
435 }
436 *parentMatch16 = match;
437 }
438 *parentMatch0 = match;
439 }
440 #ifdef SOULNG_PARSER_DEBUG_SUPPORT
441
442
443
444
445
446 #endif // SOULNG_PARSER_DEBUG_SUPPORT
447 if (!match.hit)
448 {
449 match.value = nullptr;
450 }
451 return match;
452 }