Commit fdf5beeb authored by Stefan Behnel's avatar Stefan Behnel

allow keyword arguments after *args in a function call (as Py3 does)

some EncodedString name fixes for function names
parent 809008a6
...@@ -297,32 +297,37 @@ def p_call(s, function): ...@@ -297,32 +297,37 @@ def p_call(s, function):
keyword_args = [] keyword_args = []
star_arg = None star_arg = None
starstar_arg = None starstar_arg = None
while s.sy not in ('*', '**', ')'): while s.sy not in ('**', ')'):
arg = p_simple_expr(s) if s.sy == '*':
if s.sy == '=': if star_arg:
s.error("only one star-arg parameter allowed",
pos = s.position())
s.next() s.next()
if not arg.is_name: star_arg = p_simple_expr(s)
s.error("Expected an identifier before '='",
pos = arg.pos)
encoded_name = EncodedString(arg.name)
keyword = ExprNodes.IdentifierStringNode(arg.pos,
value = encoded_name)
arg = p_simple_expr(s)
keyword_args.append((keyword, arg))
else: else:
if keyword_args: arg = p_simple_expr(s)
s.error("Non-keyword arg following keyword arg", if s.sy == '=':
pos = arg.pos) s.next()
positional_args.append(arg) if not arg.is_name:
s.error("Expected an identifier before '='",
pos = arg.pos)
encoded_name = EncodedString(arg.name)
keyword = ExprNodes.IdentifierStringNode(arg.pos,
value = encoded_name)
arg = p_simple_expr(s)
keyword_args.append((keyword, arg))
else:
if keyword_args:
s.error("Non-keyword arg following keyword arg",
pos = arg.pos)
if star_arg:
s.error("Non-keyword arg following star-arg",
pos = arg.pos)
positional_args.append(arg)
if s.sy != ',': if s.sy != ',':
break break
s.next() s.next()
if s.sy == '*':
s.next()
star_arg = p_simple_expr(s)
if s.sy == ',':
s.next()
if s.sy == '**': if s.sy == '**':
s.next() s.next()
starstar_arg = p_simple_expr(s) starstar_arg = p_simple_expr(s)
...@@ -1738,7 +1743,7 @@ def p_c_declarator(s, ctx = Ctx(), empty = 0, is_type = 0, cmethod_flag = 0, ...@@ -1738,7 +1743,7 @@ def p_c_declarator(s, ctx = Ctx(), empty = 0, is_type = 0, cmethod_flag = 0,
if s.sy == '(': if s.sy == '(':
s.next() s.next()
if s.sy == ')' or looking_at_type(s): if s.sy == ')' or looking_at_type(s):
base = Nodes.CNameDeclaratorNode(pos, name = "", cname = None) base = Nodes.CNameDeclaratorNode(pos, name = EncodedString(u""), cname = None)
result = p_c_func_declarator(s, pos, ctx, base, cmethod_flag) result = p_c_func_declarator(s, pos, ctx, base, cmethod_flag)
else: else:
result = p_c_declarator(s, ctx, empty = empty, is_type = is_type, result = p_c_declarator(s, ctx, empty = empty, is_type = is_type,
...@@ -1808,7 +1813,7 @@ def p_c_simple_declarator(s, ctx, empty, is_type, cmethod_flag, ...@@ -1808,7 +1813,7 @@ def p_c_simple_declarator(s, ctx, empty, is_type, cmethod_flag,
else: else:
rhs = None rhs = None
if s.sy == 'IDENT': if s.sy == 'IDENT':
name = s.systring name = EncodedString(s.systring)
if is_type: if is_type:
s.add_type_name(name) s.add_type_name(name)
if empty: if empty:
...@@ -2171,7 +2176,7 @@ def p_def_statement(s, decorators=None): ...@@ -2171,7 +2176,7 @@ def p_def_statement(s, decorators=None):
# s.sy == 'def' # s.sy == 'def'
pos = s.position() pos = s.position()
s.next() s.next()
name = p_ident(s) name = EncodedString( p_ident(s) )
#args = [] #args = []
s.expect('('); s.expect('(');
args = p_c_arg_list(s, in_pyfunc = 1, nonempty_declarators = 1) args = p_c_arg_list(s, in_pyfunc = 1, nonempty_declarators = 1)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment