Support chained comparisons in parser

This commit is contained in:
Kevin Brown 2020-05-15 10:32:07 -04:00
parent 4ebdaf162e
commit 52a618e587
2 changed files with 25 additions and 7 deletions

View File

@ -332,7 +332,7 @@ conditional_expression_operator
| (
left:variable_identifier
{SP}* operator:conditional_expression_operator_operations {SP}*
right:variable_identifier
right:conditional_expression
)
;

View File

@ -539,14 +539,32 @@ def parse_conditional_expression_operator(ast):
'<=': 'lteq',
}
return nodes.Compare(
parse_variable(ast['left']),
[
expr = parse_variable(ast['left'])
operator = operand_map.get(ast['operator'], ast['operator'])
operands = []
right = parse_conditional_expression(ast['right'])
if isinstance(right, nodes.Compare):
operands.append(
nodes.Operand(
operand_map.get(ast['operator'], ast['operator']),
parse_variable(ast['right'])
operator,
right.expr
)
],
)
operands.extend(right.ops)
else:
operands.append(
nodes.Operand(
operator,
right
)
)
return nodes.Compare(
expr,
operands,
lineno=lineno_from_parseinfo(ast['parseinfo'])
)