1 #include "BuildLangServerParser.hpp"
2 #include <soulng/util/Unicode.hpp>
3 #include <cmajor/build/BuildLangLexer.hpp>
4 #include <cmajor/build/BuildLangTokens.hpp>
5 #include <cmajor/build/BuildLangOptionParser.hpp>
6
7
8
9 using namespace soulng::unicode;
10 using namespace BuildLangTokens;
11
12 std::std::unique_ptr<cmajor::build::ServerCommand>BuildLangServerParser::Parse(BuildLangLexer&lexer, cmajor::build::BuildOptionSetter*optionSetter)
13 {
14 std::unique_ptr<cmajor::build::ServerCommand> value;
15 #ifdef SOULNG_PARSER_DEBUG_SUPPORT
16
17
18
19
20
21 #endif // SOULNG_PARSER_DEBUG_SUPPORT
22 ++lexer;
23 soulng::lexer::Span span = lexer.GetSpan();
24 soulng::parser::Match match = BuildLangServerParser::ServerSentence(lexer, optionSetter);
25 value.reset(static_cast<cmajor::build::ServerCommand*>(match.value));
26 #ifdef SOULNG_PARSER_DEBUG_SUPPORT
27
28
29
30
31
32 #endif // SOULNG_PARSER_DEBUG_SUPPORT
33 if (match.hit)
34 {
35 if (*lexer == soulng::lexer::END_TOKEN)
36 {
37 return value;
38 }
39 else
40 {
41 lexer.ThrowExpectationFailure(lexer.GetSpan(), ToUtf32(soulng::lexer::GetEndTokenInfo()));
42 }
43 }
44 else
45 {
46 lexer.ThrowExpectationFailure(span, U"cmserver (add server | remove server | run server | show condiguration) ...");
47 }
48 return value;
49 }
50
51 soulng::parser::Match BuildLangServerParser::ServerSentence(BuildLangLexer& lexer, cmajor::build::BuildOptionSetter* optionSetter)
52 {
53 #ifdef SOULNG_PARSER_DEBUG_SUPPORT
54
55
56
57
58
59
60
61 #endif // SOULNG_PARSER_DEBUG_SUPPORT
62 std::unique_ptr<cmajor::build::ServerCommand> sentence;
63 soulng::parser::Match match(false);
64 soulng::parser::Match* parentMatch0 = &match;
65 {
66 soulng::parser::Match match(true);
67 int64_t save = lexer.GetPos();
68 soulng::parser::Match* parentMatch1 = &match;
69 {
70 soulng::parser::Match match = BuildLangOptionParser::Options(lexer, optionSetter);
71 if (match.hit)
72 {
73 *parentMatch1 = match;
74 }
75 else
76 {
77 lexer.SetPos(save);
78 }
79 }
80 *parentMatch0 = match;
81 }
82 if (match.hit)
83 {
84 soulng::parser::Match match(false);
85 soulng::parser::Match* parentMatch2 = &match;
86 {
87 soulng::parser::Match match(false);
88 soulng::parser::Match* parentMatch3 = &match;
89 {
90 int64_t pos = lexer.GetPos();
91 soulng::parser::Match match(true);
92 soulng::parser::Match* parentMatch4 = &match;
93 {
94 soulng::lexer::Span span = lexer.GetSpan();
95 soulng::parser::Match match = BuildLangServerParser::ServerCommandSentence(lexer);
96 sentence.reset(static_cast<cmajor::build::ServerCommand*>(match.value));
97 if (match.hit)
98 {
99 *parentMatch4 = match;
100 }
101 else
102 {
103 lexer.ThrowExpectationFailure(span, U"cmserver (add server | remove server | run server | show condiguration) ...");
104 }
105 }
106 if (match.hit)
107 {
108 {
109 #ifdef SOULNG_PARSER_DEBUG_SUPPORT
110
111 #endif // SOULNG_PARSER_DEBUG_SUPPORT
112 return soulng::parser::Match(true, sentence.release());
113 }
114 }
115 *parentMatch3 = match;
116 }
117 *parentMatch2 = match;
118 }
119 *parentMatch0 = match;
120 }
121 #ifdef SOULNG_PARSER_DEBUG_SUPPORT
122
123
124
125
126
127 #endif // SOULNG_PARSER_DEBUG_SUPPORT
128 if (!match.hit)
129 {
130 match.value = nullptr;
131 }
132 return match;
133 }
134
135 soulng::parser::Match BuildLangServerParser::ServerCommandSentence(BuildLangLexer& lexer)
136 {
137 #ifdef SOULNG_PARSER_DEBUG_SUPPORT
138
139
140
141
142
143
144
145 #endif // SOULNG_PARSER_DEBUG_SUPPORT
146 std::unique_ptr<cmajor::build::ServerCommand> addServerCommand;
147 std::unique_ptr<cmajor::build::ServerCommand> removeServerCommand;
148 std::unique_ptr<cmajor::build::ServerCommand> runServerCommand;
149 std::unique_ptr<cmajor::build::ServerCommand> showConfigurationCommand;
150 soulng::parser::Match match(false);
151 soulng::parser::Match* parentMatch0 = &match;
152 {
153 soulng::parser::Match match(false);
154 soulng::parser::Match* parentMatch1 = &match;
155 {
156 int64_t save = lexer.GetPos();
157 soulng::parser::Match match(false);
158 soulng::parser::Match* parentMatch2 = &match;
159 {
160 int64_t save = lexer.GetPos();
161 soulng::parser::Match match(false);
162 soulng::parser::Match* parentMatch3 = &match;
163 {
164 int64_t save = lexer.GetPos();
165 soulng::parser::Match match(false);
166 soulng::parser::Match* parentMatch4 = &match;
167 {
168 int64_t pos = lexer.GetPos();
169 soulng::parser::Match match = BuildLangServerParser::AddServerSentence(lexer);
170 addServerCommand.reset(static_cast<cmajor::build::ServerCommand*>(match.value));
171 if (match.hit)
172 {
173 {
174 #ifdef SOULNG_PARSER_DEBUG_SUPPORT
175
176 #endif // SOULNG_PARSER_DEBUG_SUPPORT
177 return soulng::parser::Match(true, addServerCommand.release());
178 }
179 }
180 *parentMatch4 = match;
181 }
182 *parentMatch3 = match;
183 if (!match.hit)
184 {
185 soulng::parser::Match match(false);
186 soulng::parser::Match* parentMatch5 = &match;
187 lexer.SetPos(save);
188 {
189 soulng::parser::Match match(false);
190 soulng::parser::Match* parentMatch6 = &match;
191 {
192 int64_t pos = lexer.GetPos();
193 soulng::parser::Match match = BuildLangServerParser::RemoveServerSentence(lexer);
194 removeServerCommand.reset(static_cast<cmajor::build::ServerCommand*>(match.value));
195 if (match.hit)
196 {
197 {
198 #ifdef SOULNG_PARSER_DEBUG_SUPPORT
199
200 #endif // SOULNG_PARSER_DEBUG_SUPPORT
201 return soulng::parser::Match(true, removeServerCommand.release());
202 }
203 }
204 *parentMatch6 = match;
205 }
206 *parentMatch5 = match;
207 }
208 *parentMatch3 = match;
209 }
210 }
211 *parentMatch2 = match;
212 if (!match.hit)
213 {
214 soulng::parser::Match match(false);
215 soulng::parser::Match* parentMatch7 = &match;
216 lexer.SetPos(save);
217 {
218 soulng::parser::Match match(false);
219 soulng::parser::Match* parentMatch8 = &match;
220 {
221 int64_t pos = lexer.GetPos();
222 soulng::parser::Match match = BuildLangServerParser::RunServerSentence(lexer);
223 runServerCommand.reset(static_cast<cmajor::build::ServerCommand*>(match.value));
224 if (match.hit)
225 {
226 {
227 #ifdef SOULNG_PARSER_DEBUG_SUPPORT
228
229 #endif // SOULNG_PARSER_DEBUG_SUPPORT
230 return soulng::parser::Match(true, runServerCommand.release());
231 }
232 }
233 *parentMatch8 = match;
234 }
235 *parentMatch7 = match;
236 }
237 *parentMatch2 = match;
238 }
239 }
240 *parentMatch1 = match;
241 if (!match.hit)
242 {
243 soulng::parser::Match match(false);
244 soulng::parser::Match* parentMatch9 = &match;
245 lexer.SetPos(save);
246 {
247 soulng::parser::Match match(false);
248 soulng::parser::Match* parentMatch10 = &match;
249 {
250 int64_t pos = lexer.GetPos();
251 soulng::parser::Match match = BuildLangServerParser::ShowConfigurationSentence(lexer);
252 showConfigurationCommand.reset(static_cast<cmajor::build::ServerCommand*>(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(true, showConfigurationCommand.release());
260 }
261 }
262 *parentMatch10 = match;
263 }
264 *parentMatch9 = match;
265 }
266 *parentMatch1 = match;
267 }
268 }
269 *parentMatch0 = match;
270 }
271 #ifdef SOULNG_PARSER_DEBUG_SUPPORT
272
273
274
275
276
277 #endif // SOULNG_PARSER_DEBUG_SUPPORT
278 if (!match.hit)
279 {
280 match.value = nullptr;
281 }
282 return match;
283 }
284
285 soulng::parser::Match BuildLangServerParser::AddServerSentence(BuildLangLexer& lexer)
286 {
287 #ifdef SOULNG_PARSER_DEBUG_SUPPORT
288
289
290
291
292
293
294
295 #endif // SOULNG_PARSER_DEBUG_SUPPORT
296 std::unique_ptr<soulng::parser::soulng::parser::Value<std::string>>server;
297 std::unique_ptr<soulng::parser::soulng::parser::Value<int>>port;
298 soulng::parser::Match match(false);
299 soulng::parser::Match* parentMatch0 = &match;
300 {
301 int64_t pos = lexer.GetPos();
302 soulng::parser::Match match(false);
303 soulng::parser::Match* parentMatch1 = &match;
304 {
305 soulng::parser::Match match(false);
306 soulng::parser::Match* parentMatch2 = &match;
307 {
308 soulng::parser::Match match(false);
309 soulng::parser::Match* parentMatch3 = &match;
310 {
311 soulng::parser::Match match(false);
312 soulng::parser::Match* parentMatch4 = &match;
313 {
314 soulng::parser::Match match(false);
315 soulng::parser::Match* parentMatch5 = &match;
316 {
317 soulng::parser::Match match(false);
318 if (*lexer == ADD)
319 {
320 ++lexer;
321 match.hit = true;
322 }
323 *parentMatch5 = match;
324 }
325 if (match.hit)
326 {
327 soulng::parser::Match match(false);
328 soulng::parser::Match* parentMatch6 = &match;
329 {
330 soulng::parser::Match match(true);
331 soulng::parser::Match* parentMatch7 = &match;
332 {
333 soulng::lexer::Span span = lexer.GetSpan();
334 soulng::parser::Match match(false);
335 if (*lexer == SERVER)
336 {
337 ++lexer;
338 match.hit = true;
339 }
340 if (match.hit)
341 {
342 *parentMatch7 = match;
343 }
344 else
345 {
346 lexer.ThrowExpectationFailure(span, ToUtf32(GetTokenInfo(SERVER)));
347 }
348 }
349 *parentMatch6 = match;
350 }
351 *parentMatch5 = match;
352 }
353 *parentMatch4 = match;
354 }
355 if (match.hit)
356 {
357 soulng::parser::Match match(false);
358 soulng::parser::Match* parentMatch8 = &match;
359 {
360 soulng::parser::Match match(true);
361 soulng::parser::Match* parentMatch9 = &match;
362 {
363 soulng::lexer::Span span = lexer.GetSpan();
364 soulng::parser::Match match = BuildLangServerParser::ServerId(lexer);
365 server.reset(static_cast<soulng::parser::soulng::parser::Value<std::string>*>(match.value));
366 if (match.hit)
367 {
368 *parentMatch9 = match;
369 }
370 else
371 {
372 lexer.ThrowExpectationFailure(span, U"server name");
373 }
374 }
375 *parentMatch8 = match;
376 }
377 *parentMatch4 = match;
378 }
379 *parentMatch3 = match;
380 }
381 if (match.hit)
382 {
383 soulng::parser::Match match(false);
384 soulng::parser::Match* parentMatch10 = &match;
385 {
386 soulng::parser::Match match(true);
387 soulng::parser::Match* parentMatch11 = &match;
388 {
389 soulng::lexer::Span span = lexer.GetSpan();
390 soulng::parser::Match match(false);
391 if (*lexer == PORT)
392 {
393 ++lexer;
394 match.hit = true;
395 }
396 if (match.hit)
397 {
398 *parentMatch11 = match;
399 }
400 else
401 {
402 lexer.ThrowExpectationFailure(span, ToUtf32(GetTokenInfo(PORT)));
403 }
404 }
405 *parentMatch10 = match;
406 }
407 *parentMatch3 = match;
408 }
409 *parentMatch2 = match;
410 }
411 if (match.hit)
412 {
413 soulng::parser::Match match(false);
414 soulng::parser::Match* parentMatch12 = &match;
415 {
416 soulng::parser::Match match = BuildLangServerParser::Port(lexer);
417 port.reset(static_cast<soulng::parser::soulng::parser::Value<int>*>(match.value));
418 *parentMatch12 = match;
419 }
420 *parentMatch2 = match;
421 }
422 *parentMatch1 = match;
423 }
424 if (match.hit)
425 {
426 {
427 #ifdef SOULNG_PARSER_DEBUG_SUPPORT
428
429 #endif // SOULNG_PARSER_DEBUG_SUPPORT
430 return soulng::parser::Match(true, new cmajor::build::AddServerServerCommand(server->value, port->value));
431 }
432 }
433 *parentMatch0 = match;
434 }
435 #ifdef SOULNG_PARSER_DEBUG_SUPPORT
436
437
438
439
440
441 #endif // SOULNG_PARSER_DEBUG_SUPPORT
442 if (!match.hit)
443 {
444 match.value = nullptr;
445 }
446 return match;
447 }
448
449 soulng::parser::Match BuildLangServerParser::RemoveServerSentence(BuildLangLexer& lexer)
450 {
451 #ifdef SOULNG_PARSER_DEBUG_SUPPORT
452
453
454
455
456
457
458
459 #endif // SOULNG_PARSER_DEBUG_SUPPORT
460 std::unique_ptr<soulng::parser::soulng::parser::Value<std::string>>server;
461 soulng::parser::Match match(false);
462 soulng::parser::Match* parentMatch0 = &match;
463 {
464 int64_t pos = lexer.GetPos();
465 soulng::parser::Match match(false);
466 soulng::parser::Match* parentMatch1 = &match;
467 {
468 soulng::parser::Match match(false);
469 soulng::parser::Match* parentMatch2 = &match;
470 {
471 soulng::parser::Match match(false);
472 soulng::parser::Match* parentMatch3 = &match;
473 {
474 soulng::parser::Match match(false);
475 if (*lexer == REMOVE)
476 {
477 ++lexer;
478 match.hit = true;
479 }
480 *parentMatch3 = match;
481 }
482 if (match.hit)
483 {
484 soulng::parser::Match match(false);
485 soulng::parser::Match* parentMatch4 = &match;
486 {
487 soulng::parser::Match match(true);
488 soulng::parser::Match* parentMatch5 = &match;
489 {
490 soulng::lexer::Span span = lexer.GetSpan();
491 soulng::parser::Match match(false);
492 if (*lexer == SERVER)
493 {
494 ++lexer;
495 match.hit = true;
496 }
497 if (match.hit)
498 {
499 *parentMatch5 = match;
500 }
501 else
502 {
503 lexer.ThrowExpectationFailure(span, ToUtf32(GetTokenInfo(SERVER)));
504 }
505 }
506 *parentMatch4 = match;
507 }
508 *parentMatch3 = match;
509 }
510 *parentMatch2 = match;
511 }
512 if (match.hit)
513 {
514 soulng::parser::Match match(false);
515 soulng::parser::Match* parentMatch6 = &match;
516 {
517 soulng::parser::Match match(true);
518 soulng::parser::Match* parentMatch7 = &match;
519 {
520 soulng::lexer::Span span = lexer.GetSpan();
521 soulng::parser::Match match = BuildLangServerParser::ServerId(lexer);
522 server.reset(static_cast<soulng::parser::soulng::parser::Value<std::string>*>(match.value));
523 if (match.hit)
524 {
525 *parentMatch7 = match;
526 }
527 else
528 {
529 lexer.ThrowExpectationFailure(span, U"server name");
530 }
531 }
532 *parentMatch6 = match;
533 }
534 *parentMatch2 = match;
535 }
536 *parentMatch1 = match;
537 }
538 if (match.hit)
539 {
540 {
541 #ifdef SOULNG_PARSER_DEBUG_SUPPORT
542
543 #endif // SOULNG_PARSER_DEBUG_SUPPORT
544 return soulng::parser::Match(true, new cmajor::build::RemoveServerServerCommand(server->value));
545 }
546 }
547 *parentMatch0 = match;
548 }
549 #ifdef SOULNG_PARSER_DEBUG_SUPPORT
550
551
552
553
554
555 #endif // SOULNG_PARSER_DEBUG_SUPPORT
556 if (!match.hit)
557 {
558 match.value = nullptr;
559 }
560 return match;
561 }
562
563 soulng::parser::Match BuildLangServerParser::RunServerSentence(BuildLangLexer& lexer)
564 {
565 #ifdef SOULNG_PARSER_DEBUG_SUPPORT
566
567
568
569
570
571
572
573 #endif // SOULNG_PARSER_DEBUG_SUPPORT
574 std::unique_ptr<soulng::parser::soulng::parser::Value<std::string>>server;
575 soulng::parser::Match match(false);
576 soulng::parser::Match* parentMatch0 = &match;
577 {
578 int64_t pos = lexer.GetPos();
579 soulng::parser::Match match(false);
580 soulng::parser::Match* parentMatch1 = &match;
581 {
582 soulng::parser::Match match(false);
583 soulng::parser::Match* parentMatch2 = &match;
584 {
585 soulng::parser::Match match(false);
586 soulng::parser::Match* parentMatch3 = &match;
587 {
588 soulng::parser::Match match(false);
589 if (*lexer == RUN)
590 {
591 ++lexer;
592 match.hit = true;
593 }
594 *parentMatch3 = match;
595 }
596 if (match.hit)
597 {
598 soulng::parser::Match match(false);
599 soulng::parser::Match* parentMatch4 = &match;
600 {
601 soulng::parser::Match match(false);
602 if (*lexer == SERVER)
603 {
604 ++lexer;
605 match.hit = true;
606 }
607 *parentMatch4 = match;
608 }
609 *parentMatch3 = match;
610 }
611 *parentMatch2 = match;
612 }
613 if (match.hit)
614 {
615 soulng::parser::Match match(false);
616 soulng::parser::Match* parentMatch5 = &match;
617 {
618 soulng::parser::Match match(true);
619 soulng::parser::Match* parentMatch6 = &match;
620 {
621 soulng::lexer::Span span = lexer.GetSpan();
622 soulng::parser::Match match = BuildLangServerParser::ServerId(lexer);
623 server.reset(static_cast<soulng::parser::soulng::parser::Value<std::string>*>(match.value));
624 if (match.hit)
625 {
626 *parentMatch6 = match;
627 }
628 else
629 {
630 lexer.ThrowExpectationFailure(span, U"server name");
631 }
632 }
633 *parentMatch5 = match;
634 }
635 *parentMatch2 = match;
636 }
637 *parentMatch1 = match;
638 }
639 if (match.hit)
640 {
641 {
642 #ifdef SOULNG_PARSER_DEBUG_SUPPORT
643
644 #endif // SOULNG_PARSER_DEBUG_SUPPORT
645 return soulng::parser::Match(true, new cmajor::build::RunServerServerCommand(server->value));
646 }
647 }
648 *parentMatch0 = match;
649 }
650 #ifdef SOULNG_PARSER_DEBUG_SUPPORT
651
652
653
654
655
656 #endif // SOULNG_PARSER_DEBUG_SUPPORT
657 if (!match.hit)
658 {
659 match.value = nullptr;
660 }
661 return match;
662 }
663
664 soulng::parser::Match BuildLangServerParser::ShowConfigurationSentence(BuildLangLexer& lexer)
665 {
666 #ifdef SOULNG_PARSER_DEBUG_SUPPORT
667
668
669
670
671
672
673
674 #endif // SOULNG_PARSER_DEBUG_SUPPORT
675 soulng::parser::Match match(false);
676 soulng::parser::Match* parentMatch0 = &match;
677 {
678 int64_t pos = lexer.GetPos();
679 soulng::parser::Match match(false);
680 soulng::parser::Match* parentMatch1 = &match;
681 {
682 soulng::parser::Match match(false);
683 soulng::parser::Match* parentMatch2 = &match;
684 {
685 soulng::parser::Match match(false);
686 if (*lexer == SHOW)
687 {
688 ++lexer;
689 match.hit = true;
690 }
691 *parentMatch2 = match;
692 }
693 if (match.hit)
694 {
695 soulng::parser::Match match(false);
696 soulng::parser::Match* parentMatch3 = &match;
697 {
698 soulng::parser::Match match(false);
699 if (*lexer == CONFIGURATION)
700 {
701 ++lexer;
702 match.hit = true;
703 }
704 *parentMatch3 = match;
705 }
706 *parentMatch2 = match;
707 }
708 *parentMatch1 = match;
709 }
710 if (match.hit)
711 {
712 {
713 #ifdef SOULNG_PARSER_DEBUG_SUPPORT
714
715 #endif // SOULNG_PARSER_DEBUG_SUPPORT
716 return soulng::parser::Match(true, new cmajor::build::ShowConfigurationServerCommand());
717 }
718 }
719 *parentMatch0 = match;
720 }
721 #ifdef SOULNG_PARSER_DEBUG_SUPPORT
722
723
724
725
726
727 #endif // SOULNG_PARSER_DEBUG_SUPPORT
728 if (!match.hit)
729 {
730 match.value = nullptr;
731 }
732 return match;
733 }
734
735 soulng::parser::Match BuildLangServerParser::ServerId(BuildLangLexer& lexer)
736 {
737 #ifdef SOULNG_PARSER_DEBUG_SUPPORT
738
739
740
741
742
743
744
745 #endif // SOULNG_PARSER_DEBUG_SUPPORT
746 soulng::parser::Match match(false);
747 soulng::parser::Match* parentMatch0 = &match;
748 {
749 int64_t pos = lexer.GetPos();
750 soulng::parser::Match match(false);
751 if (*lexer == ID)
752 {
753 ++lexer;
754 match.hit = true;
755 }
756 if (match.hit)
757 {
758 {
759 #ifdef SOULNG_PARSER_DEBUG_SUPPORT
760
761 #endif // SOULNG_PARSER_DEBUG_SUPPORT
762 return soulng::parser::Match(true, new soulng::parser::Value<std::string>(ToUtf8(lexer.GetToken(pos).match.ToString())));
763 }
764 }
765 *parentMatch0 = match;
766 }
767 #ifdef SOULNG_PARSER_DEBUG_SUPPORT
768
769
770
771
772
773 #endif // SOULNG_PARSER_DEBUG_SUPPORT
774 if (!match.hit)
775 {
776 match.value = nullptr;
777 }
778 return match;
779 }
780
781 soulng::parser::Match BuildLangServerParser::Port(BuildLangLexer& lexer)
782 {
783 #ifdef SOULNG_PARSER_DEBUG_SUPPORT
784
785
786
787
788
789
790
791 #endif // SOULNG_PARSER_DEBUG_SUPPORT
792 std::string portStr = std::string();
793 soulng::parser::Match match(false);
794 soulng::parser::Match* parentMatch0 = &match;
795 {
796 int64_t pos = lexer.GetPos();
797 soulng::parser::Match match(false);
798 if (*lexer == INTEGER)
799 {
800 ++lexer;
801 match.hit = true;
802 }
803 if (match.hit)
804 {
805 portStr = ToUtf8(lexer.GetToken(pos).match.ToString());
806 {
807 #ifdef SOULNG_PARSER_DEBUG_SUPPORT
808
809 #endif // SOULNG_PARSER_DEBUG_SUPPORT
810 return soulng::parser::Match(true, new soulng::parser::Value<int>(std::stoi(portStr)));
811 }
812 }
813 *parentMatch0 = match;
814 }
815 #ifdef SOULNG_PARSER_DEBUG_SUPPORT
816
817
818
819
820
821 #endif // SOULNG_PARSER_DEBUG_SUPPORT
822 if (!match.hit)
823 {
824 match.value = nullptr;
825 }
826 return match;
827 }