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