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/HttpHeaderParser.parser' using soulcm parser generator scmpg version 3.0.0
  9 
 10 public static class HttpHeaderParser
 11 {
 12     public static HttpHeader Parse(HttpLexer& lexer)
 13     {
 14         UniquePtr<Value<HttpHeader>> 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 = message_header(lexer);
 25         value.Reset(cast<Value<HttpHeader>*>(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"message_header");
 47         }
 48         return value->value;
 49     }
 50     public static Match message_header(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"message_header");
 59             }
 60         #endif
 61         UniquePtr<Value<string>> fn;
 62         UniquePtr<Value<string>> fv;
 63         Match match(false);
 64         Match* parentMatch0 = &match;
 65         {
 66             long pos = lexer.GetPos();
 67             Match match(false);
 68             Match* parentMatch1 = &match;
 69             {
 70                 Match match(false);
 71                 Match* parentMatch2 = &match;
 72                 {
 73                     Match match(false);
 74                     Match* parentMatch3 = &match;
 75                     {
 76                         Match match = HttpHeaderParser.field_name(lexer);
 77                         fn.Reset(cast<Value<string>*>(match.value));
 78                         *parentMatch3 = match;
 79                     }
 80                     if (match.hit)
 81                     {
 82                         Match match(false);
 83                         Match* parentMatch4 = &match;
 84                         {
 85                             Match match(false);
 86                             if (*lexer == COLON)
 87                             {
 88                                 ++lexer;
 89                                 match.hit = true;
 90                             }
 91                             *parentMatch4 = match;
 92                         }
 93                         *parentMatch3 = match;
 94                     }
 95                     *parentMatch2 = match;
 96                 }
 97                 if (match.hit)
 98                 {
 99                     Match match(false);
100                     Match* parentMatch5 = &match;
101                     {
102                         Match match(true);
103                         long save = lexer.GetPos();
104                         Match* parentMatch6 = &match;
105                         {
106                             Match match = HttpHeaderParser.field_value(lexer);
107                             fv.Reset(cast<Value<string>*>(match.value));
108                             if (match.hit)
109                             {
110                                 *parentMatch6 = match;
111                             }
112                             else
113                             {
114                                 lexer.SetPos(save);
115                             }
116                         }
117                         *parentMatch5 = match;
118                     }
119                     *parentMatch2 = match;
120                 }
121                 *parentMatch1 = match;
122             }
123             if (match.hit)
124             {
125                 {
126                     #if (DEBUG)
127                         if (writeToLog) System.Lex.WriteSuccessToLog(lexerdebugSpanu"message_header");
128                     #endif
129                     return Match(truenew Value<HttpHeader>(HttpHeader(fn->valuefv->value)));
130                 }
131             }
132             *parentMatch0 = match;
133         }
134         #if (DEBUG)
135             if (writeToLog)
136             {
137                 if (match.hit)
138                 {
139                     System.Lex.WriteSuccessToLog(lexerdebugSpanu"message_header");
140                 }
141                 else
142                 {
143                     System.Lex.WriteFailureToLog(lexeru"message_header");
144                 }
145             }
146         #endif
147         if (!match.hit)
148         {
149             match.value = null;
150         }
151         return match;
152     }
153     public static Match field_name(HttpLexer& lexer)
154     {
155         #if (DEBUG)
156             Span debugSpan;
157             bool writeToLog = lexer.Log() != null;
158             if (writeToLog)
159             {
160                 debugSpan = lexer.GetSpan();
161                 System.Lex.WriteBeginRuleToLog(lexeru"field_name");
162             }
163         #endif
164         UniquePtr<Value<string>> tk;
165         Match match(false);
166         Match* parentMatch0 = &match;
167         {
168             long pos = lexer.GetPos();
169             Match match = Http.token(lexer);
170             tk.Reset(cast<Value<string>*>(match.value));
171             if (match.hit)
172             {
173                 {
174                     #if (DEBUG)
175                         if (writeToLog) System.Lex.WriteSuccessToLog(lexerdebugSpanu"field_name");
176                     #endif
177                     return Match(truenew Value<string>(tk->value));
178                 }
179             }
180             *parentMatch0 = match;
181         }
182         #if (DEBUG)
183             if (writeToLog)
184             {
185                 if (match.hit)
186                 {
187                     System.Lex.WriteSuccessToLog(lexerdebugSpanu"field_name");
188                 }
189                 else
190                 {
191                     System.Lex.WriteFailureToLog(lexeru"field_name");
192                 }
193             }
194         #endif
195         if (!match.hit)
196         {
197             match.value = null;
198         }
199         return match;
200     }
201     public static Match field_value(HttpLexer& lexer)
202     {
203         #if (DEBUG)
204             Span debugSpan;
205             bool writeToLog = lexer.Log() != null;
206             if (writeToLog)
207             {
208                 debugSpan = lexer.GetSpan();
209                 System.Lex.WriteBeginRuleToLog(lexeru"field_value");
210             }
211         #endif
212         string s;
213         UniquePtr<Value<string>> fc;
214         Match match(false);
215         Match* parentMatch0 = &match;
216         {
217             long pos = lexer.GetPos();
218             Match match(false);
219             Match* parentMatch1 = &match;
220             {
221                 Match match(false);
222                 Match* parentMatch2 = &match;
223                 {
224                     Match match(false);
225                     Match* parentMatch3 = &match;
226                     {
227                         Match match(false);
228                         Match* parentMatch4 = &match;
229                         {
230                             long save = lexer.GetPos();
231                             Match match(false);
232                             Match* parentMatch5 = &match;
233                             {
234                                 long pos = lexer.GetPos();
235                                 Match match = Http.lws(lexer);
236                                 if (match.hit)
237                                 {
238                                     s.Append(' ');
239                                 }
240                                 *parentMatch5 = match;
241                             }
242                             *parentMatch4 = match;
243                             if (!match.hit)
244                             {
245                                 Match match(false);
246                                 Match* parentMatch6 = &match;
247                                 lexer.SetPos(save);
248                                 {
249                                     Match match(false);
250                                     Match* parentMatch7 = &match;
251                                     {
252                                         long pos = lexer.GetPos();
253                                         Match match = HttpHeaderParser.field_content(lexer);
254                                         fc.Reset(cast<Value<string>*>(match.value));
255                                         if (match.hit)
256                                         {
257                                             s.Append(fc->value);
258                                         }
259                                         *parentMatch7 = match;
260                                     }
261                                     *parentMatch6 = match;
262                                 }
263                                 *parentMatch4 = match;
264                             }
265                         }
266                         *parentMatch3 = match;
267                     }
268                     *parentMatch2 = match;
269                 }
270                 if (match.hit)
271                 {
272                     Match match(true);
273                     Match* parentMatch8 = &match;
274                     while (true)
275                     {
276                         long save = lexer.GetPos();
277                         {
278                             Match match(false);
279                             Match* parentMatch9 = &match;
280                             {
281                                 Match match(false);
282                                 Match* parentMatch10 = &match;
283                                 {
284                                     long save = lexer.GetPos();
285                                     Match match(false);
286                                     Match* parentMatch11 = &match;
287                                     {
288                                         long pos = lexer.GetPos();
289                                         Match match = Http.lws(lexer);
290                                         if (match.hit)
291                                         {
292                                             s.Append(' ');
293                                         }
294                                         *parentMatch11 = match;
295                                     }
296                                     *parentMatch10 = match;
297                                     if (!match.hit)
298                                     {
299                                         Match match(false);
300                                         Match* parentMatch12 = &match;
301                                         lexer.SetPos(save);
302                                         {
303                                             Match match(false);
304                                             Match* parentMatch13 = &match;
305                                             {
306                                                 long pos = lexer.GetPos();
307                                                 Match match = HttpHeaderParser.field_content(lexer);
308                                                 fc.Reset(cast<Value<string>*>(match.value));
309                                                 if (match.hit)
310                                                 {
311                                                     s.Append(fc->value);
312                                                 }
313                                                 *parentMatch13 = match;
314                                             }
315                                             *parentMatch12 = match;
316                                         }
317                                         *parentMatch10 = match;
318                                     }
319                                 }
320                                 *parentMatch9 = match;
321                             }
322                             if (match.hit)
323                             {
324                                 *parentMatch8 = match;
325                             }
326                             else
327                             {
328                                 lexer.SetPos(save);
329                                 break;
330                             }
331                         }
332                     }
333                 }
334                 *parentMatch1 = match;
335             }
336             if (match.hit)
337             {
338                 {
339                     #if (DEBUG)
340                         if (writeToLog) System.Lex.WriteSuccessToLog(lexerdebugSpanu"field_value");
341                     #endif
342                     return Match(truenew Value<string>(s));
343                 }
344             }
345             *parentMatch0 = match;
346         }
347         #if (DEBUG)
348             if (writeToLog)
349             {
350                 if (match.hit)
351                 {
352                     System.Lex.WriteSuccessToLog(lexerdebugSpanu"field_value");
353                 }
354                 else
355                 {
356                     System.Lex.WriteFailureToLog(lexeru"field_value");
357                 }
358             }
359         #endif
360         if (!match.hit)
361         {
362             match.value = null;
363         }
364         return match;
365     }
366     public static Match field_content(HttpLexer& lexer)
367     {
368         #if (DEBUG)
369             Span debugSpan;
370             bool writeToLog = lexer.Log() != null;
371             if (writeToLog)
372             {
373                 debugSpan = lexer.GetSpan();
374                 System.Lex.WriteBeginRuleToLog(lexeru"field_content");
375             }
376         #endif
377         string s;
378         UniquePtr<Value<char>> t;
379         Match match(false);
380         Match* parentMatch0 = &match;
381         {
382             long pos = lexer.GetPos();
383             Match match(false);
384             Match* parentMatch1 = &match;
385             {
386                 Match match(false);
387                 Match* parentMatch2 = &match;
388                 {
389                     Match match(false);
390                     Match* parentMatch3 = &match;
391                     {
392                         Match match(false);
393                         Match* parentMatch4 = &match;
394                         {
395                             long pos = lexer.GetPos();
396                             Match match = Http.text(lexer);
397                             t.Reset(cast<Value<char>*>(match.value));
398                             if (match.hit)
399                             {
400                                 s.Append(t->value);
401                             }
402                             *parentMatch4 = match;
403                         }
404                         *parentMatch3 = match;
405                     }
406                     *parentMatch2 = match;
407                 }
408                 if (match.hit)
409                 {
410                     Match match(true);
411                     Match* parentMatch5 = &match;
412                     while (true)
413                     {
414                         long save = lexer.GetPos();
415                         {
416                             Match match(false);
417                             Match* parentMatch6 = &match;
418                             {
419                                 Match match(false);
420                                 Match* parentMatch7 = &match;
421                                 {
422                                     long pos = lexer.GetPos();
423                                     Match match = Http.text(lexer);
424                                     t.Reset(cast<Value<char>*>(match.value));
425                                     if (match.hit)
426                                     {
427                                         s.Append(t->value);
428                                     }
429                                     *parentMatch7 = match;
430                                 }
431                                 *parentMatch6 = match;
432                             }
433                             if (match.hit)
434                             {
435                                 *parentMatch5 = match;
436                             }
437                             else
438                             {
439                                 lexer.SetPos(save);
440                                 break;
441                             }
442                         }
443                     }
444                 }
445                 *parentMatch1 = match;
446             }
447             if (match.hit)
448             {
449                 {
450                     #if (DEBUG)
451                         if (writeToLog) System.Lex.WriteSuccessToLog(lexerdebugSpanu"field_content");
452                     #endif
453                     return Match(truenew Value<string>(s));
454                 }
455             }
456             *parentMatch0 = match;
457         }
458         #if (DEBUG)
459             if (writeToLog)
460             {
461                 if (match.hit)
462                 {
463                     System.Lex.WriteSuccessToLog(lexerdebugSpanu"field_content");
464                 }
465                 else
466                 {
467                     System.Lex.WriteFailureToLog(lexeru"field_content");
468                 }
469             }
470         #endif
471         if (!match.hit)
472         {
473             match.value = null;
474         }
475         return match;
476     }
477 }