#[code]A love letter to Boost.Spirit
From: "Jez Higgins"
Date: Thu, January 4, 2007 11:29 am
To: "Kevlin Henney"
Hi Kevlin,
Alongside the normal keynotes, sessions, panel discussions and so on
that conferences usually have, the academic conferences I went to as a
fresh faced young thing also had poster presentations. A poster
presentation was, as you might have guessed, a poster of usually about
A3 size, which you filled with whatever you fancied. The posters were
usually displayed on freestanding boards in the mingling/coffee drinking
areas between the main session rooms. The nice things about doing a
poster were it was easier (because you could present a small piece of
work, or work in progress), it was cheaper (because you didn't actually
have to be there), but you could still list it as a publication.
I appreciate this is rather late in the day, but wondered if BoostCon
might consider posters? I only bring it up because I doubt I can afford
to attend, it clashes with my wife's birthday in any case, but I do have
the scrap of an idea for a poster. It would be some little extracts I'd
written about Boost.Spirit while working on an XPath and XSLT engine,
printed in 72pt text.
XPath: variables returning node-sets
------------------------------------
Made a minor grammar fix, and reworked location steps slightly so
expressions like $doc/step1/step2 or $doc[pred] work (assuming $doc
is bound to a node-set obviously).
Everytime I find a problem in the grammar, which actually isn't very
often at all, I give thanks to the pragmatic programming Gods that I
used Spirit rather than rolling my own parser. In this case, I'd
transcribed
FilterExpr ::= PrimaryExpr | FilterExpr Predicate
after eliminating right-recursion as
FilterExpr = PrimaryExpr >> *(Predicate >> PrimaryExpr);
rather than
FilterExpr = PrimaryExpr >> *Predicate;.
Time to fix - about 30 seconds. Time to fix if I'd hand-rolled -
don't even want to think about it :)
Jaxen Bug 94 - http://jira.codehaus.org/browse/JAXEN-94
--------------------------------------------------------
"Charles Souillard reports a problem while trying to evaluate the
following expression : 2+1-1+1. It should be 3.0 but is 1.0"
Jaxen is an XPath engine that uses a hand-built parser. It turned
out that evaluation order of the arithmetic operators was wrong, and
the code had to be patched in many different places to fix it. Since
my code implements the grammar as written in the spec, I knew that
not only did I not have this problem, I *could* not have this
problem.
When is an XPath expression not an XPath expression?
----------------------------------------------------
When it's an XSLT pattern, that's when.
As an XPath
para[@ref]
selects, for a given node, its child para elements which have ref
attributes. As an XSLT pattern it tests whether a given node is a
para element which has a ref attribute.
Similarly, something like
chapter/para
tests whether a given node is a para element with a chapter element
parent. In XPath terms, you'd express this as something like
boolean(self::para[parent::chapter]).
Aside from this sematic difference, syntactically XSLT patterns are
an XPath subset. I don't have these things evaluating yet but, thanks
to the miracle that is Boost.Spirit, I've extended Arabica::XPath to
parse them. Took about half an hour, including writing a pile of test
cases and getting them passing. Spirit really is a top piece of
work. While it's not hard to find people rambling on about how Python
or Lisp or whatever really is the thing for writing little domain
specific languages, this kind of thing really shows just how deadly
cool template metaprogramming can be. Read the EBNF, transcribe it
into code, compile, and go. Easy, expressive and type-safe. What more
could you want?
Yes, it's a love letter to Spirit. Why not?
Hope you're keeping as busy as you'd like, and that you and your family
are well and happy.
Jez
[Add a comment]
The Forest Road Reader, No 37 (1)
The Forest Road Reader, No 19 (1)
The Forest Road Reader, No 17 (1)
The Forest Road Reader, No 10 (1)