[Python-3000] Brainstorming: literal construction hooks

Josiah Carlson jcarlson at uci.edu
Sat Apr 22 19:07:13 CEST 2006


"Guido van Rossum" <guido at python.org> wrote:
> 
> On 4/22/06, Fredrik Lundh <fredrik at pythonware.com> wrote:
> > Guido van Rossum wrote:
> >
> > > It's an interesting idea; it's been brought up before but nobody AFAIK
> > > has ever implemented it. I like the scoping requirement.
> >
> > can we add support for XML literals while we're at it?
> >
> >     http://effbot.org/zone/idea-xml-literal.htm
> 
> Javascript has an ECMA standardized extension that supports this
> (ECMA-357 or E4X).
> 
> Groovy has a different approach that doesn't blend the two syntaxes,
> but rather gives you more native syntax for constructing DOM trees (or
> event streams; it wasn't clear from the description I saw today). That
> makes perhaps more sense; it avoids the lexical ambiguities and a
> parentheses-based syntax is easier to type than XML. Maybe this
> example (which I am making up) suffices:
> 
> frag1 = element["some content"]
> 
> frag2 = element["some content",
>                              child(attribute='value')["spam & egg"]]

Nevow.stan has a very similar method for generating *ML with
(attribute='value')[content], but I've personally found that using only
function-call semantics to create children and attributes for *ML in
Python is much more convenient; allowing one to use any of the following
and get a reasonable method for *ML object re-use:
    (attribute='value')(content)
    (content)(attribute='value')
    (content, attribute='value')

A working system for handling this kind of *ML generation is available
in the ASPN Python Cookbook here (the non-closing tags portion may not
be correct for any *ML, even HTML):
    http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/440563


 - Josiah



More information about the Python-3000 mailing list