From: Kevin Brown Date: Fri, 8 May 2020 20:56:26 +0000 (-0400) Subject: Support implicit tuples in block parameters X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=7949f22fd19b4256ec52f91d6de231cd4043e2d4;p=thirdparty%2Fjinja.git Support implicit tuples in block parameters This fixes an issue where implicit tuples were not parsed correctly when they were used as a key in a block parameter. Now for loops and set statements with implicit tuples work properly. This only supports implicit tuples when all values are identifiers, since these are generally used for assignment and you cannot assign a new value to a literal. --- diff --git a/tatsu_grammar.txt b/tatsu_grammar.txt index a0d21e3a..d74e998f 100644 --- a/tatsu_grammar.txt +++ b/tatsu_grammar.txt @@ -39,7 +39,7 @@ block_expression block_start = - block_open type:`blockstart` !("end") name:IDENTIFIER parameters:[ { assignment_target }* ] block_close + block_open type:`blockstart` !("end") name:IDENTIFIER parameters:[ { block_parameter }* ] block_close ; block_end @@ -56,15 +56,29 @@ block_close {SP}* @:"%}" ; -assignment_target +implicit_identifier_tuple = - tuple+:block_parameter {"," {SP}* tuple+:block_parameter}+ - | block_parameter + {SP}* tuple+:IDENTIFIER {SP}* { "," {SP}* tuple+:IDENTIFIER {SP}* }+ ; block_parameter = - variable_accessor_call_parameter + block_parameter_key_value | block_parameter_value_only + ; + +block_parameter_key_value + = + key:block_parameter_key "=" value:variable_accessor_call_parameter_value + ; + +block_parameter_key + = + implicit_identifier_tuple | variable_accessor_call_parameter_key + ; + +block_parameter_value_only + = + value:implicit_identifier_tuple | value:variable_accessor_call_parameter_value ; variable_expression @@ -115,7 +129,7 @@ variable_accessor_call_parameter variable_accessor_call_parameter_key_value = - {SP}* key:IDENTIFIER {SP}* "=" value:variable_accessor_call_parameter_value {SP}* + key:variable_accessor_call_parameter_key "=" value:variable_accessor_call_parameter_value {SP}* ; variable_accessor_call_parameter_value_only @@ -123,6 +137,11 @@ variable_accessor_call_parameter_value_only value:variable_accessor_call_parameter_value ; +variable_accessor_call_parameter_key + = + {SP}* key:IDENTIFIER {SP}* + ; + variable_accessor_call_parameter_value = {SP}* @:( variable_tests | variable_identifier ) {SP}*