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