[ZPT] Re: PHP port of TAL?

Fred L. Drake, Jr. fred@zope.com
Thu, 14 Nov 2002 14:06:46 -0500


Brian Lalor writes:
 > The more I look at the Python code, the less trivial I think this
 > is going to be. :-)

It certainly won't be trivial!

 > Could someone kind if give an overview of how the internals work?
 > There's not much in the way of documentation in the Python code.
 > From what I gather, an XML parser is used to parse the template
 > source and creates "opcodes" out of the various TAL and METAL
 > commands.  That code is then parsed by an interpreter which
 > actually handles the TALES expressions.

For some definition of parsed, yes.  The use of "bytecodes" (is
"tuplecodes" a word? ;) is done to avoid parsing the *ML each time we
render a page.  It's really a performance optimization, but necessary
for real servers in practice.

 > Why weren't the Python SGML or XML parsers used for the compilation
 > phase?  I see that the overall structure of the included (HT|X)ML
 > parser is quite similar to that of the bundles Python versions and
 > I think I'll be able to replicate that shell pretty easily in PHP
 > (what Manuel has probably already accomplished).

I'm not sure what you mean.  The Python XML parser is used for XML,
but a custom parser was written for HTML since we wanted to be a
little closer to the lexical level than htmllib supported.  (This
parser, in TAL/HTMLParser.py, has been added to the Python standard
library in Python 2.2, but originated in the TAL code.)

We'll be glad to answer specific questions as they come up, but we're
pretty crushed for time these days.


  -Fred

-- 
Fred L. Drake, Jr.  <fred at zope.com>
PythonLabs at Zope Corporation