Update Google App Engine to 1.2.2 in thirdparty folder.
[Melange.git] / thirdparty / google_appengine / google / appengine / cron / GrocParser.py
blobb86cb4efc56ee96ac38f105b5f71d349c981833a
1 #!/usr/bin/env python
3 # Copyright 2007 Google Inc.
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
18 import sys
19 from antlr3 import *
20 from antlr3.compat import set, frozenset
26 allOrdinals = set([1, 2, 3, 4, 5])
27 numOrdinals = len(allOrdinals)
32 HIDDEN = BaseRecognizer.HIDDEN
34 THIRD=12
35 SEPTEMBER=35
36 FOURTH=13
37 SECOND=11
38 WEDNESDAY=21
39 NOVEMBER=37
40 SATURDAY=24
41 JULY=33
42 APRIL=30
43 DIGITS=8
44 OCTOBER=36
45 MAY=31
46 EVERY=6
47 FEBRUARY=28
48 MONDAY=19
49 SUNDAY=25
50 JUNE=32
51 DAY=18
52 MARCH=29
53 OF=4
54 EOF=-1
55 JANUARY=27
56 MONTH=26
57 FRIDAY=23
58 FIFTH=14
59 MINUTES=17
60 TIME=5
61 WS=40
62 QUARTER=39
63 THURSDAY=22
64 COMMA=9
65 DECEMBER=38
66 AUGUST=34
67 DIGIT=7
68 TUESDAY=20
69 HOURS=16
70 FIRST=10
71 FOURTH_OR_FIFTH=15
73 tokenNames = [
74 "<invalid>", "<EOR>", "<DOWN>", "<UP>",
75 "OF", "TIME", "EVERY", "DIGIT", "DIGITS", "COMMA", "FIRST", "SECOND",
76 "THIRD", "FOURTH", "FIFTH", "FOURTH_OR_FIFTH", "HOURS", "MINUTES", "DAY",
77 "MONDAY", "TUESDAY", "WEDNESDAY", "THURSDAY", "FRIDAY", "SATURDAY",
78 "SUNDAY", "MONTH", "JANUARY", "FEBRUARY", "MARCH", "APRIL", "MAY", "JUNE",
79 "JULY", "AUGUST", "SEPTEMBER", "OCTOBER", "NOVEMBER", "DECEMBER", "QUARTER",
80 "WS"
86 class GrocParser(Parser):
87 grammarFileName = "Groc.g"
88 antlr_version = version_str_to_tuple("3.1.1")
89 antlr_version_str = "3.1.1"
90 tokenNames = tokenNames
92 def __init__(self, input, state=None):
93 if state is None:
94 state = RecognizerSharedState()
96 Parser.__init__(self, input, state)
99 self.dfa3 = self.DFA3(
100 self, 3,
101 eot = self.DFA3_eot,
102 eof = self.DFA3_eof,
103 min = self.DFA3_min,
104 max = self.DFA3_max,
105 accept = self.DFA3_accept,
106 special = self.DFA3_special,
107 transition = self.DFA3_transition
113 self.ordinal_set = set()
114 self.weekday_set = set()
115 self.month_set = set()
116 self.time_string = '';
117 self.interval_mins = 0;
118 self.period_string = '';
129 valuesDict = {
130 SUNDAY: 0,
131 FIRST: 1,
132 MONDAY: 1,
133 JANUARY: 1,
134 TUESDAY: 2,
135 SECOND: 2,
136 FEBRUARY: 2,
137 WEDNESDAY: 3,
138 THIRD: 3,
139 MARCH: 3,
140 THURSDAY: 4,
141 FOURTH: 4,
142 APRIL: 4,
143 FRIDAY: 5,
144 FIFTH: 5,
145 MAY: 5,
146 SATURDAY: 6,
147 JUNE: 6,
148 JULY: 7,
149 AUGUST: 8,
150 SEPTEMBER: 9,
151 OCTOBER: 10,
152 NOVEMBER: 11,
153 DECEMBER: 12,
156 def ValueOf(self, token_type):
157 return self.valuesDict.get(token_type, -1)
162 def timespec(self, ):
164 try:
165 try:
166 pass
167 alt1 = 2
168 LA1_0 = self.input.LA(1)
170 if (LA1_0 == EVERY) :
171 LA1_1 = self.input.LA(2)
173 if ((DIGIT <= LA1_1 <= DIGITS)) :
174 alt1 = 2
175 elif ((DAY <= LA1_1 <= SUNDAY)) :
176 alt1 = 1
177 else:
178 nvae = NoViableAltException("", 1, 1, self.input)
180 raise nvae
182 elif ((FIRST <= LA1_0 <= FOURTH_OR_FIFTH)) :
183 alt1 = 1
184 else:
185 nvae = NoViableAltException("", 1, 0, self.input)
187 raise nvae
189 if alt1 == 1:
190 pass
191 self._state.following.append(self.FOLLOW_specifictime_in_timespec44)
192 self.specifictime()
194 self._state.following.pop()
197 elif alt1 == 2:
198 pass
199 self._state.following.append(self.FOLLOW_interval_in_timespec48)
200 self.interval()
202 self._state.following.pop()
210 except RecognitionException, re:
211 self.reportError(re)
212 self.recover(self.input, re)
213 finally:
215 pass
217 return
221 def specifictime(self, ):
223 TIME1 = None
225 try:
226 try:
227 pass
228 pass
229 alt3 = 2
230 alt3 = self.dfa3.predict(self.input)
231 if alt3 == 1:
232 pass
233 pass
234 pass
235 self._state.following.append(self.FOLLOW_ordinals_in_specifictime69)
236 self.ordinals()
238 self._state.following.pop()
239 self._state.following.append(self.FOLLOW_weekdays_in_specifictime71)
240 self.weekdays()
242 self._state.following.pop()
246 self.match(self.input, OF, self.FOLLOW_OF_in_specifictime74)
247 alt2 = 2
248 LA2_0 = self.input.LA(1)
250 if ((MONTH <= LA2_0 <= DECEMBER)) :
251 alt2 = 1
252 elif ((FIRST <= LA2_0 <= THIRD) or LA2_0 == QUARTER) :
253 alt2 = 2
254 else:
255 nvae = NoViableAltException("", 2, 0, self.input)
257 raise nvae
259 if alt2 == 1:
260 pass
261 self._state.following.append(self.FOLLOW_monthspec_in_specifictime77)
262 self.monthspec()
264 self._state.following.pop()
267 elif alt2 == 2:
268 pass
269 self._state.following.append(self.FOLLOW_quarterspec_in_specifictime79)
270 self.quarterspec()
272 self._state.following.pop()
281 elif alt3 == 2:
282 pass
283 pass
284 self._state.following.append(self.FOLLOW_ordinals_in_specifictime96)
285 self.ordinals()
287 self._state.following.pop()
288 self._state.following.append(self.FOLLOW_weekdays_in_specifictime98)
289 self.weekdays()
291 self._state.following.pop()
292 self.month_set = set(range(1,13))
299 TIME1=self.match(self.input, TIME, self.FOLLOW_TIME_in_specifictime112)
300 self.time_string = TIME1.text
308 except RecognitionException, re:
309 self.reportError(re)
310 self.recover(self.input, re)
311 finally:
313 pass
315 return
319 def interval(self, ):
321 intervalnum = None
322 period2 = None
325 try:
326 try:
327 pass
328 pass
329 self.match(self.input, EVERY, self.FOLLOW_EVERY_in_interval131)
330 intervalnum = self.input.LT(1)
331 if (DIGIT <= self.input.LA(1) <= DIGITS):
332 self.input.consume()
333 self._state.errorRecovery = False
335 else:
336 mse = MismatchedSetException(None, self.input)
337 raise mse
341 self.interval_mins = int(intervalnum.text)
343 self._state.following.append(self.FOLLOW_period_in_interval157)
344 period2 = self.period()
346 self._state.following.pop()
348 if ((period2 is not None) and [self.input.toString(period2.start,period2.stop)] or [None])[0] == "hours":
349 self.period_string = "hours"
350 else:
351 self.period_string = "minutes"
360 except RecognitionException, re:
361 self.reportError(re)
362 self.recover(self.input, re)
363 finally:
365 pass
367 return
371 def ordinals(self, ):
373 try:
374 try:
375 pass
376 alt5 = 2
377 LA5_0 = self.input.LA(1)
379 if (LA5_0 == EVERY) :
380 alt5 = 1
381 elif ((FIRST <= LA5_0 <= FOURTH_OR_FIFTH)) :
382 alt5 = 2
383 else:
384 nvae = NoViableAltException("", 5, 0, self.input)
386 raise nvae
388 if alt5 == 1:
389 pass
390 self.match(self.input, EVERY, self.FOLLOW_EVERY_in_ordinals176)
391 self.ordinal_set = self.ordinal_set.union(allOrdinals)
394 elif alt5 == 2:
395 pass
396 pass
397 self._state.following.append(self.FOLLOW_ordinal_in_ordinals192)
398 self.ordinal()
400 self._state.following.pop()
401 while True:
402 alt4 = 2
403 LA4_0 = self.input.LA(1)
405 if (LA4_0 == COMMA) :
406 alt4 = 1
409 if alt4 == 1:
410 pass
411 self.match(self.input, COMMA, self.FOLLOW_COMMA_in_ordinals195)
412 self._state.following.append(self.FOLLOW_ordinal_in_ordinals197)
413 self.ordinal()
415 self._state.following.pop()
418 else:
419 break
432 except RecognitionException, re:
433 self.reportError(re)
434 self.recover(self.input, re)
435 finally:
437 pass
439 return
443 def ordinal(self, ):
445 ord = None
447 try:
448 try:
449 pass
450 ord = self.input.LT(1)
451 if (FIRST <= self.input.LA(1) <= FOURTH_OR_FIFTH):
452 self.input.consume()
453 self._state.errorRecovery = False
455 else:
456 mse = MismatchedSetException(None, self.input)
457 raise mse
461 self.ordinal_set.add(self.ValueOf(ord.type));
467 except RecognitionException, re:
468 self.reportError(re)
469 self.recover(self.input, re)
470 finally:
472 pass
474 return
477 class period_return(ParserRuleReturnScope):
478 def __init__(self):
479 ParserRuleReturnScope.__init__(self)
485 def period(self, ):
487 retval = self.period_return()
488 retval.start = self.input.LT(1)
490 try:
491 try:
492 pass
493 if (HOURS <= self.input.LA(1) <= MINUTES):
494 self.input.consume()
495 self._state.errorRecovery = False
497 else:
498 mse = MismatchedSetException(None, self.input)
499 raise mse
505 retval.stop = self.input.LT(-1)
508 except RecognitionException, re:
509 self.reportError(re)
510 self.recover(self.input, re)
511 finally:
513 pass
515 return retval
519 def weekdays(self, ):
521 try:
522 try:
523 pass
524 alt7 = 2
525 LA7_0 = self.input.LA(1)
527 if (LA7_0 == DAY) :
528 alt7 = 1
529 elif ((MONDAY <= LA7_0 <= SUNDAY)) :
530 alt7 = 2
531 else:
532 nvae = NoViableAltException("", 7, 0, self.input)
534 raise nvae
536 if alt7 == 1:
537 pass
538 self.match(self.input, DAY, self.FOLLOW_DAY_in_weekdays280)
540 self.weekday_set = set([self.ValueOf(SUNDAY), self.ValueOf(MONDAY),
541 self.ValueOf(TUESDAY), self.ValueOf(WEDNESDAY),
542 self.ValueOf(THURSDAY), self.ValueOf(FRIDAY),
543 self.ValueOf(SATURDAY), self.ValueOf(SUNDAY)])
547 elif alt7 == 2:
548 pass
549 pass
550 self._state.following.append(self.FOLLOW_weekday_in_weekdays288)
551 self.weekday()
553 self._state.following.pop()
554 while True:
555 alt6 = 2
556 LA6_0 = self.input.LA(1)
558 if (LA6_0 == COMMA) :
559 alt6 = 1
562 if alt6 == 1:
563 pass
564 self.match(self.input, COMMA, self.FOLLOW_COMMA_in_weekdays291)
565 self._state.following.append(self.FOLLOW_weekday_in_weekdays293)
566 self.weekday()
568 self._state.following.pop()
571 else:
572 break
585 except RecognitionException, re:
586 self.reportError(re)
587 self.recover(self.input, re)
588 finally:
590 pass
592 return
596 def weekday(self, ):
598 dayname = None
600 try:
601 try:
602 pass
603 dayname = self.input.LT(1)
604 if (MONDAY <= self.input.LA(1) <= SUNDAY):
605 self.input.consume()
606 self._state.errorRecovery = False
608 else:
609 mse = MismatchedSetException(None, self.input)
610 raise mse
614 self.weekday_set.add(self.ValueOf(dayname.type))
620 except RecognitionException, re:
621 self.reportError(re)
622 self.recover(self.input, re)
623 finally:
625 pass
627 return
631 def monthspec(self, ):
633 try:
634 try:
635 pass
636 alt8 = 2
637 LA8_0 = self.input.LA(1)
639 if (LA8_0 == MONTH) :
640 alt8 = 1
641 elif ((JANUARY <= LA8_0 <= DECEMBER)) :
642 alt8 = 2
643 else:
644 nvae = NoViableAltException("", 8, 0, self.input)
646 raise nvae
648 if alt8 == 1:
649 pass
650 self.match(self.input, MONTH, self.FOLLOW_MONTH_in_monthspec373)
652 self.month_set = self.month_set.union(set([
653 self.ValueOf(JANUARY), self.ValueOf(FEBRUARY), self.ValueOf(MARCH),
654 self.ValueOf(APRIL), self.ValueOf(MAY), self.ValueOf(JUNE),
655 self.ValueOf(JULY), self.ValueOf(AUGUST), self.ValueOf(SEPTEMBER),
656 self.ValueOf(OCTOBER), self.ValueOf(NOVEMBER),
657 self.ValueOf(DECEMBER)]))
661 elif alt8 == 2:
662 pass
663 self._state.following.append(self.FOLLOW_months_in_monthspec383)
664 self.months()
666 self._state.following.pop()
674 except RecognitionException, re:
675 self.reportError(re)
676 self.recover(self.input, re)
677 finally:
679 pass
681 return
685 def months(self, ):
687 try:
688 try:
689 pass
690 pass
691 self._state.following.append(self.FOLLOW_month_in_months400)
692 self.month()
694 self._state.following.pop()
695 while True:
696 alt9 = 2
697 LA9_0 = self.input.LA(1)
699 if (LA9_0 == COMMA) :
700 alt9 = 1
703 if alt9 == 1:
704 pass
705 self.match(self.input, COMMA, self.FOLLOW_COMMA_in_months403)
706 self._state.following.append(self.FOLLOW_month_in_months405)
707 self.month()
709 self._state.following.pop()
712 else:
713 break
723 except RecognitionException, re:
724 self.reportError(re)
725 self.recover(self.input, re)
726 finally:
728 pass
730 return
734 def month(self, ):
736 monthname = None
738 try:
739 try:
740 pass
741 monthname = self.input.LT(1)
742 if (JANUARY <= self.input.LA(1) <= DECEMBER):
743 self.input.consume()
744 self._state.errorRecovery = False
746 else:
747 mse = MismatchedSetException(None, self.input)
748 raise mse
751 self.month_set.add(self.ValueOf(monthname.type));
756 except RecognitionException, re:
757 self.reportError(re)
758 self.recover(self.input, re)
759 finally:
761 pass
763 return
767 def quarterspec(self, ):
769 try:
770 try:
771 pass
772 alt10 = 2
773 LA10_0 = self.input.LA(1)
775 if (LA10_0 == QUARTER) :
776 alt10 = 1
777 elif ((FIRST <= LA10_0 <= THIRD)) :
778 alt10 = 2
779 else:
780 nvae = NoViableAltException("", 10, 0, self.input)
782 raise nvae
784 if alt10 == 1:
785 pass
786 self.match(self.input, QUARTER, self.FOLLOW_QUARTER_in_quarterspec497)
788 self.month_set = self.month_set.union(set([
789 self.ValueOf(JANUARY), self.ValueOf(APRIL), self.ValueOf(JULY),
790 self.ValueOf(OCTOBER)]))
793 elif alt10 == 2:
794 pass
795 pass
796 self._state.following.append(self.FOLLOW_quarter_ordinals_in_quarterspec509)
797 self.quarter_ordinals()
799 self._state.following.pop()
800 self.match(self.input, MONTH, self.FOLLOW_MONTH_in_quarterspec511)
801 self.match(self.input, OF, self.FOLLOW_OF_in_quarterspec513)
802 self.match(self.input, QUARTER, self.FOLLOW_QUARTER_in_quarterspec515)
813 except RecognitionException, re:
814 self.reportError(re)
815 self.recover(self.input, re)
816 finally:
818 pass
820 return
824 def quarter_ordinals(self, ):
826 try:
827 try:
828 pass
829 pass
830 self._state.following.append(self.FOLLOW_month_of_quarter_ordinal_in_quarter_ordinals534)
831 self.month_of_quarter_ordinal()
833 self._state.following.pop()
834 while True:
835 alt11 = 2
836 LA11_0 = self.input.LA(1)
838 if (LA11_0 == COMMA) :
839 alt11 = 1
842 if alt11 == 1:
843 pass
844 self.match(self.input, COMMA, self.FOLLOW_COMMA_in_quarter_ordinals537)
845 self._state.following.append(self.FOLLOW_month_of_quarter_ordinal_in_quarter_ordinals539)
846 self.month_of_quarter_ordinal()
848 self._state.following.pop()
851 else:
852 break
862 except RecognitionException, re:
863 self.reportError(re)
864 self.recover(self.input, re)
865 finally:
867 pass
869 return
873 def month_of_quarter_ordinal(self, ):
875 offset = None
877 try:
878 try:
879 pass
880 offset = self.input.LT(1)
881 if (FIRST <= self.input.LA(1) <= THIRD):
882 self.input.consume()
883 self._state.errorRecovery = False
885 else:
886 mse = MismatchedSetException(None, self.input)
887 raise mse
891 jOffset = self.ValueOf(offset.type) - 1
892 self.month_set = self.month_set.union(set([
893 jOffset + self.ValueOf(JANUARY), jOffset + self.ValueOf(APRIL),
894 jOffset + self.ValueOf(JULY), jOffset + self.ValueOf(OCTOBER)]))
899 except RecognitionException, re:
900 self.reportError(re)
901 self.recover(self.input, re)
902 finally:
904 pass
906 return
913 DFA3_eot = DFA.unpack(
914 u"\13\uffff"
917 DFA3_eof = DFA.unpack(
918 u"\13\uffff"
921 DFA3_min = DFA.unpack(
922 u"\1\6\1\22\1\11\2\4\1\12\2\uffff\1\23\1\11\1\4"
925 DFA3_max = DFA.unpack(
926 u"\1\17\2\31\1\5\1\11\1\17\2\uffff\2\31\1\11"
929 DFA3_accept = DFA.unpack(
930 u"\6\uffff\1\1\1\2\3\uffff"
933 DFA3_special = DFA.unpack(
934 u"\13\uffff"
938 DFA3_transition = [
939 DFA.unpack(u"\1\1\3\uffff\6\2"),
940 DFA.unpack(u"\1\3\7\4"),
941 DFA.unpack(u"\1\5\10\uffff\1\3\7\4"),
942 DFA.unpack(u"\1\6\1\7"),
943 DFA.unpack(u"\1\6\1\7\3\uffff\1\10"),
944 DFA.unpack(u"\6\11"),
945 DFA.unpack(u""),
946 DFA.unpack(u""),
947 DFA.unpack(u"\7\12"),
948 DFA.unpack(u"\1\5\10\uffff\1\3\7\4"),
949 DFA.unpack(u"\1\6\1\7\3\uffff\1\10")
953 DFA3 = DFA
956 FOLLOW_specifictime_in_timespec44 = frozenset([1])
957 FOLLOW_interval_in_timespec48 = frozenset([1])
958 FOLLOW_ordinals_in_specifictime69 = frozenset([18, 19, 20, 21, 22, 23, 24, 25])
959 FOLLOW_weekdays_in_specifictime71 = frozenset([4])
960 FOLLOW_OF_in_specifictime74 = frozenset([10, 11, 12, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39])
961 FOLLOW_monthspec_in_specifictime77 = frozenset([5])
962 FOLLOW_quarterspec_in_specifictime79 = frozenset([5])
963 FOLLOW_ordinals_in_specifictime96 = frozenset([18, 19, 20, 21, 22, 23, 24, 25])
964 FOLLOW_weekdays_in_specifictime98 = frozenset([5])
965 FOLLOW_TIME_in_specifictime112 = frozenset([1])
966 FOLLOW_EVERY_in_interval131 = frozenset([7, 8])
967 FOLLOW_set_in_interval141 = frozenset([16, 17])
968 FOLLOW_period_in_interval157 = frozenset([1])
969 FOLLOW_EVERY_in_ordinals176 = frozenset([1])
970 FOLLOW_ordinal_in_ordinals192 = frozenset([1, 9])
971 FOLLOW_COMMA_in_ordinals195 = frozenset([10, 11, 12, 13, 14, 15])
972 FOLLOW_ordinal_in_ordinals197 = frozenset([1, 9])
973 FOLLOW_set_in_ordinal218 = frozenset([1])
974 FOLLOW_set_in_period257 = frozenset([1])
975 FOLLOW_DAY_in_weekdays280 = frozenset([1])
976 FOLLOW_weekday_in_weekdays288 = frozenset([1, 9])
977 FOLLOW_COMMA_in_weekdays291 = frozenset([18, 19, 20, 21, 22, 23, 24, 25])
978 FOLLOW_weekday_in_weekdays293 = frozenset([1, 9])
979 FOLLOW_set_in_weekday314 = frozenset([1])
980 FOLLOW_MONTH_in_monthspec373 = frozenset([1])
981 FOLLOW_months_in_monthspec383 = frozenset([1])
982 FOLLOW_month_in_months400 = frozenset([1, 9])
983 FOLLOW_COMMA_in_months403 = frozenset([26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38])
984 FOLLOW_month_in_months405 = frozenset([1, 9])
985 FOLLOW_set_in_month424 = frozenset([1])
986 FOLLOW_QUARTER_in_quarterspec497 = frozenset([1])
987 FOLLOW_quarter_ordinals_in_quarterspec509 = frozenset([26])
988 FOLLOW_MONTH_in_quarterspec511 = frozenset([4])
989 FOLLOW_OF_in_quarterspec513 = frozenset([39])
990 FOLLOW_QUARTER_in_quarterspec515 = frozenset([1])
991 FOLLOW_month_of_quarter_ordinal_in_quarter_ordinals534 = frozenset([1, 9])
992 FOLLOW_COMMA_in_quarter_ordinals537 = frozenset([10, 11, 12, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39])
993 FOLLOW_month_of_quarter_ordinal_in_quarter_ordinals539 = frozenset([1, 9])
994 FOLLOW_set_in_month_of_quarter_ordinal558 = frozenset([1])
998 def main(argv, stdin=sys.stdin, stdout=sys.stdout, stderr=sys.stderr):
999 from antlr3.main import ParserMain
1000 main = ParserMain("GrocLexer", GrocParser)
1001 main.stdin = stdin
1002 main.stdout = stdout
1003 main.stderr = stderr
1004 main.execute(argv)
1007 if __name__ == '__main__':
1008 main(sys.argv)