From: Kevin Date: Sun, 10 May 2020 21:34:50 +0000 (-0400) Subject: Fix AST for conditional expressions X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=9e94e24afd92b2317768f11d991bf51eed2c7adf;p=thirdparty%2Fjinja.git Fix AST for conditional expressions Previously all conditional expressions were left associative which produced an AST that was nothing like the one in Jinja and one which did not respect order of operations within conditions. The conditional expression part of the grammar has been rewritten to be more explicit about what can and cannot match which appears to have fixed those issues with the AST. --- diff --git a/grammar.ebnf b/grammar.ebnf index f04cede1..0c47bba9 100644 --- a/grammar.ebnf +++ b/grammar.ebnf @@ -212,17 +212,45 @@ variable_accessor_call_parameter_key variable_accessor_call_parameter_value = - | variable_tests + | conditional_expression | variable_identifier ; +conditional_expression + = + | conditional_expression_logical + | conditional_expression_comparator + | conditional_expression_test + ; + +conditional_expression_logical + = + left:conditional_expression + {SP}* logical_operator:variable_tests_logical_operator {SP}* + right:conditional_expression + ; + +conditional_expression_comparator + = + left:variable_identifier + {SP}* comparator:variable_tests_comparator {SP}* + right:variable_identifier + ; + +conditional_expression_test + = + test_variable:variable_identifier + {SP}* "is" {SP}* + test_function:variable_identifier + ; + variable_tests = - left:variable_identifier {SP}* + left:variable_tests {SP}* ( + | ( logical_operator:variable_tests_logical_operator {SP}* right:variable_tests ) + | ( comparator:variable_tests_comparator {SP}* right:variable_tests ) | ( "is" {SP}* test_function:variable_accessor_call_parameter_value ) - | ( comparator:variable_tests_comparator {SP}* right:variable_accessor_call_parameter_value ) - | ( logical_operator:variable_tests_logical_operator {SP}* right:variable_accessor_call_parameter_value ) ) ;