1 using System;
2 using System.Collections;
3 using System.Lex;
4 using System.Parsing;
5 using RegExTokens;
6
7 public static class LexRegExParser
8 {
9 public static UniquePtr<soulcm.scm2html.RegExpression> Parse(RegExLexer& lexer, soulcm.scm2html.LexerContext* lexerContext)
10 {
11 UniquePtr<soulcm.scm2html.RegExpression> value;
12 #if (DEBUG)
13 if (lexer.Log() != null)
14 {
15 lexer.Log()->WriteBeginRule(u"parse");
16 lexer.Log()->IncIndent();
17 }
18 #endif
19 ++lexer;
20 System.Lex.Span span = lexer.GetSpan();
21 Match match = RegularExpression(lexer, lexerContext);
22 value.Reset(cast<soulcm.scm2html.RegExpression*>(match.value));
23 #if (DEBUG)
24 if (lexer.Log() != null)
25 {
26 lexer.Log()->DecIndent();
27 lexer.Log()->WriteEndRule(u"parse");
28 }
29 #endif
30 if (match.hit)
31 {
32 if (*lexer == System.Lex.END_TOKEN)
33 {
34 return value;
35 }
36 else
37 {
38 lexer.ThrowExpectationFailure(lexer.GetSpan(), GetEndTokenInfo());
39 }
40 }
41 else
42 {
43 lexer.ThrowExpectationFailure(span, u"regular expression");
44 }
45 return value;
46 }
47 public static Match RegularExpression(RegExLexer& lexer, soulcm.scm2html.LexerContext* lexerContext)
48 {
49 #if (DEBUG)
50 Span debugSpan;
51 bool writeToLog = lexer.Log() != null;
52 if (writeToLog)
53 {
54 debugSpan = lexer.GetSpan();
55 System.Lex.WriteBeginRuleToLog(lexer, u"RegularExpression");
56 }
57 #endif
58 UniquePtr<soulcm.scm2html.RegExpression> alternative;
59 Match match(false);
60 Match* parentMatch0 = &match;
61 {
62 long pos = lexer.GetPos();
63 Match match = LexRegExParser.Alternative(lexer, lexerContext);
64 alternative.Reset(cast<soulcm.scm2html.RegExpression*>(match.value));
65 if (match.hit)
66 {
67 {
68 #if (DEBUG)
69 if (writeToLog) System.Lex.WriteSuccessToLog(lexer, debugSpan, u"RegularExpression");
70 #endif
71 return Match(true, alternative.Release());
72 }
73 }
74 *parentMatch0 = match;
75 }
76 #if (DEBUG)
77 if (writeToLog)
78 {
79 if (match.hit)
80 {
81 System.Lex.WriteSuccessToLog(lexer, debugSpan, u"RegularExpression");
82 }
83 else
84 {
85 System.Lex.WriteFailureToLog(lexer, u"RegularExpression");
86 }
87 }
88 #endif
89 if (!match.hit)
90 {
91 match.value = null;
92 }
93 return match;
94 }
95 public static Match Alternative(RegExLexer& lexer, soulcm.scm2html.LexerContext* lexerContext)
96 {
97 #if (DEBUG)
98 Span debugSpan;
99 bool writeToLog = lexer.Log() != null;
100 if (writeToLog)
101 {
102 debugSpan = lexer.GetSpan();
103 System.Lex.WriteBeginRuleToLog(lexer, u"Alternative");
104 }
105 #endif
106 UniquePtr<soulcm.scm2html.RegExpression> value;
107 UniquePtr<soulcm.scm2html.RegExpression> left;
108 UniquePtr<soulcm.scm2html.RegExpression> right;
109 Match match(false);
110 Match* parentMatch0 = &match;
111 {
112 long pos = lexer.GetPos();
113 Match match(false);
114 Match* parentMatch1 = &match;
115 {
116 Match match(false);
117 Match* parentMatch2 = &match;
118 {
119 Match match(false);
120 Match* parentMatch3 = &match;
121 {
122 Match match(false);
123 Match* parentMatch4 = &match;
124 {
125 long pos = lexer.GetPos();
126 Match match = LexRegExParser.Catenation(lexer, lexerContext);
127 left.Reset(cast<soulcm.scm2html.RegExpression*>(match.value));
128 if (match.hit)
129 {
130 value.Reset(left.Release());
131 }
132 *parentMatch4 = match;
133 }
134 *parentMatch3 = match;
135 }
136 if (match.hit)
137 {
138 Match match(false);
139 Match* parentMatch5 = &match;
140 {
141 Match match(true);
142 Match* parentMatch6 = &match;
143 {
144 while (true)
145 {
146 long save = lexer.GetPos();
147 {
148 Match match(false);
149 Match* parentMatch7 = &match;
150 {
151 Match match(false);
152 Match* parentMatch8 = &match;
153 {
154 Match match(false);
155 if (*lexer == ALT)
156 {
157 ++lexer;
158 match.hit = true;
159 }
160 *parentMatch8 = match;
161 }
162 if (match.hit)
163 {
164 Match match(false);
165 Match* parentMatch9 = &match;
166 {
167 Match match(false);
168 Match* parentMatch10 = &match;
169 {
170 long pos = lexer.GetPos();
171 Match match(true);
172 Match* parentMatch11 = &match;
173 {
174 System.Lex.Span span = lexer.GetSpan();
175 Match match = LexRegExParser.Catenation(lexer, lexerContext);
176 right.Reset(cast<soulcm.scm2html.RegExpression*>(match.value));
177 if (match.hit)
178 {
179 *parentMatch11 = match;
180 }
181 else
182 {
183 lexer.ThrowExpectationFailure(span, u"catenation");
184 }
185 }
186 if (match.hit)
187 {
188 value.Reset(new soulcm.scm2html.Alt(value.Release(), right.Release()));
189 }
190 *parentMatch10 = match;
191 }
192 *parentMatch9 = match;
193 }
194 *parentMatch8 = match;
195 }
196 *parentMatch7 = match;
197 }
198 if (match.hit)
199 {
200 *parentMatch6 = match;
201 }
202 else
203 {
204 lexer.SetPos(save);
205 break;
206 }
207 }
208 }
209 }
210 *parentMatch5 = match;
211 }
212 *parentMatch3 = match;
213 }
214 *parentMatch2 = match;
215 }
216 *parentMatch1 = match;
217 }
218 if (match.hit)
219 {
220 {
221 #if (DEBUG)
222 if (writeToLog) System.Lex.WriteSuccessToLog(lexer, debugSpan, u"Alternative");
223 #endif
224 return Match(true, value.Release());
225 }
226 }
227 *parentMatch0 = match;
228 }
229 #if (DEBUG)
230 if (writeToLog)
231 {
232 if (match.hit)
233 {
234 System.Lex.WriteSuccessToLog(lexer, debugSpan, u"Alternative");
235 }
236 else
237 {
238 System.Lex.WriteFailureToLog(lexer, u"Alternative");
239 }
240 }
241 #endif
242 if (!match.hit)
243 {
244 match.value = null;
245 }
246 return match;
247 }
248 public static Match Catenation(RegExLexer& lexer, soulcm.scm2html.LexerContext* lexerContext)
249 {
250 #if (DEBUG)
251 Span debugSpan;
252 bool writeToLog = lexer.Log() != null;
253 if (writeToLog)
254 {
255 debugSpan = lexer.GetSpan();
256 System.Lex.WriteBeginRuleToLog(lexer, u"Catenation");
257 }
258 #endif
259 UniquePtr<soulcm.scm2html.RegExpression> value;
260 UniquePtr<soulcm.scm2html.RegExpression> left;
261 UniquePtr<soulcm.scm2html.RegExpression> right;
262 Match match(false);
263 Match* parentMatch0 = &match;
264 {
265 long pos = lexer.GetPos();
266 Match match(false);
267 Match* parentMatch1 = &match;
268 {
269 Match match(false);
270 Match* parentMatch2 = &match;
271 {
272 Match match(false);
273 Match* parentMatch3 = &match;
274 {
275 Match match(false);
276 Match* parentMatch4 = &match;
277 {
278 long pos = lexer.GetPos();
279 Match match = LexRegExParser.Repetition(lexer, lexerContext);
280 left.Reset(cast<soulcm.scm2html.RegExpression*>(match.value));
281 if (match.hit)
282 {
283 value.Reset(left.Release());
284 }
285 *parentMatch4 = match;
286 }
287 *parentMatch3 = match;
288 }
289 if (match.hit)
290 {
291 Match match(false);
292 Match* parentMatch5 = &match;
293 {
294 Match match(true);
295 Match* parentMatch6 = &match;
296 {
297 while (true)
298 {
299 long save = lexer.GetPos();
300 {
301 Match match(false);
302 Match* parentMatch7 = &match;
303 {
304 Match match(false);
305 Match* parentMatch8 = &match;
306 {
307 long pos = lexer.GetPos();
308 Match match = LexRegExParser.Repetition(lexer, lexerContext);
309 right.Reset(cast<soulcm.scm2html.RegExpression*>(match.value));
310 if (match.hit)
311 {
312 value.Reset(new soulcm.scm2html.Cat(value.Release(), right.Release()));
313 }
314 *parentMatch8 = match;
315 }
316 *parentMatch7 = match;
317 }
318 if (match.hit)
319 {
320 *parentMatch6 = match;
321 }
322 else
323 {
324 lexer.SetPos(save);
325 break;
326 }
327 }
328 }
329 }
330 *parentMatch5 = match;
331 }
332 *parentMatch3 = match;
333 }
334 *parentMatch2 = match;
335 }
336 *parentMatch1 = match;
337 }
338 if (match.hit)
339 {
340 {
341 #if (DEBUG)
342 if (writeToLog) System.Lex.WriteSuccessToLog(lexer, debugSpan, u"Catenation");
343 #endif
344 return Match(true, value.Release());
345 }
346 }
347 *parentMatch0 = match;
348 }
349 #if (DEBUG)
350 if (writeToLog)
351 {
352 if (match.hit)
353 {
354 System.Lex.WriteSuccessToLog(lexer, debugSpan, u"Catenation");
355 }
356 else
357 {
358 System.Lex.WriteFailureToLog(lexer, u"Catenation");
359 }
360 }
361 #endif
362 if (!match.hit)
363 {
364 match.value = null;
365 }
366 return match;
367 }
368 public static Match Repetition(RegExLexer& lexer, soulcm.scm2html.LexerContext* lexerContext)
369 {
370 #if (DEBUG)
371 Span debugSpan;
372 bool writeToLog = lexer.Log() != null;
373 if (writeToLog)
374 {
375 debugSpan = lexer.GetSpan();
376 System.Lex.WriteBeginRuleToLog(lexer, u"Repetition");
377 }
378 #endif
379 UniquePtr<soulcm.scm2html.RegExpression> value;
380 UniquePtr<soulcm.scm2html.RegExpression> left;
381 Match match(false);
382 Match* parentMatch0 = &match;
383 {
384 long pos = lexer.GetPos();
385 Match match(false);
386 Match* parentMatch1 = &match;
387 {
388 Match match(false);
389 Match* parentMatch2 = &match;
390 {
391 Match match(false);
392 Match* parentMatch3 = &match;
393 {
394 long pos = lexer.GetPos();
395 Match match = LexRegExParser.Primary(lexer, lexerContext);
396 left.Reset(cast<soulcm.scm2html.RegExpression*>(match.value));
397 if (match.hit)
398 {
399 value.Reset(left.Release());
400 }
401 *parentMatch3 = match;
402 }
403 *parentMatch2 = match;
404 }
405 if (match.hit)
406 {
407 Match match(false);
408 Match* parentMatch4 = &match;
409 {
410 Match match(true);
411 long save = lexer.GetPos();
412 Match* parentMatch5 = &match;
413 {
414 Match match(false);
415 Match* parentMatch6 = &match;
416 {
417 Match match(false);
418 Match* parentMatch7 = &match;
419 {
420 long save = lexer.GetPos();
421 Match match(false);
422 Match* parentMatch8 = &match;
423 {
424 long save = lexer.GetPos();
425 Match match(false);
426 Match* parentMatch9 = &match;
427 {
428 long pos = lexer.GetPos();
429 Match match(false);
430 if (*lexer == STAR)
431 {
432 ++lexer;
433 match.hit = true;
434 }
435 if (match.hit)
436 {
437 value.Reset(new soulcm.scm2html.Kleene(value.Release()));
438 }
439 *parentMatch9 = match;
440 }
441 *parentMatch8 = match;
442 if (!match.hit)
443 {
444 Match match(false);
445 Match* parentMatch10 = &match;
446 lexer.SetPos(save);
447 {
448 Match match(false);
449 Match* parentMatch11 = &match;
450 {
451 long pos = lexer.GetPos();
452 Match match(false);
453 if (*lexer == PLUS)
454 {
455 ++lexer;
456 match.hit = true;
457 }
458 if (match.hit)
459 {
460 value.Reset(new soulcm.scm2html.Pos(value.Release()));
461 }
462 *parentMatch11 = match;
463 }
464 *parentMatch10 = match;
465 }
466 *parentMatch8 = match;
467 }
468 }
469 *parentMatch7 = match;
470 if (!match.hit)
471 {
472 Match match(false);
473 Match* parentMatch12 = &match;
474 lexer.SetPos(save);
475 {
476 Match match(false);
477 Match* parentMatch13 = &match;
478 {
479 long pos = lexer.GetPos();
480 Match match(false);
481 if (*lexer == QUEST)
482 {
483 ++lexer;
484 match.hit = true;
485 }
486 if (match.hit)
487 {
488 value.Reset(new soulcm.scm2html.Opt(value.Release()));
489 }
490 *parentMatch13 = match;
491 }
492 *parentMatch12 = match;
493 }
494 *parentMatch7 = match;
495 }
496 }
497 *parentMatch6 = match;
498 }
499 if (match.hit)
500 {
501 *parentMatch5 = match;
502 }
503 else
504 {
505 lexer.SetPos(save);
506 }
507 }
508 *parentMatch4 = match;
509 }
510 *parentMatch2 = match;
511 }
512 *parentMatch1 = match;
513 }
514 if (match.hit)
515 {
516 {
517 #if (DEBUG)
518 if (writeToLog) System.Lex.WriteSuccessToLog(lexer, debugSpan, u"Repetition");
519 #endif
520 return Match(true, value.Release());
521 }
522 }
523 *parentMatch0 = match;
524 }
525 #if (DEBUG)
526 if (writeToLog)
527 {
528 if (match.hit)
529 {
530 System.Lex.WriteSuccessToLog(lexer, debugSpan, u"Repetition");
531 }
532 else
533 {
534 System.Lex.WriteFailureToLog(lexer, u"Repetition");
535 }
536 }
537 #endif
538 if (!match.hit)
539 {
540 match.value = null;
541 }
542 return match;
543 }
544 public static Match Primary(RegExLexer& lexer, soulcm.scm2html.LexerContext* lexerContext)
545 {
546 #if (DEBUG)
547 Span debugSpan;
548 bool writeToLog = lexer.Log() != null;
549 if (writeToLog)
550 {
551 debugSpan = lexer.GetSpan();
552 System.Lex.WriteBeginRuleToLog(lexer, u"Primary");
553 }
554 #endif
555 UniquePtr<soulcm.scm2html.RegExpression> value;
556 UniquePtr<soulcm.scm2html.RegExpression> alt;
557 UniquePtr<soulcm.scm2html.Class> cls;
558 UniquePtr<Value<ustring>> ref;
559 Match match(false);
560 Match* parentMatch0 = &match;
561 {
562 long pos = lexer.GetPos();
563 Match match(false);
564 Match* parentMatch1 = &match;
565 {
566 Match match(false);
567 Match* parentMatch2 = &match;
568 {
569 long save = lexer.GetPos();
570 Match match(false);
571 Match* parentMatch3 = &match;
572 {
573 long save = lexer.GetPos();
574 Match match(false);
575 Match* parentMatch4 = &match;
576 {
577 long save = lexer.GetPos();
578 Match match(false);
579 Match* parentMatch5 = &match;
580 {
581 long save = lexer.GetPos();
582 Match match(false);
583 Match* parentMatch6 = &match;
584 {
585 long save = lexer.GetPos();
586 Match match(false);
587 Match* parentMatch7 = &match;
588 {
589 long save = lexer.GetPos();
590 Match match(false);
591 Match* parentMatch8 = &match;
592 {
593 long save = lexer.GetPos();
594 Match match(false);
595 Match* parentMatch9 = &match;
596 {
597 Match match(false);
598 Match* parentMatch10 = &match;
599 {
600 Match match(false);
601 if (*lexer == LPAREN)
602 {
603 ++lexer;
604 match.hit = true;
605 }
606 *parentMatch10 = match;
607 }
608 if (match.hit)
609 {
610 Match match(false);
611 Match* parentMatch11 = &match;
612 {
613 Match match(false);
614 Match* parentMatch12 = &match;
615 {
616 long pos = lexer.GetPos();
617 Match match(true);
618 Match* parentMatch13 = &match;
619 {
620 System.Lex.Span span = lexer.GetSpan();
621 Match match = LexRegExParser.Alternative(lexer, lexerContext);
622 alt.Reset(cast<soulcm.scm2html.RegExpression*>(match.value));
623 if (match.hit)
624 {
625 *parentMatch13 = match;
626 }
627 else
628 {
629 lexer.ThrowExpectationFailure(span, u"alternative");
630 }
631 }
632 if (match.hit)
633 {
634 value.Reset(new soulcm.scm2html.ParenExpr(alt.Release()));
635 }
636 *parentMatch12 = match;
637 }
638 *parentMatch11 = match;
639 }
640 *parentMatch10 = match;
641 }
642 *parentMatch9 = match;
643 }
644 if (match.hit)
645 {
646 Match match(false);
647 Match* parentMatch14 = &match;
648 {
649 Match match(true);
650 Match* parentMatch15 = &match;
651 {
652 System.Lex.Span span = lexer.GetSpan();
653 Match match(false);
654 if (*lexer == RPAREN)
655 {
656 ++lexer;
657 match.hit = true;
658 }
659 if (match.hit)
660 {
661 *parentMatch15 = match;
662 }
663 else
664 {
665 lexer.ThrowExpectationFailure(span, GetTokenName(RPAREN));
666 }
667 }
668 *parentMatch14 = match;
669 }
670 *parentMatch9 = match;
671 }
672 *parentMatch8 = match;
673 if (!match.hit)
674 {
675 Match match(false);
676 Match* parentMatch16 = &match;
677 lexer.SetPos(save);
678 {
679 Match match(false);
680 Match* parentMatch17 = &match;
681 {
682 long pos = lexer.GetPos();
683 Match match(false);
684 if (*lexer == ESCAPE)
685 {
686 ++lexer;
687 match.hit = true;
688 }
689 if (match.hit)
690 {
691 value.Reset(new soulcm.scm2html.SymbolExpr(lexerContext->MakeChar(soulcm.scm2html.MakeEscapeValue(lexer.FileName(), lexer.GetToken(pos)))));
692 }
693 *parentMatch17 = match;
694 }
695 *parentMatch16 = match;
696 }
697 *parentMatch8 = match;
698 }
699 }
700 *parentMatch7 = match;
701 if (!match.hit)
702 {
703 Match match(false);
704 Match* parentMatch18 = &match;
705 lexer.SetPos(save);
706 {
707 Match match(false);
708 Match* parentMatch19 = &match;
709 {
710 long pos = lexer.GetPos();
711 Match match(false);
712 if (*lexer == INVERSE)
713 {
714 ++lexer;
715 match.hit = true;
716 }
717 if (match.hit)
718 {
719 value.Reset(new soulcm.scm2html.SymbolExpr(lexerContext->MakeChar('^')));
720 }
721 *parentMatch19 = match;
722 }
723 *parentMatch18 = match;
724 }
725 *parentMatch7 = match;
726 }
727 }
728 *parentMatch6 = match;
729 if (!match.hit)
730 {
731 Match match(false);
732 Match* parentMatch20 = &match;
733 lexer.SetPos(save);
734 {
735 Match match(false);
736 Match* parentMatch21 = &match;
737 {
738 long pos = lexer.GetPos();
739 Match match(false);
740 if (*lexer == MINUS)
741 {
742 ++lexer;
743 match.hit = true;
744 }
745 if (match.hit)
746 {
747 value.Reset(new soulcm.scm2html.SymbolExpr(lexerContext->MakeChar('-')));
748 }
749 *parentMatch21 = match;
750 }
751 *parentMatch20 = match;
752 }
753 *parentMatch6 = match;
754 }
755 }
756 *parentMatch5 = match;
757 if (!match.hit)
758 {
759 Match match(false);
760 Match* parentMatch22 = &match;
761 lexer.SetPos(save);
762 {
763 Match match(false);
764 Match* parentMatch23 = &match;
765 {
766 long pos = lexer.GetPos();
767 Span span = lexer.GetSpan();
768 Match match(false);
769 if (*lexer == CHAR)
770 {
771 ++lexer;
772 match.hit = true;
773 }
774 if (match.hit)
775 {
776 ustring match = lexer.GetMatch(span);
777 value.Reset(new soulcm.scm2html.SymbolExpr(lexerContext->MakeChar(match[0])));
778 }
779 *parentMatch23 = match;
780 }
781 *parentMatch22 = match;
782 }
783 *parentMatch5 = match;
784 }
785 }
786 *parentMatch4 = match;
787 if (!match.hit)
788 {
789 Match match(false);
790 Match* parentMatch24 = &match;
791 lexer.SetPos(save);
792 {
793 Match match(false);
794 Match* parentMatch25 = &match;
795 {
796 long pos = lexer.GetPos();
797 Match match(false);
798 if (*lexer == DOT)
799 {
800 ++lexer;
801 match.hit = true;
802 }
803 if (match.hit)
804 {
805 value.Reset(new soulcm.scm2html.SymbolExpr(lexerContext->MakeAny()));
806 }
807 *parentMatch25 = match;
808 }
809 *parentMatch24 = match;
810 }
811 *parentMatch4 = match;
812 }
813 }
814 *parentMatch3 = match;
815 if (!match.hit)
816 {
817 Match match(false);
818 Match* parentMatch26 = &match;
819 lexer.SetPos(save);
820 {
821 Match match(false);
822 Match* parentMatch27 = &match;
823 {
824 long pos = lexer.GetPos();
825 Match match = LexRegExParser.Class(lexer, lexerContext);
826 cls.Reset(cast<soulcm.scm2html.Class*>(match.value));
827 if (match.hit)
828 {
829 value.Reset(new soulcm.scm2html.SymbolExpr(cls.Release()));
830 }
831 *parentMatch27 = match;
832 }
833 *parentMatch26 = match;
834 }
835 *parentMatch3 = match;
836 }
837 }
838 *parentMatch2 = match;
839 if (!match.hit)
840 {
841 Match match(false);
842 Match* parentMatch28 = &match;
843 lexer.SetPos(save);
844 {
845 Match match(false);
846 Match* parentMatch29 = &match;
847 {
848 long pos = lexer.GetPos();
849 Match match = LexRegExParser.ExpressionReference(lexer);
850 ref.Reset(cast<Value<ustring>*>(match.value));
851 if (match.hit)
852 {
853 value.Reset(new soulcm.scm2html.RefExpr(ref->value));
854 }
855 *parentMatch29 = match;
856 }
857 *parentMatch28 = match;
858 }
859 *parentMatch2 = match;
860 }
861 }
862 *parentMatch1 = match;
863 }
864 if (match.hit)
865 {
866 {
867 #if (DEBUG)
868 if (writeToLog) System.Lex.WriteSuccessToLog(lexer, debugSpan, u"Primary");
869 #endif
870 return Match(true, value.Release());
871 }
872 }
873 *parentMatch0 = match;
874 }
875 #if (DEBUG)
876 if (writeToLog)
877 {
878 if (match.hit)
879 {
880 System.Lex.WriteSuccessToLog(lexer, debugSpan, u"Primary");
881 }
882 else
883 {
884 System.Lex.WriteFailureToLog(lexer, u"Primary");
885 }
886 }
887 #endif
888 if (!match.hit)
889 {
890 match.value = null;
891 }
892 return match;
893 }
894 public static Match Class(RegExLexer& lexer, soulcm.scm2html.LexerContext* lexerContext)
895 {
896 #if (DEBUG)
897 Span debugSpan;
898 bool writeToLog = lexer.Log() != null;
899 if (writeToLog)
900 {
901 debugSpan = lexer.GetSpan();
902 System.Lex.WriteBeginRuleToLog(lexer, u"Class");
903 }
904 #endif
905 soulcm.scm2html.Class* cls;
906 UniquePtr<soulcm.scm2html.Symbol> r;
907 Match match(false);
908 Match* parentMatch0 = &match;
909 {
910 long pos = lexer.GetPos();
911 Match match(false);
912 Match* parentMatch1 = &match;
913 {
914 Match match(false);
915 Match* parentMatch2 = &match;
916 {
917 Match match(false);
918 Match* parentMatch3 = &match;
919 {
920 Match match(false);
921 Match* parentMatch4 = &match;
922 {
923 long pos = lexer.GetPos();
924 Match match(false);
925 if (*lexer == LBRACKET)
926 {
927 ++lexer;
928 match.hit = true;
929 }
930 if (match.hit)
931 {
932 cls = lexerContext->MakeClass();
933 }
934 *parentMatch4 = match;
935 }
936 *parentMatch3 = match;
937 }
938 if (match.hit)
939 {
940 Match match(false);
941 Match* parentMatch5 = &match;
942 {
943 Match match(false);
944 Match* parentMatch6 = &match;
945 {
946 Match match(false);
947 Match* parentMatch7 = &match;
948 {
949 Match match(true);
950 long save = lexer.GetPos();
951 Match* parentMatch8 = &match;
952 {
953 Match match(false);
954 Match* parentMatch9 = &match;
955 {
956 Match match(false);
957 Match* parentMatch10 = &match;
958 {
959 long pos = lexer.GetPos();
960 Match match(false);
961 if (*lexer == INVERSE)
962 {
963 ++lexer;
964 match.hit = true;
965 }
966 if (match.hit)
967 {
968 cls->SetInverse();
969 }
970 *parentMatch10 = match;
971 }
972 *parentMatch9 = match;
973 }
974 if (match.hit)
975 {
976 *parentMatch8 = match;
977 }
978 else
979 {
980 lexer.SetPos(save);
981 }
982 }
983 *parentMatch7 = match;
984 }
985 if (match.hit)
986 {
987 Match match(false);
988 Match* parentMatch11 = &match;
989 {
990 Match match(true);
991 Match* parentMatch12 = &match;
992 {
993 while (true)
994 {
995 long save = lexer.GetPos();
996 {
997 Match match(false);
998 Match* parentMatch13 = &match;
999 {
1000 Match match(false);
1001 Match* parentMatch14 = &match;
1002 {
1003 long pos = lexer.GetPos();
1004 Match match = LexRegExParser.Range(lexer, lexerContext);
1005 r.Reset(cast<soulcm.scm2html.Symbol*>(match.value));
1006 if (match.hit)
1007 {
1008 cls->AddSymbol(r.Release());
1009 }
1010 *parentMatch14 = match;
1011 }
1012 *parentMatch13 = match;
1013 }
1014 if (match.hit)
1015 {
1016 *parentMatch12 = match;
1017 }
1018 else
1019 {
1020 lexer.SetPos(save);
1021 break;
1022 }
1023 }
1024 }
1025 }
1026 *parentMatch11 = match;
1027 }
1028 *parentMatch7 = match;
1029 }
1030 *parentMatch6 = match;
1031 }
1032 *parentMatch5 = match;
1033 }
1034 *parentMatch3 = match;
1035 }
1036 *parentMatch2 = match;
1037 }
1038 if (match.hit)
1039 {
1040 Match match(false);
1041 Match* parentMatch15 = &match;
1042 {
1043 Match match(true);
1044 Match* parentMatch16 = &match;
1045 {
1046 System.Lex.Span span = lexer.GetSpan();
1047 Match match(false);
1048 if (*lexer == RBRACKET)
1049 {
1050 ++lexer;
1051 match.hit = true;
1052 }
1053 if (match.hit)
1054 {
1055 *parentMatch16 = match;
1056 }
1057 else
1058 {
1059 lexer.ThrowExpectationFailure(span, GetTokenName(RBRACKET));
1060 }
1061 }
1062 *parentMatch15 = match;
1063 }
1064 *parentMatch2 = match;
1065 }
1066 *parentMatch1 = match;
1067 }
1068 if (match.hit)
1069 {
1070 {
1071 #if (DEBUG)
1072 if (writeToLog) System.Lex.WriteSuccessToLog(lexer, debugSpan, u"Class");
1073 #endif
1074 return Match(true, cls);
1075 }
1076 }
1077 *parentMatch0 = match;
1078 }
1079 #if (DEBUG)
1080 if (writeToLog)
1081 {
1082 if (match.hit)
1083 {
1084 System.Lex.WriteSuccessToLog(lexer, debugSpan, u"Class");
1085 }
1086 else
1087 {
1088 System.Lex.WriteFailureToLog(lexer, u"Class");
1089 }
1090 }
1091 #endif
1092 if (!match.hit)
1093 {
1094 match.value = null;
1095 }
1096 return match;
1097 }
1098 public static Match Range(RegExLexer& lexer, soulcm.scm2html.LexerContext* lexerContext)
1099 {
1100 #if (DEBUG)
1101 Span debugSpan;
1102 bool writeToLog = lexer.Log() != null;
1103 if (writeToLog)
1104 {
1105 debugSpan = lexer.GetSpan();
1106 System.Lex.WriteBeginRuleToLog(lexer, u"Range");
1107 }
1108 #endif
1109 soulcm.scm2html.Symbol* symbol;
1110 UniquePtr<Value<uchar>> s;
1111 UniquePtr<Value<uchar>> e;
1112 Match match(false);
1113 Match* parentMatch0 = &match;
1114 {
1115 long pos = lexer.GetPos();
1116 Match match(false);
1117 Match* parentMatch1 = &match;
1118 {
1119 Match match(false);
1120 Match* parentMatch2 = &match;
1121 {
1122 Match match = LexRegExParser.Char(lexer);
1123 s.Reset(cast<Value<uchar>*>(match.value));
1124 *parentMatch2 = match;
1125 }
1126 if (match.hit)
1127 {
1128 Match match(false);
1129 Match* parentMatch3 = &match;
1130 {
1131 Match match(false);
1132 Match* parentMatch4 = &match;
1133 {
1134 Match match(false);
1135 Match* parentMatch5 = &match;
1136 {
1137 long save = lexer.GetPos();
1138 Match match(false);
1139 Match* parentMatch6 = &match;
1140 {
1141 Match match(false);
1142 if (*lexer == MINUS)
1143 {
1144 ++lexer;
1145 match.hit = true;
1146 }
1147 *parentMatch6 = match;
1148 }
1149 if (match.hit)
1150 {
1151 Match match(false);
1152 Match* parentMatch7 = &match;
1153 {
1154 Match match(false);
1155 Match* parentMatch8 = &match;
1156 {
1157 long pos = lexer.GetPos();
1158 Match match = LexRegExParser.Char(lexer);
1159 e.Reset(cast<Value<uchar>*>(match.value));
1160 if (match.hit)
1161 {
1162 symbol = lexerContext->MakeRange(s->value, e->value);
1163 }
1164 *parentMatch8 = match;
1165 }
1166 *parentMatch7 = match;
1167 }
1168 *parentMatch6 = match;
1169 }
1170 *parentMatch5 = match;
1171 if (!match.hit)
1172 {
1173 Match match(false);
1174 Match* parentMatch9 = &match;
1175 lexer.SetPos(save);
1176 {
1177 Match match(false);
1178 Match* parentMatch10 = &match;
1179 {
1180 long pos = lexer.GetPos();
1181 Match match(true);
1182 if (match.hit)
1183 {
1184 symbol = lexerContext->MakeChar(s->value);
1185 }
1186 *parentMatch10 = match;
1187 }
1188 *parentMatch9 = match;
1189 }
1190 *parentMatch5 = match;
1191 }
1192 }
1193 *parentMatch4 = match;
1194 }
1195 *parentMatch3 = match;
1196 }
1197 *parentMatch2 = match;
1198 }
1199 *parentMatch1 = match;
1200 }
1201 if (match.hit)
1202 {
1203 {
1204 #if (DEBUG)
1205 if (writeToLog) System.Lex.WriteSuccessToLog(lexer, debugSpan, u"Range");
1206 #endif
1207 return Match(true, symbol);
1208 }
1209 }
1210 *parentMatch0 = match;
1211 }
1212 #if (DEBUG)
1213 if (writeToLog)
1214 {
1215 if (match.hit)
1216 {
1217 System.Lex.WriteSuccessToLog(lexer, debugSpan, u"Range");
1218 }
1219 else
1220 {
1221 System.Lex.WriteFailureToLog(lexer, u"Range");
1222 }
1223 }
1224 #endif
1225 if (!match.hit)
1226 {
1227 match.value = null;
1228 }
1229 return match;
1230 }
1231 public static Match Char(RegExLexer& lexer)
1232 {
1233 #if (DEBUG)
1234 Span debugSpan;
1235 bool writeToLog = lexer.Log() != null;
1236 if (writeToLog)
1237 {
1238 debugSpan = lexer.GetSpan();
1239 System.Lex.WriteBeginRuleToLog(lexer, u"Char");
1240 }
1241 #endif
1242 Match match(false);
1243 long pos = lexer.GetPos();
1244 Span span = lexer.GetSpan();
1245 switch (*lexer)
1246 {
1247 case LPAREN:
1248 {
1249 ++lexer;
1250 {
1251 #if (DEBUG)
1252 if (writeToLog) System.Lex.WriteSuccessToLog(lexer, debugSpan, u"Char");
1253 #endif
1254 return Match(true, new Value<uchar>('('));
1255 }
1256 break;
1257 }
1258 case RPAREN:
1259 {
1260 ++lexer;
1261 {
1262 #if (DEBUG)
1263 if (writeToLog) System.Lex.WriteSuccessToLog(lexer, debugSpan, u"Char");
1264 #endif
1265 return Match(true, new Value<uchar>(')'));
1266 }
1267 break;
1268 }
1269 case LBRACKET:
1270 {
1271 ++lexer;
1272 {
1273 #if (DEBUG)
1274 if (writeToLog) System.Lex.WriteSuccessToLog(lexer, debugSpan, u"Char");
1275 #endif
1276 return Match(true, new Value<uchar>('['));
1277 }
1278 break;
1279 }
1280 case LBRACE:
1281 {
1282 ++lexer;
1283 {
1284 #if (DEBUG)
1285 if (writeToLog) System.Lex.WriteSuccessToLog(lexer, debugSpan, u"Char");
1286 #endif
1287 return Match(true, new Value<uchar>('{'));
1288 }
1289 break;
1290 }
1291 case RBRACE:
1292 {
1293 ++lexer;
1294 {
1295 #if (DEBUG)
1296 if (writeToLog) System.Lex.WriteSuccessToLog(lexer, debugSpan, u"Char");
1297 #endif
1298 return Match(true, new Value<uchar>('}'));
1299 }
1300 break;
1301 }
1302 case ALT:
1303 {
1304 ++lexer;
1305 {
1306 #if (DEBUG)
1307 if (writeToLog) System.Lex.WriteSuccessToLog(lexer, debugSpan, u"Char");
1308 #endif
1309 return Match(true, new Value<uchar>('|'));
1310 }
1311 break;
1312 }
1313 case STAR:
1314 {
1315 ++lexer;
1316 {
1317 #if (DEBUG)
1318 if (writeToLog) System.Lex.WriteSuccessToLog(lexer, debugSpan, u"Char");
1319 #endif
1320 return Match(true, new Value<uchar>('*'));
1321 }
1322 break;
1323 }
1324 case PLUS:
1325 {
1326 ++lexer;
1327 {
1328 #if (DEBUG)
1329 if (writeToLog) System.Lex.WriteSuccessToLog(lexer, debugSpan, u"Char");
1330 #endif
1331 return Match(true, new Value<uchar>('+'));
1332 }
1333 break;
1334 }
1335 case QUEST:
1336 {
1337 ++lexer;
1338 {
1339 #if (DEBUG)
1340 if (writeToLog) System.Lex.WriteSuccessToLog(lexer, debugSpan, u"Char");
1341 #endif
1342 return Match(true, new Value<uchar>('?'));
1343 }
1344 break;
1345 }
1346 case DOT:
1347 {
1348 ++lexer;
1349 {
1350 #if (DEBUG)
1351 if (writeToLog) System.Lex.WriteSuccessToLog(lexer, debugSpan, u"Char");
1352 #endif
1353 return Match(true, new Value<uchar>('.'));
1354 }
1355 break;
1356 }
1357 case ESCAPE:
1358 {
1359 ++lexer;
1360 {
1361 #if (DEBUG)
1362 if (writeToLog) System.Lex.WriteSuccessToLog(lexer, debugSpan, u"Char");
1363 #endif
1364 return Match(true, new Value<uchar>(soulcm.scm2html.MakeEscapeValue(lexer.FileName(), lexer.GetToken(pos))));
1365 }
1366 break;
1367 }
1368 case INVERSE:
1369 {
1370 ++lexer;
1371 {
1372 #if (DEBUG)
1373 if (writeToLog) System.Lex.WriteSuccessToLog(lexer, debugSpan, u"Char");
1374 #endif
1375 return Match(true, new Value<uchar>('^'));
1376 }
1377 break;
1378 }
1379 case MINUS:
1380 {
1381 ++lexer;
1382 {
1383 #if (DEBUG)
1384 if (writeToLog) System.Lex.WriteSuccessToLog(lexer, debugSpan, u"Char");
1385 #endif
1386 return Match(true, new Value<uchar>('-'));
1387 }
1388 break;
1389 }
1390 case CHAR:
1391 {
1392 ++lexer;
1393 ustring match = lexer.GetMatch(span);
1394 {
1395 #if (DEBUG)
1396 if (writeToLog) System.Lex.WriteSuccessToLog(lexer, debugSpan, u"Char");
1397 #endif
1398 return Match(true, new Value<uchar>(match[0]));
1399 }
1400 break;
1401 }
1402 }
1403 #if (DEBUG)
1404 if (writeToLog)
1405 {
1406 if (match.hit)
1407 {
1408 System.Lex.WriteSuccessToLog(lexer, debugSpan, u"Char");
1409 }
1410 else
1411 {
1412 System.Lex.WriteFailureToLog(lexer, u"Char");
1413 }
1414 }
1415 #endif
1416 if (!match.hit)
1417 {
1418 match.value = null;
1419 }
1420 return match;
1421 }
1422 public static Match ExpressionReference(RegExLexer& lexer)
1423 {
1424 #if (DEBUG)
1425 Span debugSpan;
1426 bool writeToLog = lexer.Log() != null;
1427 if (writeToLog)
1428 {
1429 debugSpan = lexer.GetSpan();
1430 System.Lex.WriteBeginRuleToLog(lexer, u"ExpressionReference");
1431 }
1432 #endif
1433 Span s;
1434 Match match(false);
1435 Match* parentMatch0 = &match;
1436 {
1437 Match match(false);
1438 Match* parentMatch1 = &match;
1439 {
1440 Match match(false);
1441 Match* parentMatch2 = &match;
1442 {
1443 long pos = lexer.GetPos();
1444 Span span = lexer.GetSpan();
1445 Match match(false);
1446 if (*lexer == LBRACE)
1447 {
1448 ++lexer;
1449 match.hit = true;
1450 }
1451 if (match.hit)
1452 {
1453 s = span;
1454 }
1455 *parentMatch2 = match;
1456 }
1457 *parentMatch1 = match;
1458 }
1459 if (match.hit)
1460 {
1461 Match match(false);
1462 Match* parentMatch3 = &match;
1463 {
1464 Match match(false);
1465 Match* parentMatch4 = &match;
1466 {
1467 Match match(false);
1468 if (*lexer == CHAR)
1469 {
1470 ++lexer;
1471 match.hit = true;
1472 }
1473 *parentMatch4 = match;
1474 }
1475 if (match.hit)
1476 {
1477 Match match(true);
1478 Match* parentMatch5 = &match;
1479 while (true)
1480 {
1481 long save = lexer.GetPos();
1482 {
1483 Match match(false);
1484 if (*lexer == CHAR)
1485 {
1486 ++lexer;
1487 match.hit = true;
1488 }
1489 if (match.hit)
1490 {
1491 *parentMatch5 = match;
1492 }
1493 else
1494 {
1495 lexer.SetPos(save);
1496 break;
1497 }
1498 }
1499 }
1500 }
1501 *parentMatch3 = match;
1502 }
1503 *parentMatch1 = match;
1504 }
1505 *parentMatch0 = match;
1506 }
1507 if (match.hit)
1508 {
1509 Match match(false);
1510 Match* parentMatch6 = &match;
1511 {
1512 Match match(false);
1513 Match* parentMatch7 = &match;
1514 {
1515 long pos = lexer.GetPos();
1516 Span span = lexer.GetSpan();
1517 Match match(false);
1518 if (*lexer == RBRACE)
1519 {
1520 ++lexer;
1521 match.hit = true;
1522 }
1523 if (match.hit)
1524 {
1525 s.end = span.end;
1526 {
1527 #if (DEBUG)
1528 if (writeToLog) System.Lex.WriteSuccessToLog(lexer, debugSpan, u"ExpressionReference");
1529 #endif
1530 return Match(true, new Value<ustring>(soulcm.scm2html.MakeExprRefId(lexer.FileName(), lexer.GetMatch(s), lexer.GetToken(pos).line)));
1531 }
1532 }
1533 *parentMatch7 = match;
1534 }
1535 *parentMatch6 = match;
1536 }
1537 *parentMatch0 = match;
1538 }
1539 #if (DEBUG)
1540 if (writeToLog)
1541 {
1542 if (match.hit)
1543 {
1544 System.Lex.WriteSuccessToLog(lexer, debugSpan, u"ExpressionReference");
1545 }
1546 else
1547 {
1548 System.Lex.WriteFailureToLog(lexer, u"ExpressionReference");
1549 }
1550 }
1551 #endif
1552 if (!match.hit)
1553 {
1554 match.value = null;
1555 }
1556 return match;
1557 }
1558 }