NT call_function -> call to match AST

This commit is contained in:
rocky
2017-11-28 22:13:23 -05:00
parent d03c5549a6
commit fb695616a6
10 changed files with 45 additions and 47 deletions

View File

@@ -17,7 +17,7 @@ def test_grammar():
(lhs, rhs, tokens,
right_recursive, dup_rhs) = p.check_sets()
expect_lhs = set(['expr1024', 'pos_arg'])
unused_rhs = set(['build_list', 'call_function', 'mkfunc',
unused_rhs = set(['build_list', 'call', 'mkfunc',
'mklambda',
'unpack',])

View File

@@ -437,7 +437,7 @@ class PythonParser(GenericASTBuilder):
expr ::= and
expr ::= or
expr ::= unary_expr
expr ::= call_function
expr ::= call
expr ::= unary_not
expr ::= binary_subscr
expr ::= binary_subscr2

View File

@@ -320,7 +320,7 @@ class Python2Parser(PythonParser):
args_kw = (v >> 8) & 0xff # keyword parameters
# number of apply equiv arguments:
nak = ( len(opname_base)-len('CALL_FUNCTION') ) // 3
rule = 'call_function ::= expr ' + 'expr '*args_pos + 'kwarg '*args_kw \
rule = 'call ::= expr ' + 'expr '*args_pos + 'kwarg '*args_kw \
+ 'expr ' * nak + opname
elif opname_base == 'CALL_METHOD':
# PyPy only - DRY with parse3
@@ -328,7 +328,7 @@ class Python2Parser(PythonParser):
args_kw = (v >> 8) & 0xff # keyword parameters
# number of apply equiv arguments:
nak = ( len(opname_base)-len('CALL_METHOD') ) // 3
rule = 'call_function ::= expr ' + 'expr '*args_pos + 'kwarg '*args_kw \
rule = 'call ::= expr ' + 'expr '*args_pos + 'kwarg '*args_kw \
+ 'expr ' * nak + opname
elif opname == 'CONTINUE_LOOP':
self.add_unique_rule('continue_stmt ::= CONTINUE_LOOP',

View File

@@ -67,13 +67,13 @@ class Python25Parser(Python26Parser):
mkfuncdeco ::= expr mkfuncdeco CALL_FUNCTION_1
ret_cond ::= expr jmp_false_then expr RETURN_END_IF POP_TOP ret_expr_or_cond
return_if_lambda ::= RETURN_END_IF_LAMBDA POP_TOP
return_if_stmt ::= ret_expr RETURN_END_IF POP_TOP
return_if_stmts ::= return_if_stmt
return_stmt ::= ret_expr RETURN_END_IF POP_TOP
return_stmt ::= ret_expr RETURN_VALUE POP_TOP
return_if_stmt ::= ret_expr RETURN_END_IF POP_TOP
return_if_stmts ::= return_if_stmt
return_stmt ::= ret_expr RETURN_END_IF POP_TOP
return_stmt ::= ret_expr RETURN_VALUE POP_TOP
setupwithas ::= DUP_TOP LOAD_ATTR ROT_TWO LOAD_ATTR CALL_FUNCTION_0 setup_finally
stmt ::= classdefdeco
stmt ::= conditional_lambda
stmt ::= classdefdeco
stmt ::= conditional_lambda
""")
super(Python25Parser, self).add_custom_rules(tokens, customize)
if self.version == 2.5:

View File

@@ -119,7 +119,7 @@ class Python3Parser(PythonParser):
# Python3 introduced LOAD_BUILD_CLASS
# Other definitions are in a custom rule
build_class ::= LOAD_BUILD_CLASS mkfunc expr call_function CALL_FUNCTION_3
build_class ::= LOAD_BUILD_CLASS mkfunc expr call CALL_FUNCTION_3
stmt ::= classdefdeco
classdefdeco ::= classdefdeco1 designator
@@ -486,10 +486,10 @@ class Python3Parser(PythonParser):
possible_class_decorator,
seen_GET_AWAITABLE_YIELD_FROM, next_token):
"""
call_function ::= expr {expr}^n CALL_FUNCTION_n
call_function ::= expr {expr}^n CALL_FUNCTION_VAR_n
call_function ::= expr {expr}^n CALL_FUNCTION_VAR_KW_n
call_function ::= expr {expr}^n CALL_FUNCTION_KW_n
call ::= expr {expr}^n CALL_FUNCTION_n
call ::= expr {expr}^n CALL_FUNCTION_VAR_n
call ::= expr {expr}^n CALL_FUNCTION_VAR_KW_n
call ::= expr {expr}^n CALL_FUNCTION_KW_n
classdefdeco2 ::= LOAD_BUILD_CLASS mkfunc {expr}^n-1 CALL_FUNCTION_n
"""
@@ -517,31 +517,31 @@ class Python3Parser(PythonParser):
kw = 'expr '
else:
kw = ''
rule = ('call_function ::= expr expr ' +
rule = ('call ::= expr expr ' +
('pos_arg ' * args_pos) +
('kwarg ' * args_kw) + kw + token.kind)
self.add_unique_rule(rule, token.kind, uniq_param, customize)
if self.version >= 3.6 and opname == 'CALL_FUNCTION_EX_KW':
rule = ('call_function36 ::= '
rule = ('call36 ::= '
'expr build_tuple_unpack_with_call build_map_unpack_with_call '
'CALL_FUNCTION_EX_KW_1')
self.add_unique_rule(rule, token.kind, uniq_param, customize)
rule = 'call_function ::= call_function36'
rule = 'call ::= call36'
else:
rule = ('call_function ::= expr ' +
rule = ('call ::= expr ' +
('pos_arg ' * args_pos) +
('kwarg ' * args_kw) +
'expr ' * nak + token.kind)
self.add_unique_rule(rule, token.kind, uniq_param, customize)
if self.version >= 3.5 and seen_GET_AWAITABLE_YIELD_FROM:
rule = ('async_call_function ::= expr ' +
rule = ('async_call ::= expr ' +
('pos_arg ' * args_pos) +
('kwarg ' * args_kw) +
'expr ' * nak + token.kind +
' GET_AWAITABLE LOAD_CONST YIELD_FROM')
self.add_unique_rule(rule, token.kind, uniq_param, customize)
self.add_unique_rule('expr ::= async_call_function', token.kind, uniq_param, customize)
self.add_unique_rule('expr ::= async_call', token.kind, uniq_param, customize)
if possible_class_decorator:
if next_token == 'CALL_FUNCTION' and next_token.attr == 1:
@@ -584,7 +584,7 @@ class Python3Parser(PythonParser):
build_set ::= {expr}^n BUILD_SET_UNPACK_n
load_closure ::= {LOAD_CLOSURE}^n BUILD_TUPLE_n
# call_function (see custom_classfunc_rule)
# call (see custom_classfunc_rule)
# ------------
# Python <= 3.2 omits LOAD_CONST before MAKE_
@@ -623,7 +623,7 @@ class Python3Parser(PythonParser):
For PYPY:
load_attr ::= expr LOOKUP_METHOD
call_function ::= expr CALL_METHOD
call ::= expr CALL_METHOD
"""
seen_LOAD_BUILD_CLASS = False
seen_LOAD_DICTCOMP = False
@@ -770,7 +770,7 @@ class Python3Parser(PythonParser):
# number of apply equiv arguments:
nak = ( len(opname_base)-len('CALL_METHOD') ) // 3
rule = ('call_function ::= expr ' +
rule = ('call ::= expr ' +
('pos_arg ' * args_pos) +
('kwarg ' * args_kw) +
'expr ' * nak + opname)
@@ -942,7 +942,7 @@ class Python3Parser(PythonParser):
if self.version >= 3.6:
rule = ('mkfunc_annotate ::= %s%sannotate_tuple LOAD_CONST LOAD_CONST %s' %
(('pos_arg ' * (args_pos)),
('call_function ' * (annotate_args-1)), opname))
('call ' * (annotate_args-1)), opname))
self.add_unique_rule(rule, opname, token.attr, customize)
rule = ('mkfunc_annotate ::= %s%sannotate_tuple LOAD_CONST LOAD_CONST %s' %
(('pos_arg ' * (args_pos)),
@@ -953,7 +953,7 @@ class Python3Parser(PythonParser):
# Yes this is a little hacky
rule = ('mkfunc_annotate ::= %s%sannotate_tuple LOAD_CONST LOAD_CONST EXTENDED_ARG %s' %
(('pos_arg ' * (args_pos)),
('call_function ' * (annotate_args-1)), opname))
('call ' * (annotate_args-1)), opname))
self.add_unique_rule(rule, opname, token.attr, customize)
rule = ('mkfunc_annotate ::= %s%sannotate_tuple LOAD_CONST LOAD_CONST EXTENDED_ARG %s' %
(('pos_arg ' * (args_pos)),
@@ -966,7 +966,7 @@ class Python3Parser(PythonParser):
self.add_unique_rule(rule, opname, token.attr, customize)
rule = ('mkfunc_annotate ::= %s%sannotate_tuple LOAD_CONST EXTENDED_ARG %s' %
(('pos_arg ' * (args_pos)),
('call_function ' * (annotate_args-1)), opname))
('call ' * (annotate_args-1)), opname))
self.add_unique_rule(rule, opname, token.attr, customize)
elif opname_base in ('UNPACK_EX',):
before_count, after_count = token.attr

View File

@@ -157,7 +157,7 @@ class Python35Parser(Python34Parser):
self.add_unique_rule(rule, opname, token.attr, customize)
call_token = tokens[i+1]
if self.version == 3.5:
rule = 'call_function ::= expr unmapexpr ' + call_token.kind
rule = 'call ::= expr unmapexpr ' + call_token.kind
self.add_unique_rule(rule, opname, token.attr, customize)
pass
pass

View File

@@ -24,14 +24,14 @@ class Python36Parser(Python35Parser):
fstring_expr_or_strs ::= fstring_expr_or_str+
func_args36 ::= expr BUILD_TUPLE_0
call_function ::= func_args36 unmapexpr CALL_FUNCTION_EX
call_function ::= func_args36 build_map_unpack_with_call CALL_FUNCTION_EX_KW_1
call ::= func_args36 unmapexpr CALL_FUNCTION_EX
call ::= func_args36 build_map_unpack_with_call CALL_FUNCTION_EX_KW_1
withstmt ::= expr SETUP_WITH POP_TOP suite_stmts_opt POP_BLOCK LOAD_CONST
WITH_CLEANUP_START WITH_CLEANUP_FINISH END_FINALLY
withstmt ::= expr SETUP_WITH POP_TOP suite_stmts_opt POP_BLOCK LOAD_CONST
WITH_CLEANUP_START WITH_CLEANUP_FINISH END_FINALLY
call_function ::= expr expr CALL_FUNCTION_EX
call_function ::= expr expr expr CALL_FUNCTION_EX_KW_1
call ::= expr expr CALL_FUNCTION_EX
call ::= expr expr expr CALL_FUNCTION_EX_KW_1
# This might be valid in < 3.6
and ::= expr jmp_false expr
@@ -103,7 +103,7 @@ class Python36Parser(Python35Parser):
seen_GET_AWAITABLE_YIELD_FROM, next_token):
if opname.startswith('CALL_FUNCTION_KW'):
values = 'expr ' * token.attr
rule = 'call_function ::= expr kwargs_only_36 {token.kind}'.format(**locals())
rule = 'call ::= expr kwargs_only_36 {token.kind}'.format(**locals())
self.add_unique_rule(rule, token.kind, token.attr, customize)
rule = 'kwargs_only_36 ::= {values} LOAD_CONST'.format(**locals())
self.add_unique_rule(rule, token.kind, token.attr, customize)

View File

@@ -287,8 +287,8 @@ MAP_R0 = (TABLE_R0, -1, 0)
MAP_R = (TABLE_R, -1)
MAP = {
'stmt': MAP_R,
'call_function': MAP_R,
'stmt': MAP_R,
'call': MAP_R,
'del_stmt': MAP_R,
'designator': MAP_R,
'exprlist': MAP_R0,
@@ -316,7 +316,7 @@ PRECEDENCE = {
'slice3': 2,
'buildslice2': 2,
'buildslice3': 2,
'call_function': 2,
'call': 2,
'BINARY_POWER': 4,

View File

@@ -1623,10 +1623,8 @@ class FragmentsWalker(pysource.SourceWalker, object):
# 2. subroutine calls. It the last op is the call and for purposes of printing
# we don't need to print anything special there. However it encompases the
# entire string of the node fn(...)
match = re.search(r'^call_function', startnode.kind)
if match:
if startnode.kind == 'call':
last_node = startnode[-1]
# import traceback; traceback.print_stack()
self.set_pos_info(last_node, startnode_start, self.last_finish)
return

View File

@@ -435,21 +435,21 @@ class SourceWalker(GenericASTTraversal, object):
'trystmt36': ( '%|try:\n%+%c%-%c\n\n', 1, 2 ),
})
def n_async_call_function(node):
def n_async_call(node):
self.f.write('async ')
node.kind == 'call_function'
node.kind == 'call'
p = self.prec
self.prec = 80
self.template_engine(('%c(%P)', 0,
(1, -4, ', ', 100)), node)
self.prec = p
node.kind == 'async_call_function'
node.kind == 'async_call'
self.prune()
self.n_async_call_function = n_async_call_function
self.n_async_call = n_async_call
self.n_build_list_unpack = self.n_build_list
if version == 3.5:
def n_call_function(node):
def n_call(node):
mapping = self._get_mapping(node)
table = mapping[0]
key = node
@@ -472,7 +472,7 @@ class SourceWalker(GenericASTTraversal, object):
args_pos = kwarg_pos
kwarg_pos += 1
self.default(node)
self.n_call_function = n_call_function
self.n_call = n_call
def n_funcdef(node):
if self.version == 3.6: