1 using System;
2 using System.Collections;
3 using System.Lex;
4 using System.Parsing;
5 using Cm.Ast;
6 using ParserFileTokens;
7
8
9
10 public static class ParTemplateParser
11 {
12 public static Match TemplateId(ParserFileLexer& lexer, ParsingContext* ctx)
13 {
14 #if (DEBUG)
15 Span debugSpan;
16 bool writeToLog = lexer.Log() != null;
17 if (writeToLog)
18 {
19 debugSpan = lexer.GetSpan();
20 System.Lex.WriteBeginRuleToLog(lexer, u"TemplateId");
21 }
22 #endif
23 UniquePtr<TemplateIdNode> templateId;
24 Span e;
25 UniquePtr<IdentifierNode> primary;
26 UniquePtr<Node> templateArg;
27 Match match(false);
28 Match* parentMatch0 = &match;
29 {
30 Match match(false);
31 Match* parentMatch1 = &match;
32 {
33 long pos = lexer.GetPos();
34 Match match(true);
35 if (match.hit)
36 {
37 ctx->BeginParsingTemplateId();
38 }
39 *parentMatch1 = match;
40 }
41 *parentMatch0 = match;
42 }
43 if (match.hit)
44 {
45 Match match(false);
46 Match* parentMatch2 = &match;
47 {
48 Match match(false);
49 Match* parentMatch3 = &match;
50 {
51 long pos = lexer.GetPos();
52 Match match(false);
53 Match* parentMatch4 = &match;
54 {
55 Match match(false);
56 Match* parentMatch5 = &match;
57 {
58 Match match(false);
59 Match* parentMatch6 = &match;
60 {
61 Match match(false);
62 Match* parentMatch7 = &match;
63 {
64 long pos = lexer.GetPos();
65 Span span = lexer.GetSpan();
66 Match match = ParIdentifierParser.QualifiedId(lexer);
67 primary.Reset(cast<IdentifierNode*>(match.value));
68 if (match.hit)
69 {
70 templateId.Reset(new TemplateIdNode(span, primary.Release()));
71 }
72 *parentMatch7 = match;
73 }
74 *parentMatch6 = match;
75 }
76 if (match.hit)
77 {
78 Match match(false);
79 Match* parentMatch8 = &match;
80 {
81 Match match(false);
82 Match* parentMatch9 = &match;
83 {
84 long pos = lexer.GetPos();
85 Match match(false);
86 if (*lexer == LANGLE)
87 {
88 ++lexer;
89 match.hit = true;
90 }
91 if (match.hit)
92 {
93 ++lexer.leftAngleCount;
94 }
95 *parentMatch9 = match;
96 }
97 *parentMatch8 = match;
98 }
99 *parentMatch6 = match;
100 }
101 *parentMatch5 = match;
102 }
103 if (match.hit)
104 {
105 Match match(false);
106 Match* parentMatch10 = &match;
107 {
108 Match match(false);
109 Match* parentMatch11 = &match;
110 {
111 long pos = lexer.GetPos();
112 Match match(false);
113 Match* parentMatch12 = &match;
114 {
115 Match match(false);
116 Match* parentMatch13 = &match;
117 {
118 Match match(false);
119 Match* parentMatch14 = &match;
120 {
121 Match match(false);
122 Match* parentMatch15 = &match;
123 {
124 Match match(false);
125 Match* parentMatch16 = &match;
126 {
127 long pos = lexer.GetPos();
128 Match match = ParTypeExprParser.TypeExpr(lexer, ctx);
129 templateArg.Reset(cast<Node*>(match.value));
130 if (match.hit)
131 {
132 templateId->AddTemplateArgument(templateArg.Release());
133 }
134 *parentMatch16 = match;
135 }
136 *parentMatch15 = match;
137 }
138 if (match.hit)
139 {
140 Match match(false);
141 Match* parentMatch17 = &match;
142 {
143 Match match(true);
144 Match* parentMatch18 = &match;
145 {
146 while (true)
147 {
148 long save = lexer.GetPos();
149 {
150 Match match(false);
151 Match* parentMatch19 = &match;
152 {
153 Match match(false);
154 if (*lexer == COMMA)
155 {
156 ++lexer;
157 match.hit = true;
158 }
159 *parentMatch19 = match;
160 }
161 if (match.hit)
162 {
163 Match match(false);
164 Match* parentMatch20 = &match;
165 {
166 Match match(false);
167 Match* parentMatch21 = &match;
168 {
169 long pos = lexer.GetPos();
170 Match match = ParTypeExprParser.TypeExpr(lexer, ctx);
171 templateArg.Reset(cast<Node*>(match.value));
172 if (match.hit)
173 {
174 templateId->AddTemplateArgument(templateArg.Release());
175 }
176 *parentMatch21 = match;
177 }
178 *parentMatch20 = match;
179 }
180 *parentMatch19 = match;
181 }
182 if (match.hit)
183 {
184 *parentMatch18 = match;
185 }
186 else
187 {
188 lexer.SetPos(save);
189 break;
190 }
191 }
192 }
193 }
194 *parentMatch17 = match;
195 }
196 *parentMatch15 = match;
197 }
198 *parentMatch14 = match;
199 }
200 *parentMatch13 = match;
201 }
202 if (match.hit)
203 {
204 Match match(false);
205 Match* parentMatch22 = &match;
206 {
207 Match match(false);
208 Match* parentMatch23 = &match;
209 {
210 long pos = lexer.GetPos();
211 Span span = lexer.GetSpan();
212 Match match(false);
213 if (*lexer == RANGLE)
214 {
215 ++lexer;
216 match.hit = true;
217 }
218 if (match.hit)
219 {
220 e = span;
221 }
222 *parentMatch23 = match;
223 }
224 *parentMatch22 = match;
225 }
226 *parentMatch13 = match;
227 }
228 *parentMatch12 = match;
229 }
230 if (match.hit)
231 {
232 --lexer.leftAngleCount;
233 }
234 else
235 {
236 --lexer.leftAngleCount;
237 }
238 *parentMatch11 = match;
239 }
240 *parentMatch10 = match;
241 }
242 *parentMatch5 = match;
243 }
244 *parentMatch4 = match;
245 }
246 if (match.hit)
247 {
248 templateId->SetSpanEnd(e.end);
249 ctx->EndParsingTemplateId();
250 {
251 #if (DEBUG)
252 if (writeToLog) System.Lex.WriteSuccessToLog(lexer, debugSpan, u"TemplateId");
253 #endif
254 return Match(true, templateId.Release());
255 }
256 }
257 else
258 {
259 ctx->EndParsingTemplateId();
260 }
261 *parentMatch3 = match;
262 }
263 *parentMatch2 = match;
264 }
265 *parentMatch0 = match;
266 }
267 #if (DEBUG)
268 if (writeToLog)
269 {
270 if (match.hit)
271 {
272 System.Lex.WriteSuccessToLog(lexer, debugSpan, u"TemplateId");
273 }
274 else
275 {
276 System.Lex.WriteFailureToLog(lexer, u"TemplateId");
277 }
278 }
279 #endif
280 if (!match.hit)
281 {
282 match.value = null;
283 }
284 return match;
285 }
286 public static Match TemplateParameter(ParserFileLexer& lexer, ParsingContext* ctx)
287 {
288 #if (DEBUG)
289 Span debugSpan;
290 bool writeToLog = lexer.Log() != null;
291 if (writeToLog)
292 {
293 debugSpan = lexer.GetSpan();
294 System.Lex.WriteBeginRuleToLog(lexer, u"TemplateParameter");
295 }
296 #endif
297 UniquePtr<IdentifierNode> id;
298 UniquePtr<Node> type;
299 Match match(false);
300 Match* parentMatch0 = &match;
301 {
302 long pos = lexer.GetPos();
303 Span span = lexer.GetSpan();
304 Match match(false);
305 Match* parentMatch1 = &match;
306 {
307 Match match(false);
308 Match* parentMatch2 = &match;
309 {
310 Match match = ParIdentifierParser.Identifier(lexer);
311 id.Reset(cast<IdentifierNode*>(match.value));
312 *parentMatch2 = match;
313 }
314 if (match.hit)
315 {
316 Match match(false);
317 Match* parentMatch3 = &match;
318 {
319 Match match(true);
320 long save = lexer.GetPos();
321 Match* parentMatch4 = &match;
322 {
323 Match match(false);
324 Match* parentMatch5 = &match;
325 {
326 Match match(false);
327 Match* parentMatch6 = &match;
328 {
329 Match match(false);
330 if (*lexer == ASSIGN)
331 {
332 ++lexer;
333 match.hit = true;
334 }
335 *parentMatch6 = match;
336 }
337 if (match.hit)
338 {
339 Match match(false);
340 Match* parentMatch7 = &match;
341 {
342 Match match = ParTypeExprParser.TypeExpr(lexer, ctx);
343 type.Reset(cast<Node*>(match.value));
344 *parentMatch7 = match;
345 }
346 *parentMatch6 = match;
347 }
348 *parentMatch5 = match;
349 }
350 if (match.hit)
351 {
352 *parentMatch4 = match;
353 }
354 else
355 {
356 lexer.SetPos(save);
357 }
358 }
359 *parentMatch3 = match;
360 }
361 *parentMatch2 = match;
362 }
363 *parentMatch1 = match;
364 }
365 if (match.hit)
366 {
367 {
368 #if (DEBUG)
369 if (writeToLog) System.Lex.WriteSuccessToLog(lexer, debugSpan, u"TemplateParameter");
370 #endif
371 return Match(true, new TemplateParameterNode(span, id.Release(), type.Release()));
372 }
373 }
374 *parentMatch0 = match;
375 }
376 #if (DEBUG)
377 if (writeToLog)
378 {
379 if (match.hit)
380 {
381 System.Lex.WriteSuccessToLog(lexer, debugSpan, u"TemplateParameter");
382 }
383 else
384 {
385 System.Lex.WriteFailureToLog(lexer, u"TemplateParameter");
386 }
387 }
388 #endif
389 if (!match.hit)
390 {
391 match.value = null;
392 }
393 return match;
394 }
395 public static Match TemplateParameterList(ParserFileLexer& lexer, ParsingContext* ctx, Node* owner)
396 {
397 #if (DEBUG)
398 Span debugSpan;
399 bool writeToLog = lexer.Log() != null;
400 if (writeToLog)
401 {
402 debugSpan = lexer.GetSpan();
403 System.Lex.WriteBeginRuleToLog(lexer, u"TemplateParameterList");
404 }
405 #endif
406 UniquePtr<TemplateParameterNode> tp;
407 Match match(false);
408 Match* parentMatch0 = &match;
409 {
410 Match match(false);
411 Match* parentMatch1 = &match;
412 {
413 Match match(false);
414 if (*lexer == LANGLE)
415 {
416 ++lexer;
417 match.hit = true;
418 }
419 *parentMatch1 = match;
420 }
421 if (match.hit)
422 {
423 Match match(false);
424 Match* parentMatch2 = &match;
425 {
426 Match match(false);
427 Match* parentMatch3 = &match;
428 {
429 Match match(false);
430 Match* parentMatch4 = &match;
431 {
432 Match match(false);
433 Match* parentMatch5 = &match;
434 {
435 long pos = lexer.GetPos();
436 Match match = ParTemplateParser.TemplateParameter(lexer, ctx);
437 tp.Reset(cast<TemplateParameterNode*>(match.value));
438 if (match.hit)
439 {
440 owner->AddTemplateParameter(tp.Release());
441 }
442 *parentMatch5 = match;
443 }
444 *parentMatch4 = match;
445 }
446 if (match.hit)
447 {
448 Match match(false);
449 Match* parentMatch6 = &match;
450 {
451 Match match(true);
452 Match* parentMatch7 = &match;
453 {
454 while (true)
455 {
456 long save = lexer.GetPos();
457 {
458 Match match(false);
459 Match* parentMatch8 = &match;
460 {
461 Match match(false);
462 if (*lexer == COMMA)
463 {
464 ++lexer;
465 match.hit = true;
466 }
467 *parentMatch8 = match;
468 }
469 if (match.hit)
470 {
471 Match match(false);
472 Match* parentMatch9 = &match;
473 {
474 Match match(false);
475 Match* parentMatch10 = &match;
476 {
477 long pos = lexer.GetPos();
478 Match match = ParTemplateParser.TemplateParameter(lexer, ctx);
479 tp.Reset(cast<TemplateParameterNode*>(match.value));
480 if (match.hit)
481 {
482 owner->AddTemplateParameter(tp.Release());
483 }
484 *parentMatch10 = match;
485 }
486 *parentMatch9 = match;
487 }
488 *parentMatch8 = match;
489 }
490 if (match.hit)
491 {
492 *parentMatch7 = match;
493 }
494 else
495 {
496 lexer.SetPos(save);
497 break;
498 }
499 }
500 }
501 }
502 *parentMatch6 = match;
503 }
504 *parentMatch4 = match;
505 }
506 *parentMatch3 = match;
507 }
508 *parentMatch2 = match;
509 }
510 *parentMatch1 = match;
511 }
512 *parentMatch0 = match;
513 }
514 if (match.hit)
515 {
516 Match match(false);
517 Match* parentMatch11 = &match;
518 {
519 Match match(true);
520 Match* parentMatch12 = &match;
521 {
522 System.Lex.Span span = lexer.GetSpan();
523 Match match(false);
524 if (*lexer == RANGLE)
525 {
526 ++lexer;
527 match.hit = true;
528 }
529 if (match.hit)
530 {
531 *parentMatch12 = match;
532 }
533 else
534 {
535 lexer.ThrowExpectationFailure(span, GetTokenName(RANGLE));
536 }
537 }
538 *parentMatch11 = match;
539 }
540 *parentMatch0 = match;
541 }
542 #if (DEBUG)
543 if (writeToLog)
544 {
545 if (match.hit)
546 {
547 System.Lex.WriteSuccessToLog(lexer, debugSpan, u"TemplateParameterList");
548 }
549 else
550 {
551 System.Lex.WriteFailureToLog(lexer, u"TemplateParameterList");
552 }
553 }
554 #endif
555 if (!match.hit)
556 {
557 match.value = null;
558 }
559 return match;
560 }
561 }