From: Kevin Date: Tue, 12 May 2020 00:19:42 +0000 (-0400) Subject: Add support for "None" and "none" to grammar/parser X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=0d9afd99ed9a78ee8d016039847bef38bfefb747;p=thirdparty%2Fjinja.git Add support for "None" and "none" to grammar/parser --- diff --git a/grammar.ebnf b/grammar.ebnf index 0f97c06f..eae5e8d0 100644 --- a/grammar.ebnf +++ b/grammar.ebnf @@ -326,6 +326,7 @@ content LITERAL = + | NONE_LITERAL | STRING_LITERAL | NUMBER_LITERAL | BOOLEAN_LITERAL @@ -406,6 +407,12 @@ BOOLEAN_LITERAL ) ; +NONE_LITERAL + = + literal_type:`none` + ( "none" | "None" ) value:`None` + ; + IDENTIFIER = /[a-zA-Z_][a-zA-Z0-9_]*/ diff --git a/new_parser.py b/new_parser.py index 6edd0f7a..4b93237e 100644 --- a/new_parser.py +++ b/new_parser.py @@ -395,6 +395,11 @@ def parse_literal(ast): items, lineno=lineno_from_parseinfo(ast['parseinfo']) ) + elif literal_type == 'none': + return nodes.Const( + None, + lineno=lineno_from_parseinfo(ast['parseinfo']) + ) elif literal_type == 'list': items = [ parse_literal(item) for item in ast['value'] diff --git a/test_template.jinja b/test_template.jinja index 2ce47be1..e1044544 100644 --- a/test_template.jinja +++ b/test_template.jinja @@ -60,3 +60,7 @@ across lines #} {% if foo.attribute is sameas false %} the foo attribute really is the `False` singleton {% endif %} + +... + \ No newline at end of file