Properly handle implicit tuples

This adds support for implicit tuple literals and removes support for
identifier tuples for now.
This commit is contained in:
Kevin Brown 2020-05-16 17:09:24 -04:00
parent a3aa821a5f
commit 0581e3d8bd
2 changed files with 21 additions and 25 deletions

View File

@ -134,11 +134,6 @@ line_block_parameters
@+:block_parameter { { !"\n" SP }+ @+:block_parameter }*
;
implicit_identifier_tuple
=
tuple+:IDENTIFIER { {SP}* "," {SP}* tuple+:IDENTIFIER }+
;
block_parameters
=
@+:block_parameter
@ -167,13 +162,11 @@ block_parameter_key_value
block_parameter_key
=
| implicit_identifier_tuple
| variable_accessor_call_parameter_key
variable_accessor_call_parameter_key
;
block_parameter_value_only
=
| value:implicit_identifier_tuple
| value:variable_identifier_with_alias
| value:variable_accessor_call_parameter_value
| value:conditional_expression
@ -560,11 +553,29 @@ TUPLE_LITERAL
=
literal_type:`tuple`
(
| ( "(" {SP}* value+:LITERAL {SP}* { "," {SP}* value+:LITERAL {SP}* }+ ")" )
| ( "(" {SP}* value+:LITERAL {SP}* "," {SP}* ")" )
| value:EXPLICIT_TUPLE_LITERAL
| value:IMPLICIT_TUPLE_LITERAL
| EMPTY_TUPLE_LITERAL
)
;
EXPLICIT_TUPLE_LITERAL
=
| ( "(" {SP}* @+:LITERAL {SP}* { "," {SP}* @+:LITERAL {SP}* }+ ")" )
| ( "(" {SP}* @+:LITERAL {SP}* "," {SP}* ")" )
;
IMPLICIT_TUPLE_LITERAL
=
| ( @+:LITERAL {SP}* { "," {SP}* @+:LITERAL {SP}* }+ )
| ( @+:LITERAL {SP}* "," {SP}* )
;
EMPTY_TUPLE_LITERAL
=
"(" {SP}* ")"
;
INTEGER_LITERAL
=
/[\d_]*\d+/

View File

@ -837,9 +837,6 @@ def parse_template(ast):
return nodes.Template(parse(ast), lineno=1)
def parse_variable(ast, variable_context='load'):
if 'tuple' in ast:
return parse_variable_tuple(ast, variable_context)
name = ast['variable']
if 'literal_type' in name:
@ -980,18 +977,6 @@ def parse_variable_filter(node, ast):
return last_filter
def parse_variable_tuple(ast, variable_context):
identifiers = []
for name in ast['tuple']:
identifiers.append(nodes.Name(name, variable_context))
return nodes.Tuple(
identifiers,
variable_context,
lineno=lineno_from_parseinfo(ast['parseinfo'])
)
def _parse_import_context(block_parameters):
if block_parameters[-1]['value']['variable'] != 'context':
return None