Added grammar for for loops
Since this needs to support assignment targets, it is difficult to properly support this within a generic block syntax because of the ability to create implicit tuples.
This commit is contained in:
parent
caf8992e99
commit
f69ad20fb5
@ -11,7 +11,7 @@ expressions
|
||||
|
||||
expression
|
||||
=
|
||||
content | raw_block_expression | block_expression | variable_expression | comment_expression
|
||||
content | raw_block_expression | functional_block_expression | variable_expression | comment_expression
|
||||
;
|
||||
|
||||
raw_block_expression
|
||||
@ -31,6 +31,32 @@ raw_block_end
|
||||
block_open "endraw" block_close
|
||||
;
|
||||
|
||||
functional_block_expression
|
||||
=
|
||||
for_block_expression | block_expression
|
||||
;
|
||||
|
||||
for_block_expression
|
||||
=
|
||||
for_block_start {SP}* expressions {SP}* for_block_end
|
||||
;
|
||||
|
||||
for_block_start
|
||||
=
|
||||
block_open type:`blockstart` name:"for" {SP}* target:assignment_target {SP}* "in" {SP}* iter:variable_accessor_call_parameter_value [ {SP}* recursive:`True` "recursive" ] block_close
|
||||
;
|
||||
|
||||
for_block_end
|
||||
=
|
||||
block_open "endfor" block_close
|
||||
;
|
||||
|
||||
assignment_target
|
||||
=
|
||||
tuple+:block_parameter {"," {SP}* tuple+:block_parameter}+
|
||||
| block_parameter
|
||||
;
|
||||
|
||||
block_expression
|
||||
=
|
||||
block_start {SP}* expressions {SP}* block_end
|
||||
@ -39,7 +65,7 @@ block_expression
|
||||
|
||||
block_start
|
||||
=
|
||||
block_open type:`blockstart` !("end") name:IDENTIFIER parameters:[{block_parameter}*] block_close
|
||||
block_open type:`blockstart` !("end") name:IDENTIFIER parameters:[ { block_parameter }* ] block_close
|
||||
;
|
||||
|
||||
block_end
|
||||
|
||||
@ -14,7 +14,7 @@ across lines #}
|
||||
{% if False %}
|
||||
{{ '{{' }}
|
||||
{% endif %}
|
||||
{% for href caption in [('index.html', 'Index'), ('about.html', 'About'),
|
||||
{% for href, caption in [('index.html', 'Index'), ('about.html', 'About'),
|
||||
('downloads.html', 'Downloads')] %}
|
||||
<li><a href="{{ href }}">{{ caption }}</a></li>
|
||||
{% endfor %}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user