1 using System;
  2 using System.Collections;
  3 using System.Lex;
  4 using System.Parsing;
  5 using Cm.Ast;
  6 using ParserFileTokens;
  7 
  8 // this file has been automatically generated from 'C:/work/cmajorm/cmajor/projects/tools/soulcm/scmpg/build/Literal.parser' using soulcm parser generator scmpg version 5.0.0
  9 
 10 public static class LiteralParser
 11 {
 12     public static Match Literal(ParserFileLexer& lexerParsingContext* 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(lexeru"Literal");
 21             }
 22         #endif
 23         UniquePtr<LiteralNode> simpleLiteral;
 24         UniquePtr<LiteralNode> complexLiteral;
 25         Match match(false);
 26         Match* parentMatch0 = &match;
 27         {
 28             long save = lexer.GetPos();
 29             Match match(false);
 30             Match* parentMatch1 = &match;
 31             {
 32                 long pos = lexer.GetPos();
 33                 Match match = LiteralParser.SimpleLiteral(lexerctx);
 34                 simpleLiteral.Reset(cast<LiteralNode*>(match.value));
 35                 if (match.hit)
 36                 {
 37                     {
 38                         #if (DEBUG)
 39                             if (writeToLog) System.Lex.WriteSuccessToLog(lexerdebugSpanu"Literal");
 40                         #endif
 41                         return Match(truesimpleLiteral.Release());
 42                     }
 43                 }
 44                 *parentMatch1 = match;
 45             }
 46             *parentMatch0 = match;
 47             if (!match.hit)
 48             {
 49                 Match match(false);
 50                 Match* parentMatch2 = &match;
 51                 lexer.SetPos(save);
 52                 {
 53                     Match match(false);
 54                     Match* parentMatch3 = &match;
 55                     {
 56                         long pos = lexer.GetPos();
 57                         Match match = LiteralParser.ComplexLiteral(lexerctx);
 58                         complexLiteral.Reset(cast<LiteralNode*>(match.value));
 59                         if (match.hit)
 60                         {
 61                             {
 62                                 #if (DEBUG)
 63                                     if (writeToLog) System.Lex.WriteSuccessToLog(lexerdebugSpanu"Literal");
 64                                 #endif
 65                                 return Match(truecomplexLiteral.Release());
 66                             }
 67                         }
 68                         *parentMatch3 = match;
 69                     }
 70                     *parentMatch2 = match;
 71                 }
 72                 *parentMatch0 = match;
 73             }
 74         }
 75         #if (DEBUG)
 76             if (writeToLog)
 77             {
 78                 if (match.hit)
 79                 {
 80                     System.Lex.WriteSuccessToLog(lexerdebugSpanu"Literal");
 81                 }
 82                 else
 83                 {
 84                     System.Lex.WriteFailureToLog(lexeru"Literal");
 85                 }
 86             }
 87         #endif
 88         if (!match.hit)
 89         {
 90             match.value = null;
 91         }
 92         return match;
 93     }
 94     public static Match SimpleLiteral(ParserFileLexer& lexerParsingContext* ctx)
 95     {
 96         #if (DEBUG)
 97             Span debugSpan;
 98             bool writeToLog = lexer.Log() != null;
 99             if (writeToLog)
100             {
101                 debugSpan = lexer.GetSpan();
102                 System.Lex.WriteBeginRuleToLog(lexeru"SimpleLiteral");
103             }
104         #endif
105         Match match(false);
106         long pos = lexer.GetPos();
107         Span span = lexer.GetSpan();
108         switch (*lexer)
109         {
110             case TRUE:
111             {
112                 ++lexer;
113                 LiteralNode* value = new BooleanLiteralNode(spanctx->ModuleId()true);
114                 value->SetText(lexer.GetMatch(span));
115                 {
116                     #if (DEBUG)
117                         if (writeToLog) System.Lex.WriteSuccessToLog(lexerdebugSpanu"SimpleLiteral");
118                     #endif
119                     return Match(truevalue);
120                 }
121                 break;
122             }
123             case FALSE:
124             {
125                 ++lexer;
126                 LiteralNode* value = new BooleanLiteralNode(spanctx->ModuleId()false);
127                 value->SetText(lexer.GetMatch(span));
128                 {
129                     #if (DEBUG)
130                         if (writeToLog) System.Lex.WriteSuccessToLog(lexerdebugSpanu"SimpleLiteral");
131                     #endif
132                     return Match(truevalue);
133                 }
134                 break;
135             }
136             case FLOATINGLIT:
137             {
138                 ++lexer;
139                 soulcm.scmpg.ParseFloatingLiteral(lexer.FileName()lexer.GetToken(pos)lexer.floatingLitlexer.floatingLitFloat);
140                 LiteralNode* value = CreateFloatingLiteralNode(spanctx->ModuleId()lexer.floatingLitlexer.floatingLitFloat);
141                 value->SetText(lexer.GetMatch(span));
142                 {
143                     #if (DEBUG)
144                         if (writeToLog) System.Lex.WriteSuccessToLog(lexerdebugSpanu"SimpleLiteral");
145                     #endif
146                     return Match(truevalue);
147                 }
148                 break;
149             }
150             case INTLIT:
151             {
152                 ++lexer;
153                 soulcm.scmpg.ParseIntegerLiteral(lexer.FileName()lexer.GetToken(pos)lexer.intLitlexer.intLitUnsigned);
154                 LiteralNode* value = CreateIntegerLiteralNode(spanctx->ModuleId()lexer.intLitlexer.intLitUnsigned);
155                 value->SetText(lexer.GetMatch(span));
156                 {
157                     #if (DEBUG)
158                         if (writeToLog) System.Lex.WriteSuccessToLog(lexerdebugSpanu"SimpleLiteral");
159                     #endif
160                     return Match(truevalue);
161                 }
162                 break;
163             }
164             case CHARLIT:
165             {
166                 ++lexer;
167                 soulcm.scmpg.ParseCharacterLiteral(lexer.FileName()lexer.GetToken(pos)lexer.chrLitlexer.chrLitPrefix);
168                 LiteralNode* value = CreateCharacterLiteralNode(spanctx->ModuleId()lexer.chrLitlexer.chrLitPrefix);
169                 value->SetText(lexer.GetMatch(span));
170                 {
171                     #if (DEBUG)
172                         if (writeToLog) System.Lex.WriteSuccessToLog(lexerdebugSpanu"SimpleLiteral");
173                     #endif
174                     return Match(truevalue);
175                 }
176                 break;
177             }
178             case STRINGLIT:
179             {
180                 ++lexer;
181                 soulcm.scmpg.ParseStringLiteral(lexer.FileName()lexer.GetToken(pos)lexer.strLitlexer.strLitPrefix);
182                 LiteralNode* value = CreateStringLiteralNode(spanctx->ModuleId()lexer.strLitlexer.strLitPrefix);
183                 value->SetText(lexer.GetMatch(span));
184                 {
185                     #if (DEBUG)
186                         if (writeToLog) System.Lex.WriteSuccessToLog(lexerdebugSpanu"SimpleLiteral");
187                     #endif
188                     return Match(truevalue);
189                 }
190                 break;
191             }
192             case NULLLIT:
193             {
194                 ++lexer;
195                 LiteralNode* value = new NullLiteralNode(spanctx->ModuleId());
196                 value->SetText(lexer.GetMatch(span));
197                 {
198                     #if (DEBUG)
199                         if (writeToLog) System.Lex.WriteSuccessToLog(lexerdebugSpanu"SimpleLiteral");
200                     #endif
201                     return Match(truevalue);
202                 }
203                 break;
204             }
205         }
206         #if (DEBUG)
207             if (writeToLog)
208             {
209                 if (match.hit)
210                 {
211                     System.Lex.WriteSuccessToLog(lexerdebugSpanu"SimpleLiteral");
212                 }
213                 else
214                 {
215                     System.Lex.WriteFailureToLog(lexeru"SimpleLiteral");
216                 }
217             }
218         #endif
219         if (!match.hit)
220         {
221             match.value = null;
222         }
223         return match;
224     }
225     public static Match ComplexLiteral(ParserFileLexer& lexerParsingContext* ctx)
226     {
227         #if (DEBUG)
228             Span debugSpan;
229             bool writeToLog = lexer.Log() != null;
230             if (writeToLog)
231             {
232                 debugSpan = lexer.GetSpan();
233                 System.Lex.WriteBeginRuleToLog(lexeru"ComplexLiteral");
234             }
235         #endif
236         UniquePtr<ArrayLiteralNode> arrayLiteral;
237         UniquePtr<StructuredLiteralNode> structuredLiteral;
238         Match match(false);
239         Match* parentMatch0 = &match;
240         {
241             long save = lexer.GetPos();
242             Match match(false);
243             Match* parentMatch1 = &match;
244             {
245                 long pos = lexer.GetPos();
246                 Match match = LiteralParser.ArrayLiteral(lexerctx);
247                 arrayLiteral.Reset(cast<ArrayLiteralNode*>(match.value));
248                 if (match.hit)
249                 {
250                     {
251                         #if (DEBUG)
252                             if (writeToLog) System.Lex.WriteSuccessToLog(lexerdebugSpanu"ComplexLiteral");
253                         #endif
254                         return Match(truearrayLiteral.Release());
255                     }
256                 }
257                 *parentMatch1 = match;
258             }
259             *parentMatch0 = match;
260             if (!match.hit)
261             {
262                 Match match(false);
263                 Match* parentMatch2 = &match;
264                 lexer.SetPos(save);
265                 {
266                     Match match(false);
267                     Match* parentMatch3 = &match;
268                     {
269                         long pos = lexer.GetPos();
270                         Match match = LiteralParser.StructuredLiteral(lexerctx);
271                         structuredLiteral.Reset(cast<StructuredLiteralNode*>(match.value));
272                         if (match.hit)
273                         {
274                             {
275                                 #if (DEBUG)
276                                     if (writeToLog) System.Lex.WriteSuccessToLog(lexerdebugSpanu"ComplexLiteral");
277                                 #endif
278                                 return Match(truestructuredLiteral.Release());
279                             }
280                         }
281                         *parentMatch3 = match;
282                     }
283                     *parentMatch2 = match;
284                 }
285                 *parentMatch0 = match;
286             }
287         }
288         #if (DEBUG)
289             if (writeToLog)
290             {
291                 if (match.hit)
292                 {
293                     System.Lex.WriteSuccessToLog(lexerdebugSpanu"ComplexLiteral");
294                 }
295                 else
296                 {
297                     System.Lex.WriteFailureToLog(lexeru"ComplexLiteral");
298                 }
299             }
300         #endif
301         if (!match.hit)
302         {
303             match.value = null;
304         }
305         return match;
306     }
307     public static Match ArrayLiteral(ParserFileLexer& lexerParsingContext* ctx)
308     {
309         #if (DEBUG)
310             Span debugSpan;
311             bool writeToLog = lexer.Log() != null;
312             if (writeToLog)
313             {
314                 debugSpan = lexer.GetSpan();
315                 System.Lex.WriteBeginRuleToLog(lexeru"ArrayLiteral");
316             }
317         #endif
318         UniquePtr<ArrayLiteralNode> arrayLiteral;
319         UniquePtr<Node> expr;
320         Match match(false);
321         Match* parentMatch0 = &match;
322         {
323             Match match(false);
324             Match* parentMatch1 = &match;
325             {
326                 Match match(false);
327                 Match* parentMatch2 = &match;
328                 {
329                     long pos = lexer.GetPos();
330                     Span span = lexer.GetSpan();
331                     Match match(false);
332                     if (*lexer == LBRACKET)
333                     {
334                         ++lexer;
335                         match.hit = true;
336                     }
337                     if (match.hit)
338                     {
339                         arrayLiteral.Reset(new ArrayLiteralNode(spanctx->ModuleId()));
340                     }
341                     *parentMatch2 = match;
342                 }
343                 *parentMatch1 = match;
344             }
345             if (match.hit)
346             {
347                 Match match(false);
348                 Match* parentMatch3 = &match;
349                 {
350                     Match match(true);
351                     long save = lexer.GetPos();
352                     Match* parentMatch4 = &match;
353                     {
354                         Match match(false);
355                         Match* parentMatch5 = &match;
356                         {
357                             Match match(false);
358                             Match* parentMatch6 = &match;
359                             {
360                                 Match match(false);
361                                 Match* parentMatch7 = &match;
362                                 {
363                                     long pos = lexer.GetPos();
364                                     Match match = ExpressionParser.Expression(lexerctx);
365                                     expr.Reset(cast<Node*>(match.value));
366                                     if (match.hit)
367                                     {
368                                         arrayLiteral->AddValue(expr.Release());
369                                     }
370                                     *parentMatch7 = match;
371                                 }
372                                 *parentMatch6 = match;
373                             }
374                             if (match.hit)
375                             {
376                                 Match match(false);
377                                 Match* parentMatch8 = &match;
378                                 {
379                                     Match match(true);
380                                     Match* parentMatch9 = &match;
381                                     {
382                                         while (true)
383                                         {
384                                             long save = lexer.GetPos();
385                                             {
386                                                 Match match(false);
387                                                 Match* parentMatch10 = &match;
388                                                 {
389                                                     Match match(false);
390                                                     if (*lexer == COMMA)
391                                                     {
392                                                         ++lexer;
393                                                         match.hit = true;
394                                                     }
395                                                     *parentMatch10 = match;
396                                                 }
397                                                 if (match.hit)
398                                                 {
399                                                     Match match(false);
400                                                     Match* parentMatch11 = &match;
401                                                     {
402                                                         Match match(false);
403                                                         Match* parentMatch12 = &match;
404                                                         {
405                                                             long pos = lexer.GetPos();
406                                                             Match match = ExpressionParser.Expression(lexerctx);
407                                                             expr.Reset(cast<Node*>(match.value));
408                                                             if (match.hit)
409                                                             {
410                                                                 arrayLiteral->AddValue(expr.Release());
411                                                             }
412                                                             *parentMatch12 = match;
413                                                         }
414                                                         *parentMatch11 = match;
415                                                     }
416                                                     *parentMatch10 = match;
417                                                 }
418                                                 if (match.hit)
419                                                 {
420                                                     *parentMatch9 = match;
421                                                 }
422                                                 else
423                                                 {
424                                                     lexer.SetPos(save);
425                                                     break;
426                                                 }
427                                             }
428                                         }
429                                     }
430                                     *parentMatch8 = match;
431                                 }
432                                 *parentMatch6 = match;
433                             }
434                             *parentMatch5 = match;
435                         }
436                         if (match.hit)
437                         {
438                             *parentMatch4 = match;
439                         }
440                         else
441                         {
442                             lexer.SetPos(save);
443                         }
444                     }
445                     *parentMatch3 = match;
446                 }
447                 *parentMatch1 = match;
448             }
449             *parentMatch0 = match;
450         }
451         if (match.hit)
452         {
453             Match match(false);
454             Match* parentMatch13 = &match;
455             {
456                 Match match(false);
457                 Match* parentMatch14 = &match;
458                 {
459                     long pos = lexer.GetPos();
460                     Span span = lexer.GetSpan();
461                     Match match(true);
462                     Match* parentMatch15 = &match;
463                     {
464                         System.Lex.Span span = lexer.GetSpan();
465                         Match match(false);
466                         if (*lexer == RBRACKET)
467                         {
468                             ++lexer;
469                             match.hit = true;
470                         }
471                         if (match.hit)
472                         {
473                             *parentMatch15 = match;
474                         }
475                         else
476                         {
477                             lexer.ThrowExpectationFailure(spanGetTokenName(RBRACKET));
478                         }
479                     }
480                     if (match.hit)
481                     {
482                         arrayLiteral->SetSpanEnd(span.end);
483                         {
484                             #if (DEBUG)
485                                 if (writeToLog) System.Lex.WriteSuccessToLog(lexerdebugSpanu"ArrayLiteral");
486                             #endif
487                             return Match(truearrayLiteral.Release());
488                         }
489                     }
490                     *parentMatch14 = match;
491                 }
492                 *parentMatch13 = match;
493             }
494             *parentMatch0 = match;
495         }
496         #if (DEBUG)
497             if (writeToLog)
498             {
499                 if (match.hit)
500                 {
501                     System.Lex.WriteSuccessToLog(lexerdebugSpanu"ArrayLiteral");
502                 }
503                 else
504                 {
505                     System.Lex.WriteFailureToLog(lexeru"ArrayLiteral");
506                 }
507             }
508         #endif
509         if (!match.hit)
510         {
511             match.value = null;
512         }
513         return match;
514     }
515     public static Match StructuredLiteral(ParserFileLexer& lexerParsingContext* ctx)
516     {
517         #if (DEBUG)
518             Span debugSpan;
519             bool writeToLog = lexer.Log() != null;
520             if (writeToLog)
521             {
522                 debugSpan = lexer.GetSpan();
523                 System.Lex.WriteBeginRuleToLog(lexeru"StructuredLiteral");
524             }
525         #endif
526         UniquePtr<StructuredLiteralNode> structuredLiteral;
527         UniquePtr<Node> expr;
528         Match match(false);
529         Match* parentMatch0 = &match;
530         {
531             Match match(false);
532             Match* parentMatch1 = &match;
533             {
534                 Match match(false);
535                 Match* parentMatch2 = &match;
536                 {
537                     long pos = lexer.GetPos();
538                     Span span = lexer.GetSpan();
539                     Match match(false);
540                     if (*lexer == LBRACE)
541                     {
542                         ++lexer;
543                         match.hit = true;
544                     }
545                     if (match.hit)
546                     {
547                         structuredLiteral.Reset(new StructuredLiteralNode(spanctx->ModuleId()));
548                     }
549                     *parentMatch2 = match;
550                 }
551                 *parentMatch1 = match;
552             }
553             if (match.hit)
554             {
555                 Match match(false);
556                 Match* parentMatch3 = &match;
557                 {
558                     Match match(true);
559                     long save = lexer.GetPos();
560                     Match* parentMatch4 = &match;
561                     {
562                         Match match(false);
563                         Match* parentMatch5 = &match;
564                         {
565                             Match match(false);
566                             Match* parentMatch6 = &match;
567                             {
568                                 Match match(false);
569                                 Match* parentMatch7 = &match;
570                                 {
571                                     long pos = lexer.GetPos();
572                                     Match match = ExpressionParser.Expression(lexerctx);
573                                     expr.Reset(cast<Node*>(match.value));
574                                     if (match.hit)
575                                     {
576                                         structuredLiteral->AddMember(expr.Release());
577                                     }
578                                     *parentMatch7 = match;
579                                 }
580                                 *parentMatch6 = match;
581                             }
582                             if (match.hit)
583                             {
584                                 Match match(false);
585                                 Match* parentMatch8 = &match;
586                                 {
587                                     Match match(true);
588                                     Match* parentMatch9 = &match;
589                                     {
590                                         while (true)
591                                         {
592                                             long save = lexer.GetPos();
593                                             {
594                                                 Match match(false);
595                                                 Match* parentMatch10 = &match;
596                                                 {
597                                                     Match match(false);
598                                                     if (*lexer == COMMA)
599                                                     {
600                                                         ++lexer;
601                                                         match.hit = true;
602                                                     }
603                                                     *parentMatch10 = match;
604                                                 }
605                                                 if (match.hit)
606                                                 {
607                                                     Match match(false);
608                                                     Match* parentMatch11 = &match;
609                                                     {
610                                                         Match match(false);
611                                                         Match* parentMatch12 = &match;
612                                                         {
613                                                             long pos = lexer.GetPos();
614                                                             Match match = ExpressionParser.Expression(lexerctx);
615                                                             expr.Reset(cast<Node*>(match.value));
616                                                             if (match.hit)
617                                                             {
618                                                                 structuredLiteral->AddMember(expr.Release());
619                                                             }
620                                                             *parentMatch12 = match;
621                                                         }
622                                                         *parentMatch11 = match;
623                                                     }
624                                                     *parentMatch10 = match;
625                                                 }
626                                                 if (match.hit)
627                                                 {
628                                                     *parentMatch9 = match;
629                                                 }
630                                                 else
631                                                 {
632                                                     lexer.SetPos(save);
633                                                     break;
634                                                 }
635                                             }
636                                         }
637                                     }
638                                     *parentMatch8 = match;
639                                 }
640                                 *parentMatch6 = match;
641                             }
642                             *parentMatch5 = match;
643                         }
644                         if (match.hit)
645                         {
646                             *parentMatch4 = match;
647                         }
648                         else
649                         {
650                             lexer.SetPos(save);
651                         }
652                     }
653                     *parentMatch3 = match;
654                 }
655                 *parentMatch1 = match;
656             }
657             *parentMatch0 = match;
658         }
659         if (match.hit)
660         {
661             Match match(false);
662             Match* parentMatch13 = &match;
663             {
664                 Match match(false);
665                 Match* parentMatch14 = &match;
666                 {
667                     long pos = lexer.GetPos();
668                     Span span = lexer.GetSpan();
669                     Match match(true);
670                     Match* parentMatch15 = &match;
671                     {
672                         System.Lex.Span span = lexer.GetSpan();
673                         Match match(false);
674                         if (*lexer == RBRACE)
675                         {
676                             ++lexer;
677                             match.hit = true;
678                         }
679                         if (match.hit)
680                         {
681                             *parentMatch15 = match;
682                         }
683                         else
684                         {
685                             lexer.ThrowExpectationFailure(spanGetTokenName(RBRACE));
686                         }
687                     }
688                     if (match.hit)
689                     {
690                         structuredLiteral->SetSpanEnd(span.end);
691                         {
692                             #if (DEBUG)
693                                 if (writeToLog) System.Lex.WriteSuccessToLog(lexerdebugSpanu"StructuredLiteral");
694                             #endif
695                             return Match(truestructuredLiteral.Release());
696                         }
697                     }
698                     *parentMatch14 = match;
699                 }
700                 *parentMatch13 = match;
701             }
702             *parentMatch0 = match;
703         }
704         #if (DEBUG)
705             if (writeToLog)
706             {
707                 if (match.hit)
708                 {
709                     System.Lex.WriteSuccessToLog(lexerdebugSpanu"StructuredLiteral");
710                 }
711                 else
712                 {
713                     System.Lex.WriteFailureToLog(lexeru"StructuredLiteral");
714                 }
715             }
716         #endif
717         if (!match.hit)
718         {
719             match.value = null;
720         }
721         return match;
722     }
723 }