A Simple TT3 Template
Hello [% name or 'World' %]! --EOF--look inside...
- Non-destructive tokeniser
- Extensible operator precedence parser
- Generates complete parse tree
- Views transforms to Perl, HTML, JS, etc...
Thus Spake Andy:
This is a simple TT3 template. You'll be relieved to see that it's the
same as the TT2 equivalent. Note the syntax highlighting. That's being
done by TT3. These slides are generated by Spork
, one of Ingy's marvellous
creations. That uses TT2 to generate the HTML from the slides. So I wrote
a TT2 plugin that munges the output on the way. It looks for embedded
"include this TT3 example" tags, has TT3 load and parse the example, and then
generate a syntax highlighted HTML version of it.
TT3 has a brand new parsing engine. It generates a non-destructive list of all the tokens in the template and then parses them into a tree of expressions. The "non-destructive" part means that we can re-generate the original template source (very important for accurate debugging and error reporting). It also makes it easy to generate different views of the template, e.g. to generate runtime Perl code, or HTML markup for debugging).
TT3 has some nifty debugging capabilities. See that "look inside" link up
there... click it now. This is an HTML debugging page generated by TT3 for
the embedded example (see the bin/tt3-html
script in the repository - but be warned
that it's just a quick hack for now). The Source
tab shows the syntax highlighted source
code. The Tokens
tabs shows a list of all tokens scanned from the template.
The Tree
shows the expression tree - you can click on compound nodes to
open them up. The Variables
tab shows the variables used in the template,
including a source extract and line number of where they're used -
again you can click on the boxes to expand them. The Output
tab shows
the output generated by the template.