Commit c0fb8492 authored by Robert Bradshaw's avatar Robert Bradshaw

Simplify p_positional_and_keyword_args with s.peek()

parent 69160834
...@@ -1747,31 +1747,24 @@ def p_positional_and_keyword_args(s, end_sy_set, type_positions=(), type_keyword ...@@ -1747,31 +1747,24 @@ def p_positional_and_keyword_args(s, end_sy_set, type_positions=(), type_keyword
was_keyword = False was_keyword = False
parsed_type = False parsed_type = False
if s.sy == 'IDENT': if s.sy == 'IDENT' and s.peek()[0] == '=':
# Since we can have either types or expressions as positional args,
# we use a strategy of looking an extra step forward for a '=' and
# if it is a positional arg we backtrack.
ident = s.systring ident = s.systring
s.next() # s.sy is '='
s.next() s.next()
if s.sy == '=': if type_keywords is None or ident in type_keywords:
s.next() base_type = p_c_base_type(s)
# Is keyword arg declarator = p_c_declarator(s, empty = 1)
if type_keywords is None or ident in type_keywords: arg = Nodes.CComplexBaseTypeNode(base_type.pos,
base_type = p_c_base_type(s) base_type = base_type, declarator = declarator)
declarator = p_c_declarator(s, empty = 1) parsed_type = True
arg = Nodes.CComplexBaseTypeNode(base_type.pos,
base_type = base_type, declarator = declarator)
parsed_type = True
else:
arg = p_simple_expr(s)
keyword_node = ExprNodes.IdentifierStringNode(
arg.pos, value = EncodedString(ident))
keyword_args.append((keyword_node, arg))
was_keyword = True
else: else:
s.put_back('IDENT', ident) arg = p_simple_expr(s)
keyword_node = ExprNodes.IdentifierStringNode(
arg.pos, value = EncodedString(ident))
keyword_args.append((keyword_node, arg))
was_keyword = True
if not was_keyword: else:
if type_positions is None or pos_idx in type_positions: if type_positions is None or pos_idx in type_positions:
base_type = p_c_base_type(s) base_type = p_c_base_type(s)
declarator = p_c_declarator(s, empty = 1) declarator = p_c_declarator(s, empty = 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