1 using System.Net.Http;
2
3 parser HttpDateParser
4 {
5 uselexer TrivialLexer;
6 main;
7
8 HttpDate : DateTime
9 ::= RFC1123Date:d1{ return d1; } | RFC850Date:d2{ return d2; } | AscTimeDate:d3{ return d3; }
10 ;
11
12 RFC1123Date : DateTime
13 ::= (wkday:wd ',' SP:sp1 date1:d1 SP:sp2 time:t SP:sp3 "GMT"){ return DateTime(d1, t); }
14 ;
15
16 RFC850Date : DateTime
17 ::= (weekday:wd "," SP:sp1 date2:d2 SP:sp2 time:t SP:sp3 "GMT"){ return DateTime(d2, t); }
18 ;
19
20 AscTimeDate(var Date monthday) : DateTime
21 ::= (wkday:wd SP:sp1 date3:md{ monthday = md; } SP:sp2 time:t SP:sp3 Year:y){ return DateTime(Date(y, monthday.GetMonth(), monthday.Day()), t); }
22 ;
23
24 date1 : Date
25 ::= (Day:day SP:sp1 month:m SP:sp2 Year:y){ return Date(y, m, day); }
26 ;
27
28 date2 : Date
29 ::= (Day:day '-' month:m '-' Year2:y){ return Date(y, m, day); }
30 ;
31
32 date3(var sbyte d) : Date
33 ::= (month:m SP:sp (Day:day{ d = day; } | Day1:day1{ d = day1; })){ return Date(0, m, d); }
34 ;
35
36 Year(var ustring s) : short
37 ::= (DIGIT:d1{ s.Append(d1); } DIGIT:d2{ s.Append(d2); } DIGIT:d3{ s.Append(d3); } DIGIT:d4{ s.Append(d4); }){ return ParseShort(ToUtf8(s)); }
38 ;
39
40 Year2(var ustring s) : short
41 ::= (DIGIT:d1{ s.Append(d1); } DIGIT:d2{ s.Append(d2); }){ return 2000 + ParseShort(ToUtf8(s)); }
42 ;
43
44 Day(var ustring s) : sbyte
45 ::= (DIGIT:d1{ s.Append(d1); } DIGIT:d2{ s.Append(d2); }){ return ParseSByte(ToUtf8(s)); }
46 ;
47
48 Day1(var ustring s) : sbyte
49 ::= SP:sp DIGIT:digit{ s.Append(digit); return ParseSByte(ToUtf8(s)); }
50 ;
51
52 wkday
53 ::= "Mon" | "Tue" | "Wed" | "Thu" | "Fri" | "Sat" | "Sun"
54 ;
55
56 weekday
57 ::= "Monday" | "Tuesday" | "Wednesday" | "Thursday" | "Friday" | "Saturday" | "Sunday"
58 ;
59
60 month : Month
61 ::= "Jan"{ return Month.january; }
62 | "Feb"{ return Month.february; }
63 | "Mar"{ return Month.march; }
64 | "Apr"{ return Month.april; }
65 | "May"{ return Month.may; }
66 | "Jun"{ return Month.june; }
67 | "Jul"{ return Month.july; }
68 | "Aug"{ return Month.august; }
69 | "Sep"{ return Month.september; }
70 | "Oct"{ return Month.october; }
71 | "Nov"{ return Month.november; }
72 | "Dec"{ return Month.december; }
73 ;
74
75 time : int
76 ::= (Hour:hour ':' Min:min ':' Sec:sec){ return 3600 * hour + 60 * min + sec; }
77 ;
78
79 Hour(var ustring s) : int
80 ::= (DIGIT:d1{ s.Append(d1); } DIGIT:d2{ s.Append(d2); }){ return ParseInt(ToUtf8(s)); }
81 ;
82
83 Min(var ustring s) : int
84 ::= (DIGIT:d1{ s.Append(d1); } DIGIT:d2{ s.Append(d2); }){ return ParseInt(ToUtf8(s)); }
85 ;
86
87 Sec(var ustring s) : int
88 ::= (DIGIT:d1{ s.Append(d1); } DIGIT:d2{ s.Append(d2); }){ return ParseInt(ToUtf8(s)); }
89 ;
90
91 deltaSeconds(var ustring s) : int
92 ::= ((DIGIT:digit{ s.Append(digit); })+){ return ParseInt(ToUtf8(s)); }
93 ;
94
95 SP : uchar
96 ::= ' '{ return ' '; }
97 ;
98
99 DIGIT : uchar
100 ::= "[0-9]"{ return lexer.GetUChar(pos); }
101 ;
102 }