TT3: /home/abw/web/london/tt3/slides/examples/generators.tt3
Source
Tokens
Tree
Variables
Output
Template Source
[%
numbers
=
[
item
*
3
for
1
to
10
]
%]
[%
numbers
.
join
(
', '
)
-%]
--EOF--
Source Tokens
tag_start
@0
[%
whitespace
@2
variable
@4
numbers
whitespace
@11
operator assign
@12
=
whitespace
@13
construct list
@14
[
whitespace
@15
variable
@16
item
whitespace
@20
number multiply
@21
*
whitespace
@22
number
@23
3
whitespace
@24
command for
@25
for
whitespace
@28
number
@29
1
whitespace
@30
number to
@31
to
whitespace
@33
number
@34
10
whitespace
@36
terminator
@37
]
whitespace
@38
tag_end
@40
%]
text
@42
\n\n
tag_start
@44
[%
whitespace
@46
variable
@48
numbers
operator dot
@55
.
word
@56
join
construct parens
@60
(
squote string
@61
', '
terminator
@65
)
whitespace
@66
tag_end
@67
-%]
whitespace
@70
\n
eof
@71
Parse Tree
binary expr
@12
numbers = [ for ]
variable element
@4
numbers
=
list expr
@14
[ for ]
[
for keyword
@25
for
List
binary expr
@31
1 to 10
number element
@29
1
to
number element
@34
10
Then
binary expr
@21
item * 3
variable element
@16
item
*
number element
@23
3
]
text
@42
\n\n
binary expr
@55
numbers.join
variable element
@48
numbers
.
word element
@56
join
Variables Used
item
Uses
@ line 1
[% numbers = [
item
* 3 for 1 to 10 ] %]
numbers
Uses
@ line 1
[%
numbers
= [ item * 3 for 1 to 10 ] %]
@ line 3
[%
numbers
.join(', ') -%]
Vars
join
Uses
@ line 3
[%
numbers.join
(', ') -%]
Generated Output
3, 6, 9, 12, 15, 18, 21, 24, 27, 30