]> git.ipfire.org Git - thirdparty/jinja.git/commitdiff
Add support dictionary literals to grammar
authorKevin <kevin@kevin-brown.com>
Tue, 12 May 2020 00:14:40 +0000 (20:14 -0400)
committerKevin <kevin@kevin-brown.com>
Tue, 12 May 2020 00:14:40 +0000 (20:14 -0400)
This also allows dictionary values to be variables instead of just
regular identifiers, a change which might be made to other literals
such as lists and tuples in the future as we determine what those
also support.

grammar.ebnf

index 53bb82546c9c5a803d655fefeb2da26920939e60..0f97c06f4d2f147b960dedf63f2a36256c7cc40a 100644 (file)
@@ -329,10 +329,25 @@ LITERAL
     | STRING_LITERAL\r
     | NUMBER_LITERAL\r
     | BOOLEAN_LITERAL\r
+    | DICTIONARY_LITERAL\r
     | LIST_LITERAL\r
     | TUPLE_LITERAL\r
     ;\r
 \r
+DICTIONARY_LITERAL\r
+    =\r
+    literal_type:`dictionary`\r
+    (\r
+        | ( "{" {SP}* value+:dictionary_key_value { {SP}* "," {SP}* value+:dictionary_key_value } {SP}* "}" )\r
+        | ( "{" {SP}* "}" )\r
+    )\r
+    ;\r
+\r
+dictionary_key_value\r
+    =\r
+    key:STRING_LITERAL {SP}* ":" {SP}* value:variable_identifier\r
+    ;\r
+\r
 LIST_LITERAL\r
     =\r
     literal_type:`list`\r