[Python-Dev] Re: User extendable literal modifiers ?!
Jeff Epler
jepler@unpythonic.net
Mon, 30 Sep 2002 10:16:12 -0500
On Mon, Sep 30, 2002 at 11:01:24AM +0200, Fredrik Lundh wrote:
> btw, the following note is slightly related to this topic, and has been
> generating some buzz lately (at least in my mailbox):
>
> http://effbot.org/zone/idea-xml-literal.htm
This is a little like what I implemented for 'pyhtml'. It was inteded
to be an extension to the Quixote templating system, so it used the idea
that a HTML tag embedded in the code should write itself directly to the
output, like the result of expression statements already does in
templates.
An excerpt the README:
The following code:
<UL>
for i in range(10):
<LI> i
would output something like
<UL><LI>0</LI><LI>2</LI>....<LI>9</LI></UL>
As you can see, I let <TAG> start a block, and let blocks end according
to Python's normal indentation rules. The productions added to the
grammar were:
compound_stmt: ... | tag_stmt
tag_stmt: '<' NAME [tag_args] '>' suite
tag_args: NAME '=' expr (',' NAME '=' expr)* [',']
so that
<DIV CLASS="blue"> "this might be blue"
would also work.
I thought it was rather cute to reverse the normal practice of finding a
way to shoehorn Python syntax into the midst of an HTML document, but
never wrote anything serious using pyhtml. The remains of the project
can be seen at
http://unpythonic.net/~jepler/falcon/pyhtml/
Jeff