From: Kevin Date: Tue, 12 May 2020 02:27:38 +0000 (-0400) Subject: Add support for negated test expressions X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=05d348e29d0528cdae6f2d8bd8048fd9c84bde6f;p=thirdparty%2Fjinja.git Add support for negated test expressions --- diff --git a/grammar.ebnf b/grammar.ebnf index ca6a1992..4933af72 100644 --- a/grammar.ebnf +++ b/grammar.ebnf @@ -280,7 +280,9 @@ conditional_expression_operator_in conditional_expression_test = test_variable:variable_identifier - {SP}* "is" {SP}* + {SP}* "is" + [ {SP}+ "not" {SP} negated:`True` ] + {SP}* test_function:variable_identifier [ {SP}* diff --git a/new_parser.py b/new_parser.py index dddae2ba..a14000d7 100644 --- a/new_parser.py +++ b/new_parser.py @@ -391,7 +391,7 @@ def parse_conditional_expression_test(ast): parse_variable(ast['test_function_parameter']) ] - return nodes.Test( + test_node = nodes.Test( node, name, args, @@ -401,6 +401,14 @@ def parse_conditional_expression_test(ast): lineno=lineno_from_parseinfo(ast['parseinfo']) ) + if 'negated' in ast and ast['negated']: + test_node = nodes.Not( + test_node, + lineno=lineno_from_parseinfo(ast['parseinfo']) + ) + + return test_node + def parse_literal(ast): if 'literal_type' not in ast: raise