]> git.ipfire.org Git - thirdparty/jinja.git/commitdiff
Add support for "None" and "none" to grammar/parser
authorKevin <kevin@kevin-brown.com>
Tue, 12 May 2020 00:19:42 +0000 (20:19 -0400)
committerKevin <kevin@kevin-brown.com>
Tue, 12 May 2020 00:19:42 +0000 (20:19 -0400)
grammar.ebnf
new_parser.py
test_template.jinja

index 0f97c06f4d2f147b960dedf63f2a36256c7cc40a..eae5e8d018be1899a7f0147b6357df5d8e54a88a 100644 (file)
@@ -326,6 +326,7 @@ content
 \r
 LITERAL\r
     =\r
+    | NONE_LITERAL\r
     | STRING_LITERAL\r
     | NUMBER_LITERAL\r
     | BOOLEAN_LITERAL\r
@@ -406,6 +407,12 @@ BOOLEAN_LITERAL
     )\r
     ;\r
 \r
+NONE_LITERAL\r
+    =\r
+    literal_type:`none`\r
+    ( "none" | "None" ) value:`None`\r
+    ;\r
+\r
 IDENTIFIER\r
     =\r
     /[a-zA-Z_][a-zA-Z0-9_]*/\r
index 6edd0f7a7a2298293658008410ecb07d4dc31b21..4b93237e32e44910644065bd143e902816add580 100644 (file)
@@ -395,6 +395,11 @@ def parse_literal(ast):
             items,\r
             lineno=lineno_from_parseinfo(ast['parseinfo'])\r
         )\r
+    elif literal_type == 'none':\r
+        return nodes.Const(\r
+            None,\r
+            lineno=lineno_from_parseinfo(ast['parseinfo'])\r
+        )\r
     elif literal_type == 'list':\r
         items = [\r
             parse_literal(item) for item in ast['value']\r
index 2ce47be142cfa64ea6c724176ebf546b51ef35b3..e1044544b1e5d2188c1e7c8b31e726b8e2cd5126 100644 (file)
@@ -60,3 +60,7 @@ across lines #}
 {% if foo.attribute is sameas false %}\r
     the foo attribute really is the `False` singleton\r
 {% endif %}\r
+<ul{{ {'class': 'my_list', 'missing': none,\r
+        'id': 'list-%d'|format(variable)}|xmlattr }}>\r
+...\r
+</ul>
\ No newline at end of file