1 #include "Template.hpp"
  2 #include <soulng/util/Unicode.hpp>
  3 #include <sngcm/cmlexer/CmajorLexer.hpp>
  4 #include <sngcm/cmlexer/CmajorTokens.hpp>
  5 
  6 // this file has been automatically generated from 'C:/work/cmajorm/cmajor/sngcm/cmparser/Template.parser' using soulng parser generator spg version 3.10.0
  7 
  8 using namespace soulng::unicode;
  9 using namespace sngcm::ast;
 10 using namespace CmajorTokens;
 11 
 12 soulng::parser::Match TemplateParser::TemplateId(CmajorLexer& lexerboost::uuids::uuid* moduleIdParsingContext* ctx)
 13 {
 14     #ifdef SOULNG_PARSER_DEBUG_SUPPORT
 15 
 16 
 17 
 18 
 19 
 20 
 21 
 22     #endif // SOULNG_PARSER_DEBUG_SUPPORT
 23     std::unique_ptr<TemplateIdNode> templateId = std::unique_ptr<TemplateIdNode>();
 24     Span e = Span();
 25     std::unique_ptr<IdentifierNode> primary;
 26     std::unique_ptr<sngcm::ast::Node> templateArg;
 27     soulng::parser::Match match(false);
 28     soulng::parser::Match* parentMatch0 = &match;
 29     {
 30         soulng::parser::Match match(false);
 31         soulng::parser::Match* parentMatch1 = &match;
 32         {
 33             int64_t pos = lexer.GetPos();
 34             soulng::parser::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         soulng::parser::Match match(false);
 46         soulng::parser::Match* parentMatch2 = &match;
 47         {
 48             soulng::parser::Match match(false);
 49             soulng::parser::Match* parentMatch3 = &match;
 50             {
 51                 int64_t pos = lexer.GetPos();
 52                 soulng::parser::Match match(false);
 53                 soulng::parser::Match* parentMatch4 = &match;
 54                 {
 55                     soulng::parser::Match match(false);
 56                     soulng::parser::Match* parentMatch5 = &match;
 57                     {
 58                         soulng::parser::Match match(false);
 59                         soulng::parser::Match* parentMatch6 = &match;
 60                         {
 61                             soulng::parser::Match match(false);
 62                             soulng::parser::Match* parentMatch7 = &match;
 63                             {
 64                                 int64_t pos = lexer.GetPos();
 65                                 soulng::lexer::Span span = lexer.GetSpan();
 66                                 soulng::parser::Match match = IdentifierParser::QualifiedId(lexermoduleId);
 67                                 primary.reset(static_cast<IdentifierNode*>(match.value));
 68                                 if (match.hit)
 69                                 {
 70                                     templateId.reset(new TemplateIdNode(span*moduleIdprimary.release()));
 71                                 }
 72                                 *parentMatch7 = match;
 73                             }
 74                             *parentMatch6 = match;
 75                         }
 76                         if (match.hit)
 77                         {
 78                             soulng::parser::Match match(false);
 79                             soulng::parser::Match* parentMatch8 = &match;
 80                             {
 81                                 soulng::parser::Match match(false);
 82                                 soulng::parser::Match* parentMatch9 = &match;
 83                                 {
 84                                     int64_t pos = lexer.GetPos();
 85                                     soulng::parser::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                         soulng::parser::Match match(false);
106                         soulng::parser::Match* parentMatch10 = &match;
107                         {
108                             soulng::parser::Match match(false);
109                             soulng::parser::Match* parentMatch11 = &match;
110                             {
111                                 int64_t pos = lexer.GetPos();
112                                 soulng::parser::Match match(false);
113                                 soulng::parser::Match* parentMatch12 = &match;
114                                 {
115                                     soulng::parser::Match match(false);
116                                     soulng::parser::Match* parentMatch13 = &match;
117                                     {
118                                         soulng::parser::Match match(false);
119                                         soulng::parser::Match* parentMatch14 = &match;
120                                         {
121                                             soulng::parser::Match match(false);
122                                             soulng::parser::Match* parentMatch15 = &match;
123                                             {
124                                                 soulng::parser::Match match(false);
125                                                 soulng::parser::Match* parentMatch16 = &match;
126                                                 {
127                                                     int64_t pos = lexer.GetPos();
128                                                     soulng::parser::Match match = TypeExprParser::TypeExpr(lexermoduleIdctx);
129                                                     templateArg.reset(static_cast<sngcm::ast::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                                                 soulng::parser::Match match(false);
141                                                 soulng::parser::Match* parentMatch17 = &match;
142                                                 {
143                                                     soulng::parser::Match match(true);
144                                                     soulng::parser::Match* parentMatch18 = &match;
145                                                     {
146                                                         while (true)
147                                                         {
148                                                             int64_t save = lexer.GetPos();
149                                                             {
150                                                                 soulng::parser::Match match(false);
151                                                                 soulng::parser::Match* parentMatch19 = &match;
152                                                                 {
153                                                                     soulng::parser::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                                                                     soulng::parser::Match match(false);
164                                                                     soulng::parser::Match* parentMatch20 = &match;
165                                                                     {
166                                                                         soulng::parser::Match match(false);
167                                                                         soulng::parser::Match* parentMatch21 = &match;
168                                                                         {
169                                                                             int64_t pos = lexer.GetPos();
170                                                                             soulng::parser::Match match = TypeExprParser::TypeExpr(lexermoduleIdctx);
171                                                                             templateArg.reset(static_cast<sngcm::ast::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                                         soulng::parser::Match match(false);
205                                         soulng::parser::Match* parentMatch22 = &match;
206                                         {
207                                             soulng::parser::Match match(false);
208                                             soulng::parser::Match* parentMatch23 = &match;
209                                             {
210                                                 int64_t pos = lexer.GetPos();
211                                                 soulng::lexer::Span span = lexer.GetSpan();
212                                                 soulng::parser::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                         #ifdef SOULNG_PARSER_DEBUG_SUPPORT
252 
253                         #endif // SOULNG_PARSER_DEBUG_SUPPORT
254                         return soulng::parser::Match(truetemplateId.release());
255                     }
256                 }
257                 else
258                 {
259                     ctx->EndParsingTemplateId();
260                 }
261                 *parentMatch3 = match;
262             }
263             *parentMatch2 = match;
264         }
265         *parentMatch0 = match;
266     }
267     #ifdef SOULNG_PARSER_DEBUG_SUPPORT
268 
269 
270 
271 
272 
273     #endif // SOULNG_PARSER_DEBUG_SUPPORT
274     if (!match.hit)
275     {
276         match.value = nullptr;
277     }
278     return match;
279 }
280 
281 soulng::parser::Match TemplateParser::TemplateParameter(CmajorLexer& lexerboost::uuids::uuid* moduleIdParsingContext* ctx)
282 {
283     #ifdef SOULNG_PARSER_DEBUG_SUPPORT
284 
285 
286 
287 
288 
289 
290 
291     #endif // SOULNG_PARSER_DEBUG_SUPPORT
292     std::unique_ptr<IdentifierNode> id;
293     std::unique_ptr<sngcm::ast::Node> type;
294     soulng::parser::Match match(false);
295     soulng::parser::Match* parentMatch0 = &match;
296     {
297         int64_t pos = lexer.GetPos();
298         soulng::lexer::Span span = lexer.GetSpan();
299         soulng::parser::Match match(false);
300         soulng::parser::Match* parentMatch1 = &match;
301         {
302             soulng::parser::Match match(false);
303             soulng::parser::Match* parentMatch2 = &match;
304             {
305                 soulng::parser::Match match = IdentifierParser::Identifier(lexermoduleId);
306                 id.reset(static_cast<IdentifierNode*>(match.value));
307                 *parentMatch2 = match;
308             }
309             if (match.hit)
310             {
311                 soulng::parser::Match match(false);
312                 soulng::parser::Match* parentMatch3 = &match;
313                 {
314                     soulng::parser::Match match(true);
315                     int64_t save = lexer.GetPos();
316                     soulng::parser::Match* parentMatch4 = &match;
317                     {
318                         soulng::parser::Match match(false);
319                         soulng::parser::Match* parentMatch5 = &match;
320                         {
321                             soulng::parser::Match match(false);
322                             soulng::parser::Match* parentMatch6 = &match;
323                             {
324                                 soulng::parser::Match match(false);
325                                 if (*lexer == ASSIGN)
326                                 {
327                                     ++lexer;
328                                     match.hit = true;
329                                 }
330                                 *parentMatch6 = match;
331                             }
332                             if (match.hit)
333                             {
334                                 soulng::parser::Match match(false);
335                                 soulng::parser::Match* parentMatch7 = &match;
336                                 {
337                                     soulng::parser::Match match = TypeExprParser::TypeExpr(lexermoduleIdctx);
338                                     type.reset(static_cast<sngcm::ast::Node*>(match.value));
339                                     *parentMatch7 = match;
340                                 }
341                                 *parentMatch6 = match;
342                             }
343                             *parentMatch5 = match;
344                         }
345                         if (match.hit)
346                         {
347                             *parentMatch4 = match;
348                         }
349                         else
350                         {
351                             lexer.SetPos(save);
352                         }
353                     }
354                     *parentMatch3 = match;
355                 }
356                 *parentMatch2 = match;
357             }
358             *parentMatch1 = match;
359         }
360         if (match.hit)
361         {
362             {
363                 #ifdef SOULNG_PARSER_DEBUG_SUPPORT
364 
365                 #endif // SOULNG_PARSER_DEBUG_SUPPORT
366                 return soulng::parser::Match(truenew TemplateParameterNode(span*moduleIdid.release()type.release()));
367             }
368         }
369         *parentMatch0 = match;
370     }
371     #ifdef SOULNG_PARSER_DEBUG_SUPPORT
372 
373 
374 
375 
376 
377     #endif // SOULNG_PARSER_DEBUG_SUPPORT
378     if (!match.hit)
379     {
380         match.value = nullptr;
381     }
382     return match;
383 }
384 
385 soulng::parser::Match TemplateParser::TemplateParameterList(CmajorLexer& lexerboost::uuids::uuid* moduleIdParsingContext* ctxsngcm::ast::Node* owner)
386 {
387     #ifdef SOULNG_PARSER_DEBUG_SUPPORT
388 
389 
390 
391 
392 
393 
394 
395     #endif // SOULNG_PARSER_DEBUG_SUPPORT
396     std::unique_ptr<TemplateParameterNode> tp;
397     soulng::parser::Match match(false);
398     soulng::parser::Match* parentMatch0 = &match;
399     {
400         soulng::parser::Match match(false);
401         soulng::parser::Match* parentMatch1 = &match;
402         {
403             soulng::parser::Match match(false);
404             if (*lexer == LANGLE)
405             {
406                 ++lexer;
407                 match.hit = true;
408             }
409             *parentMatch1 = match;
410         }
411         if (match.hit)
412         {
413             soulng::parser::Match match(false);
414             soulng::parser::Match* parentMatch2 = &match;
415             {
416                 soulng::parser::Match match(false);
417                 soulng::parser::Match* parentMatch3 = &match;
418                 {
419                     soulng::parser::Match match(false);
420                     soulng::parser::Match* parentMatch4 = &match;
421                     {
422                         soulng::parser::Match match(false);
423                         soulng::parser::Match* parentMatch5 = &match;
424                         {
425                             int64_t pos = lexer.GetPos();
426                             soulng::parser::Match match = TemplateParser::TemplateParameter(lexermoduleIdctx);
427                             tp.reset(static_cast<TemplateParameterNode*>(match.value));
428                             if (match.hit)
429                             {
430                                 owner->AddTemplateParameter(tp.release());
431                             }
432                             *parentMatch5 = match;
433                         }
434                         *parentMatch4 = match;
435                     }
436                     if (match.hit)
437                     {
438                         soulng::parser::Match match(false);
439                         soulng::parser::Match* parentMatch6 = &match;
440                         {
441                             soulng::parser::Match match(true);
442                             soulng::parser::Match* parentMatch7 = &match;
443                             {
444                                 while (true)
445                                 {
446                                     int64_t save = lexer.GetPos();
447                                     {
448                                         soulng::parser::Match match(false);
449                                         soulng::parser::Match* parentMatch8 = &match;
450                                         {
451                                             soulng::parser::Match match(false);
452                                             if (*lexer == COMMA)
453                                             {
454                                                 ++lexer;
455                                                 match.hit = true;
456                                             }
457                                             *parentMatch8 = match;
458                                         }
459                                         if (match.hit)
460                                         {
461                                             soulng::parser::Match match(false);
462                                             soulng::parser::Match* parentMatch9 = &match;
463                                             {
464                                                 soulng::parser::Match match(false);
465                                                 soulng::parser::Match* parentMatch10 = &match;
466                                                 {
467                                                     int64_t pos = lexer.GetPos();
468                                                     soulng::parser::Match match = TemplateParser::TemplateParameter(lexermoduleIdctx);
469                                                     tp.reset(static_cast<TemplateParameterNode*>(match.value));
470                                                     if (match.hit)
471                                                     {
472                                                         owner->AddTemplateParameter(tp.release());
473                                                     }
474                                                     *parentMatch10 = match;
475                                                 }
476                                                 *parentMatch9 = match;
477                                             }
478                                             *parentMatch8 = match;
479                                         }
480                                         if (match.hit)
481                                         {
482                                             *parentMatch7 = match;
483                                         }
484                                         else
485                                         {
486                                             lexer.SetPos(save);
487                                             break;
488                                         }
489                                     }
490                                 }
491                             }
492                             *parentMatch6 = match;
493                         }
494                         *parentMatch4 = match;
495                     }
496                     *parentMatch3 = match;
497                 }
498                 *parentMatch2 = match;
499             }
500             *parentMatch1 = match;
501         }
502         *parentMatch0 = match;
503     }
504     if (match.hit)
505     {
506         soulng::parser::Match match(false);
507         soulng::parser::Match* parentMatch11 = &match;
508         {
509             soulng::parser::Match match(true);
510             soulng::parser::Match* parentMatch12 = &match;
511             {
512                 soulng::lexer::Span span = lexer.GetSpan();
513                 soulng::parser::Match match(false);
514                 if (*lexer == RANGLE)
515                 {
516                     ++lexer;
517                     match.hit = true;
518                 }
519                 if (match.hit)
520                 {
521                     *parentMatch12 = match;
522                 }
523                 else
524                 {
525                     lexer.ThrowExpectationFailure(spanToUtf32(GetTokenInfo(RANGLE)));
526                 }
527             }
528             *parentMatch11 = match;
529         }
530         *parentMatch0 = match;
531     }
532     #ifdef SOULNG_PARSER_DEBUG_SUPPORT
533 
534 
535 
536 
537 
538     #endif // SOULNG_PARSER_DEBUG_SUPPORT
539     if (!match.hit)
540     {
541         match.value = nullptr;
542     }
543     return match;
544 }
545 
546 soulng::parser::Match TemplateParser::InstantiationRequest(CmajorLexer& lexerboost::uuids::uuid* moduleIdParsingContext* ctx)
547 {
548     #ifdef SOULNG_PARSER_DEBUG_SUPPORT
549 
550 
551 
552 
553 
554 
555 
556     #endif // SOULNG_PARSER_DEBUG_SUPPORT
557     Span s = Span();
558     std::unique_ptr<FullInstantiationRequestNode> fullInstantiationRequestNode = std::unique_ptr<FullInstantiationRequestNode>();
559     std::unique_ptr<TemplateIdNode> templateId;
560     soulng::parser::Match match(false);
561     soulng::parser::Match* parentMatch0 = &match;
562     {
563         int64_t pos = lexer.GetPos();
564         soulng::parser::Match match(false);
565         soulng::parser::Match* parentMatch1 = &match;
566         {
567             soulng::parser::Match match(false);
568             soulng::parser::Match* parentMatch2 = &match;
569             {
570                 soulng::parser::Match match(false);
571                 soulng::parser::Match* parentMatch3 = &match;
572                 {
573                     soulng::parser::Match match(false);
574                     soulng::parser::Match* parentMatch4 = &match;
575                     {
576                         soulng::parser::Match match(false);
577                         soulng::parser::Match* parentMatch5 = &match;
578                         {
579                             int64_t pos = lexer.GetPos();
580                             soulng::lexer::Span span = lexer.GetSpan();
581                             soulng::parser::Match match(false);
582                             if (*lexer == NEW)
583                             {
584                                 ++lexer;
585                                 match.hit = true;
586                             }
587                             if (match.hit)
588                             {
589                                 s = span;
590                             }
591                             *parentMatch5 = match;
592                         }
593                         *parentMatch4 = match;
594                     }
595                     if (match.hit)
596                     {
597                         soulng::parser::Match match(false);
598                         soulng::parser::Match* parentMatch6 = &match;
599                         {
600                             soulng::parser::Match match(false);
601                             if (*lexer == CLASS)
602                             {
603                                 ++lexer;
604                                 match.hit = true;
605                             }
606                             *parentMatch6 = match;
607                         }
608                         *parentMatch4 = match;
609                     }
610                     *parentMatch3 = match;
611                 }
612                 if (match.hit)
613                 {
614                     soulng::parser::Match match(false);
615                     soulng::parser::Match* parentMatch7 = &match;
616                     {
617                         soulng::parser::Match match(false);
618                         soulng::parser::Match* parentMatch8 = &match;
619                         {
620                             int64_t pos = lexer.GetPos();
621                             soulng::lexer::Span span = lexer.GetSpan();
622                             soulng::parser::Match match = TemplateParser::TemplateId(lexermoduleIdctx);
623                             templateId.reset(static_cast<TemplateIdNode*>(match.value));
624                             if (match.hit)
625                             {
626                                 s.end = span.end;
627                                 fullInstantiationRequestNode.reset(new FullInstantiationRequestNode(s*moduleIdtemplateId.release()));
628                             }
629                             *parentMatch8 = match;
630                         }
631                         *parentMatch7 = match;
632                     }
633                     *parentMatch3 = match;
634                 }
635                 *parentMatch2 = match;
636             }
637             if (match.hit)
638             {
639                 soulng::parser::Match match(false);
640                 soulng::parser::Match* parentMatch9 = &match;
641                 {
642                     soulng::parser::Match match(false);
643                     if (*lexer == SEMICOLON)
644                     {
645                         ++lexer;
646                         match.hit = true;
647                     }
648                     *parentMatch9 = match;
649                 }
650                 *parentMatch2 = match;
651             }
652             *parentMatch1 = match;
653         }
654         if (match.hit)
655         {
656             {
657                 #ifdef SOULNG_PARSER_DEBUG_SUPPORT
658 
659                 #endif // SOULNG_PARSER_DEBUG_SUPPORT
660                 return soulng::parser::Match(truefullInstantiationRequestNode.release());
661             }
662         }
663         *parentMatch0 = match;
664     }
665     #ifdef SOULNG_PARSER_DEBUG_SUPPORT
666 
667 
668 
669 
670 
671     #endif // SOULNG_PARSER_DEBUG_SUPPORT
672     if (!match.hit)
673     {
674         match.value = nullptr;
675     }
676     return match;
677 }