[ZPT] Re: PHP port of TAL?

Evan Simpson evan@4-am.com
Thu, 14 Nov 2002 15:17:40 -0600


Brian Lalor wrote:
> I've got a couple of questions to start things off, not necessarily related to
> the port.  Why is there a "DummyEngine" module in the TAL distribution?  It
> seems to me that the engine's what provides the TALES functionality.
> Shouldn't it be fairly standard?

The "real" TALES implementation lives in the PageTemplates Product, but 
since the three modules (the third being ZTUtils) that drive ZPT are 
theoretically independent, DummyEngine provides a stub TALES 
implementation for the unit tests.

> How do the HTMLParser, HTMLTALParser, TALGenerator, TALInterpreter and
> DummyEngine modules all tie together?

The steps from raw template source to execution are as follows:

1. Make a TALES expression compiler instance (sort of optional).

2. Make a TALGenerator instance, passing it the expression compiler and 
the source code/file for the template.  If no compiler is passed in, it 
will use DummyEngine.

3. Make a TALParser or HTMLTALParser, passing it the TALGenerator 
instance.  These are descended from XMLParser and HTMLParser, 
respectively.  HTMLParser is a lot more forgiving when it comes to 
things like unclosed tags.

4. Call the parseString() or parseFile() method of your parser.  This 
will read the template source, parse it, and send "events" to the 
TALGenerator for each opening tag, closing tag, and other significant 
structure.  TALGenerator looks for opening tags with TAL, METAL, or I18N 
attributes or namespace declarations.  It constructs instruction tuples 
and pushes them onto a program stack, using the expression compiler on 
TALES expressions.

5. Call the getCode() method of the parser to get data structures 
representing the TAL program and METAL macro definitions of the template.

6. Get an execution context from the expression compiler and pass it, 
along with the TAL program, to a TALInterpreter instance.  Call the 
instance to execute the template in that context.

There are a number of shortcomings to this implementation, not least of 
which is the complexity of instruction tuple generation.  Nobody has had 
time to improve on it, sadly.

I'll be happy to answer questions about the implementation or design; 
Please ask if you have any!

Cheers,

Evan @ 4-am