Only support implicit tuples in variable expressions

They cause super inconsistent parsing behaviour if they show up
pretty much anywhere else because there is no difference between an
implicit tuple and a set of comma-separated parameters.
This commit is contained in:
Kevin Brown 2020-05-16 17:54:52 -04:00
parent 7151d778c4
commit 7e67623cbf
2 changed files with 26 additions and 13 deletions

View File

@ -174,7 +174,7 @@ block_parameter_value_only
variable_expression
=
variable_open type:`variable` name:conditional_expression variable_close
variable_open type:`variable` name:variable_expression_name variable_close
;
variable_open
@ -199,6 +199,12 @@ variable_close_symbol
"}}"
;
variable_expression_name
=
| TUPLE_LITERAL
| conditional_expression
;
variable_identifier
=
| variable_identifier_parentheses
@ -523,7 +529,7 @@ LITERAL
| BOOLEAN_LITERAL
| DICTIONARY_LITERAL
| LIST_LITERAL
| TUPLE_LITERAL
| EXPLICIT_TUPLE_LITERAL
;
DICTIONARY_LITERAL
@ -551,28 +557,32 @@ LIST_LITERAL
TUPLE_LITERAL
=
literal_type:`tuple`
(
| value:EXPLICIT_TUPLE_LITERAL
| value:IMPLICIT_TUPLE_LITERAL
| EMPTY_TUPLE_LITERAL
)
| EXPLICIT_TUPLE_LITERAL
| IMPLICIT_TUPLE_LITERAL
| EMPTY_TUPLE_LITERAL
;
EXPLICIT_TUPLE_LITERAL
=
| ( "(" {SP}* @+:LITERAL {SP}* { "," {SP}* @+:LITERAL {SP}* }+ ")" )
| ( "(" {SP}* @+:LITERAL {SP}* "," {SP}* ")" )
literal_type:`tuple`
"(" value:TUPLE_LITERAL_CONTENTS ")"
;
IMPLICIT_TUPLE_LITERAL
=
| ( @+:LITERAL {SP}* { "," {SP}* @+:LITERAL {SP}* }+ )
| ( @+:LITERAL {SP}* "," {SP}* )
literal_type:`tuple`
value:TUPLE_LITERAL_CONTENTS
;
TUPLE_LITERAL_CONTENTS
=
| ( @+:variable_identifier {SP}* { "," {SP}* @+:variable_identifier {SP}* }+ )
| ( @+:variable_identifier {SP}* "," {SP}* )
;
EMPTY_TUPLE_LITERAL
=
literal_type:`tuple`
"(" {SP}* ")"
;

View File

@ -564,6 +564,9 @@ def parse_conditional_expression(ast):
if 'variable' in ast:
return parse_variable(ast)
if 'literal_type' in ast:
return parse_literal(ast)
if 'concatenate' in ast:
return parse_concatenate_expression(ast)
@ -806,7 +809,7 @@ def parse_literal(ast):
ast['value'] = []
items = [
parse_literal(item) for item in ast['value']
parse_variable(item) for item in ast['value']
]
return nodes.Tuple(