| 9 | |
| 10 | |
| 11 | class Python31Parser(Python32Parser): |
| 12 | def p_31(self, args): |
| 13 | """ |
| 14 | subscript2 ::= expr expr DUP_TOPX BINARY_SUBSCR |
| 15 | |
| 16 | setupwith ::= DUP_TOP LOAD_ATTR store LOAD_ATTR CALL_FUNCTION_0 POP_TOP |
| 17 | setupwithas ::= DUP_TOP LOAD_ATTR store LOAD_ATTR CALL_FUNCTION_0 store |
| 18 | with ::= expr setupwith SETUP_FINALLY |
| 19 | suite_stmts_opt |
| 20 | POP_BLOCK LOAD_CONST COME_FROM_FINALLY |
| 21 | load delete WITH_CLEANUP END_FINALLY |
| 22 | |
| 23 | # Keeps Python 3.1 "with .. as" designator in the same position as it is in other version. |
| 24 | setupwithas31 ::= setupwithas SETUP_FINALLY load delete |
| 25 | |
| 26 | with_as ::= expr setupwithas31 store |
| 27 | suite_stmts_opt |
| 28 | POP_BLOCK LOAD_CONST COME_FROM_FINALLY |
| 29 | load delete WITH_CLEANUP END_FINALLY |
| 30 | |
| 31 | store ::= STORE_NAME |
| 32 | load ::= LOAD_FAST |
| 33 | load ::= LOAD_NAME |
| 34 | """ |
| 35 | |
| 36 | def remove_rules_31(self): |
| 37 | self.remove_rules( |
| 38 | """ |
| 39 | # DUP_TOP_TWO is DUP_TOPX in 3.1 and earlier |
| 40 | subscript2 ::= expr expr DUP_TOP_TWO BINARY_SUBSCR |
| 41 | |
| 42 | # The were found using grammar coverage |
| 43 | list_if ::= expr jmp_false list_iter COME_FROM |
| 44 | list_if_not ::= expr jmp_true list_iter COME_FROM |
| 45 | """ |
| 46 | ) |
| 47 | |
| 48 | def customize_grammar_rules(self, tokens, customize): |
| 49 | super(Python31Parser, self).customize_grammar_rules(tokens, customize) |
| 50 | self.remove_rules_31() |
| 51 | return |
| 52 | |
| 53 | pass |
| 54 | |
| 55 | |
| 56 | class Python31ParserSingle(Python31Parser, PythonParserSingle): |