arglist rearrangement

This commit is contained in:
Anthony Scopatz 2015-09-26 16:18:47 -04:00
parent 39f04896f7
commit e7df9fbe46

View file

@ -199,7 +199,7 @@ class Parser(object):
self.lexer = lexer = Lexer() self.lexer = lexer = Lexer()
self.tokens = lexer.tokens self.tokens = lexer.tokens
opt_rules = ( opt_rules = [
'newlines', 'arglist', 'func_call', 'rarrow_test', 'typedargslist', 'newlines', 'arglist', 'func_call', 'rarrow_test', 'typedargslist',
'equals_test', 'colon_test', 'tfpdef', 'comma_tfpdef_list', 'equals_test', 'colon_test', 'tfpdef', 'comma_tfpdef_list',
'comma_pow_tfpdef', 'vfpdef', 'comma_vfpdef_list', 'comma_pow_tfpdef', 'vfpdef', 'comma_vfpdef_list',
@ -213,12 +213,13 @@ class Parser(object):
'op_factor_list', 'trailer_list', 'testlist_comp', 'op_factor_list', 'trailer_list', 'testlist_comp',
'yield_expr_or_testlist_comp', 'dictorsetmaker', 'yield_expr_or_testlist_comp', 'dictorsetmaker',
'comma_subscript_list', 'test', 'sliceop', 'comp_iter', 'comma_subscript_list', 'test', 'sliceop', 'comp_iter',
'yield_arg', 'argument_comma_list', 'comma_argument_list', 'yield_arg', 'test_comma_list',]
'test_comma_list', ) if VER_MAJOR_MINOR <= VER_3_4:
opt_rules += ['argument_comma_list', 'comma_argument_list',]
for rule in opt_rules: for rule in opt_rules:
self._opt_rule(rule) self._opt_rule(rule)
list_rules = ( list_rules = [
'comma_tfpdef', 'comma_vfpdef', 'semi_small_stmt', 'comma_tfpdef', 'comma_vfpdef', 'semi_small_stmt',
'comma_test_or_star_expr', 'period_or_ellipsis', 'comma_test_or_star_expr', 'period_or_ellipsis',
'comma_import_as_name', 'comma_dotted_as_name', 'period_name', 'comma_import_as_name', 'comma_dotted_as_name', 'period_name',
@ -226,9 +227,10 @@ class Parser(object):
'or_and_test', 'and_not_test', 'comp_op_expr', 'pipe_xor_expr', 'or_and_test', 'and_not_test', 'comp_op_expr', 'pipe_xor_expr',
'xor_and_expr', 'ampersand_shift_expr', 'shift_arith_expr', 'xor_and_expr', 'ampersand_shift_expr', 'shift_arith_expr',
'pm_term', 'op_factor', 'trailer', 'comma_subscript', 'pm_term', 'op_factor', 'trailer', 'comma_subscript',
'comma_expr_or_star_expr', 'comma_test', 'argument_comma', 'comma_expr_or_star_expr', 'comma_test', 'comma_argument', 'comma_item',
'comma_argument', 'comma_item', 'attr_period_name', 'test_comma', 'attr_period_name', 'test_comma', 'equals_yield_expr_or_testlist', ]
'equals_yield_expr_or_testlist', ) if VER_MAJOR_MINOR <= VER_3_4:
list_rules += ['argument_comma',]
for rule in list_rules: for rule in list_rules:
self._list_rule(rule) self._list_rule(rule)
@ -1978,61 +1980,79 @@ class Parser(object):
else: else:
args['args'].append(arg) args['args'].append(arg)
def p_arglist(self, p): #
"""arglist : argument comma_opt # arglist rule had significant changes
| argument_comma_list argument comma_opt #
| argument_comma_list_opt TIMES test comma_argument_list_opt if VER_3_5 <= VER_MAJOR_MINOR:
| argument_comma_list_opt TIMES test COMMA POW test def p_arglist(self, p):
| argument_comma_list_opt TIMES test comma_argument_list COMMA POW test """arglist : argument comma_opt
| argument_comma_list_opt POW test | argument comma_argument_list comma_opt
""" """
lenp = len(p) p0 = {'args': [], 'keywords': []}
p1, p2 = p[1], p[2] p1, p2 = p[1], p[2]
p0 = {'args': [], 'keywords': [], 'starargs': None, 'kwargs': None} p2 = None if p2 == ',' else p2
if lenp == 3:
self._set_arg(p0, p1) self._set_arg(p0, p1)
elif lenp == 4 and p2 != '**': if p2 is not None:
for arg in p1: for arg in p2:
self._set_arg(p0, arg) self._set_arg(p0, arg)
self._set_arg(p0, p2) p[0] = p0
elif lenp == 4 and p2 == '**': else: # Python v3.4
if p1 is not None: def p_arglist(self, p):
"""arglist : argument comma_opt
| argument_comma_list argument comma_opt
| argument_comma_list_opt TIMES test comma_argument_list_opt
| argument_comma_list_opt TIMES test COMMA POW test
| argument_comma_list_opt TIMES test comma_argument_list COMMA POW test
| argument_comma_list_opt POW test
"""
lenp = len(p)
p1, p2 = p[1], p[2]
p0 = {'args': [], 'keywords': [], 'starargs': None, 'kwargs': None}
if lenp == 3:
self._set_arg(p0, p1)
elif lenp == 4 and p2 != '**':
for arg in p1: for arg in p1:
self._set_arg(p0, arg) self._set_arg(p0, arg)
self._set_arg(p0, p[3], ensure_kw=True) self._set_arg(p0, p2)
elif lenp == 5: elif lenp == 4 and p2 == '**':
p0['starargs'], p4 = p[3], p[4] if p1 is not None:
if p1 is not None: for arg in p1:
for arg in p1: self._set_arg(p0, arg)
self._set_arg(p0, arg) self._set_arg(p0, p[3], ensure_kw=True)
if p4 is not None: elif lenp == 5:
p0['starargs'], p4 = p[3], p[4]
if p1 is not None:
for arg in p1:
self._set_arg(p0, arg)
if p4 is not None:
for arg in p4:
self._set_arg(p0, arg, ensure_kw=True)
elif lenp == 7:
p0['starargs'] = p[3]
if p1 is not None:
for arg in p1:
self._set_arg(p0, arg)
self._set_arg(p0, p[6], ensure_kw=True)
elif lenp == 8:
kwkey = 'keywords' if VER_MAJOR_MINOR >= VER_3_5 else 'kwargs'
p0['starargs'], p4 = p[3], p[4]
if p1 is not None:
for arg in p1:
self._set_arg(p0, arg)
for arg in p4: for arg in p4:
self._set_arg(p0, arg, ensure_kw=True) self._set_arg(p0, arg, ensure_kw=True)
elif lenp == 7: self._set_arg(p0, p[7], ensure_kw=True)
p0['starargs'] = p[3] else:
if p1 is not None: assert False
for arg in p1: p[0] = p0
self._set_arg(p0, arg)
self._set_arg(p0, p[6], ensure_kw=True)
elif lenp == 8:
kwkey = 'keywords' if VER_MAJOR_MINOR >= VER_3_5 else 'kwargs'
p0['starargs'], p4 = p[3], p[4]
if p1 is not None:
for arg in p1:
self._set_arg(p0, arg)
for arg in p4:
self._set_arg(p0, arg, ensure_kw=True)
self._set_arg(p0, p[7], ensure_kw=True)
else:
assert False
p[0] = p0
def p_argument_comma(self, p): if VER_MAJOR_MINOR <= VER_3_4:
"""argument_comma : argument COMMA""" def p_argument_comma(self, p):
p[0] = [p[1]] """argument_comma : argument COMMA"""
p[0] = [p[1]]
def p_comma_argument(self, p): def p_comma_argument(self, p):
"""comma_argument : COMMA argument """ """comma_argument : COMMA argument"""
p[0] = [p[2]] p[0] = [p[2]]
@docstring_by_version( @docstring_by_version(