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
9
10 public static class HttpFieldValueParser
11 {
12 public static void Parse(HttpLexer& lexer, List<HttpFieldValue>* values)
13 {
14 #if (DEBUG)
15 if (lexer.Log() != null)
16 {
17 lexer.Log()->WriteBeginRule(u"parse");
18 lexer.Log()->IncIndent();
19 }
20 #endif
21 ++lexer;
22 System.Lex.Span span = lexer.GetSpan();
23 Match match = CommaSeparatedFieldValue(lexer, values);
24 if (match.hit)
25 {
26 if (*lexer == System.Lex.END_TOKEN)
27 {
28 return;
29 }
30 else
31 {
32 lexer.ThrowExpectationFailure(lexer.GetSpan(), GetEndTokenInfo());
33 }
34 }
35 else
36 {
37 lexer.ThrowExpectationFailure(span, u"CommaSeparatedFieldValue");
38 }
39 return;
40 }
41 public static Match CommaSeparatedFieldValue(HttpLexer& lexer, List<HttpFieldValue>* values)
42 {
43 #if (DEBUG)
44 Span debugSpan;
45 bool writeToLog = lexer.Log() != null;
46 if (writeToLog)
47 {
48 debugSpan = lexer.GetSpan();
49 System.Lex.WriteBeginRuleToLog(lexer, u"CommaSeparatedFieldValue");
50 }
51 #endif
52 Match match(false);
53 Match* parentMatch0 = &match;
54 {
55 Match match = HttpFieldValueParser.GeneralFieldValue(lexer, values);
56 *parentMatch0 = match;
57 }
58 if (match.hit)
59 {
60 Match match(false);
61 Match* parentMatch1 = &match;
62 {
63 Match match(true);
64 Match* parentMatch2 = &match;
65 {
66 while (true)
67 {
68 long save = lexer.GetPos();
69 {
70 Match match(false);
71 Match* parentMatch3 = &match;
72 {
73 Match match(false);
74 Match* parentMatch4 = &match;
75 {
76 Match match(false);
77 Match* parentMatch5 = &match;
78 {
79 Match match(false);
80 Match* parentMatch6 = &match;
81 {
82 Match match(true);
83 long save = lexer.GetPos();
84 Match* parentMatch7 = &match;
85 {
86 Match match = Http.lws(lexer);
87 if (match.hit)
88 {
89 *parentMatch7 = match;
90 }
91 else
92 {
93 lexer.SetPos(save);
94 }
95 }
96 *parentMatch6 = match;
97 }
98 if (match.hit)
99 {
100 Match match(false);
101 Match* parentMatch8 = &match;
102 {
103 Match match(false);
104 if (*lexer == COMMA)
105 {
106 ++lexer;
107 match.hit = true;
108 }
109 *parentMatch8 = match;
110 }
111 *parentMatch6 = match;
112 }
113 *parentMatch5 = match;
114 }
115 if (match.hit)
116 {
117 Match match(false);
118 Match* parentMatch9 = &match;
119 {
120 Match match(true);
121 long save = lexer.GetPos();
122 Match* parentMatch10 = &match;
123 {
124 Match match = Http.lws(lexer);
125 if (match.hit)
126 {
127 *parentMatch10 = match;
128 }
129 else
130 {
131 lexer.SetPos(save);
132 }
133 }
134 *parentMatch9 = match;
135 }
136 *parentMatch5 = match;
137 }
138 *parentMatch4 = match;
139 }
140 if (match.hit)
141 {
142 Match match(false);
143 Match* parentMatch11 = &match;
144 {
145 Match match = HttpFieldValueParser.GeneralFieldValue(lexer, values);
146 *parentMatch11 = match;
147 }
148 *parentMatch4 = match;
149 }
150 *parentMatch3 = match;
151 }
152 if (match.hit)
153 {
154 *parentMatch2 = match;
155 }
156 else
157 {
158 lexer.SetPos(save);
159 break;
160 }
161 }
162 }
163 }
164 *parentMatch1 = match;
165 }
166 *parentMatch0 = match;
167 }
168 #if (DEBUG)
169 if (writeToLog)
170 {
171 if (match.hit)
172 {
173 System.Lex.WriteSuccessToLog(lexer, debugSpan, u"CommaSeparatedFieldValue");
174 }
175 else
176 {
177 System.Lex.WriteFailureToLog(lexer, u"CommaSeparatedFieldValue");
178 }
179 }
180 #endif
181 if (!match.hit)
182 {
183 match.value = null;
184 }
185 return match;
186 }
187 public static Match GeneralFieldValue(HttpLexer& lexer, List<HttpFieldValue>* values)
188 {
189 #if (DEBUG)
190 Span debugSpan;
191 bool writeToLog = lexer.Log() != null;
192 if (writeToLog)
193 {
194 debugSpan = lexer.GetSpan();
195 System.Lex.WriteBeginRuleToLog(lexer, u"GeneralFieldValue");
196 }
197 #endif
198 HttpFieldValue fieldValue;
199 UniquePtr<Value<string>> t;
200 Match match(false);
201 Match* parentMatch0 = &match;
202 {
203 long pos = lexer.GetPos();
204 Match match(false);
205 Match* parentMatch1 = &match;
206 {
207 Match match(false);
208 Match* parentMatch2 = &match;
209 {
210 Match match(false);
211 Match* parentMatch3 = &match;
212 {
213 long pos = lexer.GetPos();
214 Match match = Http.token(lexer);
215 t.Reset(cast<Value<string>*>(match.value));
216 if (match.hit)
217 {
218 fieldValue.SetFieldValue(t->value);
219 }
220 *parentMatch3 = match;
221 }
222 *parentMatch2 = match;
223 }
224 if (match.hit)
225 {
226 Match match(false);
227 Match* parentMatch4 = &match;
228 {
229 Match match(true);
230 Match* parentMatch5 = &match;
231 {
232 while (true)
233 {
234 long save = lexer.GetPos();
235 {
236 Match match(false);
237 Match* parentMatch6 = &match;
238 {
239 Match match(false);
240 Match* parentMatch7 = &match;
241 {
242 Match match(false);
243 Match* parentMatch8 = &match;
244 {
245 Match match(false);
246 if (*lexer == SEMICOLON)
247 {
248 ++lexer;
249 match.hit = true;
250 }
251 *parentMatch8 = match;
252 }
253 if (match.hit)
254 {
255 Match match(false);
256 Match* parentMatch9 = &match;
257 {
258 Match match(true);
259 long save = lexer.GetPos();
260 Match* parentMatch10 = &match;
261 {
262 Match match = Http.lws(lexer);
263 if (match.hit)
264 {
265 *parentMatch10 = match;
266 }
267 else
268 {
269 lexer.SetPos(save);
270 }
271 }
272 *parentMatch9 = match;
273 }
274 *parentMatch8 = match;
275 }
276 *parentMatch7 = match;
277 }
278 if (match.hit)
279 {
280 Match match(false);
281 Match* parentMatch11 = &match;
282 {
283 Match match = HttpFieldValueParser.GeneralParameter(lexer, &fieldValue);
284 *parentMatch11 = match;
285 }
286 *parentMatch7 = match;
287 }
288 *parentMatch6 = match;
289 }
290 if (match.hit)
291 {
292 *parentMatch5 = match;
293 }
294 else
295 {
296 lexer.SetPos(save);
297 break;
298 }
299 }
300 }
301 }
302 *parentMatch4 = match;
303 }
304 *parentMatch2 = match;
305 }
306 *parentMatch1 = match;
307 }
308 if (match.hit)
309 {
310 values->Add(fieldValue);
311 }
312 *parentMatch0 = match;
313 }
314 #if (DEBUG)
315 if (writeToLog)
316 {
317 if (match.hit)
318 {
319 System.Lex.WriteSuccessToLog(lexer, debugSpan, u"GeneralFieldValue");
320 }
321 else
322 {
323 System.Lex.WriteFailureToLog(lexer, u"GeneralFieldValue");
324 }
325 }
326 #endif
327 if (!match.hit)
328 {
329 match.value = null;
330 }
331 return match;
332 }
333 public static Match GeneralParameter(HttpLexer& lexer, HttpFieldValue* fieldValue)
334 {
335 #if (DEBUG)
336 Span debugSpan;
337 bool writeToLog = lexer.Log() != null;
338 if (writeToLog)
339 {
340 debugSpan = lexer.GetSpan();
341 System.Lex.WriteBeginRuleToLog(lexer, u"GeneralParameter");
342 }
343 #endif
344 UniquePtr<Value<string>> a;
345 UniquePtr<Value<string>> av;
346 Match match(false);
347 Match* parentMatch0 = &match;
348 {
349 long pos = lexer.GetPos();
350 Match match(false);
351 Match* parentMatch1 = &match;
352 {
353 Match match(false);
354 Match* parentMatch2 = &match;
355 {
356 Match match = Http.attribute(lexer);
357 a.Reset(cast<Value<string>*>(match.value));
358 *parentMatch2 = match;
359 }
360 if (match.hit)
361 {
362 Match match(false);
363 Match* parentMatch3 = &match;
364 {
365 Match match(true);
366 long save = lexer.GetPos();
367 Match* parentMatch4 = &match;
368 {
369 Match match(false);
370 Match* parentMatch5 = &match;
371 {
372 Match match(false);
373 Match* parentMatch6 = &match;
374 {
375 Match match(false);
376 if (*lexer == EQ)
377 {
378 ++lexer;
379 match.hit = true;
380 }
381 *parentMatch6 = match;
382 }
383 if (match.hit)
384 {
385 Match match(false);
386 Match* parentMatch7 = &match;
387 {
388 Match match = Http.attrval(lexer);
389 av.Reset(cast<Value<string>*>(match.value));
390 *parentMatch7 = match;
391 }
392 *parentMatch6 = match;
393 }
394 *parentMatch5 = match;
395 }
396 if (match.hit)
397 {
398 *parentMatch4 = match;
399 }
400 else
401 {
402 lexer.SetPos(save);
403 }
404 }
405 *parentMatch3 = match;
406 }
407 *parentMatch2 = match;
408 }
409 *parentMatch1 = match;
410 }
411 if (match.hit)
412 {
413 fieldValue->SetParameter(a->value, av->value);
414 }
415 *parentMatch0 = match;
416 }
417 #if (DEBUG)
418 if (writeToLog)
419 {
420 if (match.hit)
421 {
422 System.Lex.WriteSuccessToLog(lexer, debugSpan, u"GeneralParameter");
423 }
424 else
425 {
426 System.Lex.WriteFailureToLog(lexer, u"GeneralParameter");
427 }
428 }
429 #endif
430 if (!match.hit)
431 {
432 match.value = null;
433 }
434 return match;
435 }
436 }