Expand annotate handling to 3.3

(and possibly 3.2)

- DRY Python 3.1-3.3 grammar a little
This commit is contained in:
rocky
2016-10-28 08:21:23 -04:00
parent 0e7da031b2
commit 9849f06ff6
4 changed files with 59 additions and 27 deletions

View File

@@ -14,8 +14,29 @@ class Python32Parser(Python3Parser):
binary_subscr2 ::= expr expr DUP_TOP_TWO BINARY_SUBSCR
stmt ::= store_locals
store_locals ::= LOAD_FAST STORE_LOCALS
stmt ::= funcdef_annotate
funcdef_annotate ::= mkfunc_annotate designator
annotate_args ::= annotate_args annotate_arg
annotate_args ::= annotate_arg
annotate_arg ::= LOAD_CONST expr
"""
pass
def add_custom_rules(self, tokens, customize):
super(Python32Parser, self).add_custom_rules(tokens, customize)
for i, token in enumerate(tokens):
opname = token.type
if opname.startswith('MAKE_FUNCTION_A'):
args_pos, args_kw, annotate_args = token.attr
# Check that there are 2 annotated params?
rule = ('mkfunc_annotate ::= %s%sLOAD_CONST LOAD_CONST EXTENDED_ARG %s' %
(('pos_arg ' * (args_pos)),
('annotate_args ' * (annotate_args-1)), opname))
print(rule)
self.add_unique_rule(rule, opname, token.attr, customize)
class Python32ParserSingle(Python32Parser, PythonParserSingle):
pass