Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re^2: Simplifying the syntax further

by tmoertel (Chaplain)
on Nov 22, 2005 at 15:59 UTC ( [id://510838]=note: print w/replies, xml ) Need Help??


in reply to Re: Simplifying the syntax further
in thread Embedding a mini-language for XML construction into Perl

Good contribution! Your simplified text syntax is prettier and more intuitive.

The corner case where an empty element contains code is a small blemish and an easy price to pay for the benefits of the simplified text syntax. Maybe we can even reduce the blemish by introducing another helper that declares a block to represent an empty content model:

sub empty(&) { shift->(); undef }
Then the corner-case becomes:
doc { br { empty { ++$breaks } } }
It's still not perfect, but maybe we can think of yet another improvement.

Cheers,
Tom

Replies are listed 'Best First'.
Re^3: Simplifying the syntax further
by TimToady (Parson) on Nov 22, 2005 at 16:52 UTC
    Well, there's always:
    doc { br { ++$breaks; () } }
    which pretty much says "empty" to me. But maybe it's better to document it out front. I wonder if something resembling:
    doc { br {} (++$breaks) }
    could be made to work with an additional parameter that is ignored.
Re^3: Simplifying the syntax further
by Aristotle (Chancellor) on Nov 22, 2005 at 16:48 UTC

    That doesn’t look like a useful addition. The user still has to understand the edge case and know when to apply empty manually, but the cost of learning new syntax for it is not amortised, since it offers nothing over saying undef; explicitly.

    For the case of br and hr, the better solution would be to declare them as empty elements. (Then you could also warn/die if the user accidentally does call text or an element constructor.)

    Of course that still won’t help when the user wants the occasional empty td. I see no way to handle that without manual intervention, though, so there might as well be no magic for it at all. Magic must be transparent to earn the name; if it’s not, it just adds extra cost.

    Makeshifts last the longest.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://510838]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (4)
As of 2024-03-28 22:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found