Re: [xsl] Parsing XPath in XSLT?
After comparing your XPath 1 EBNF with the XQuery 1.0 EBNF, I thought
that there must be some incantation in the latter that makes REx
understand patterns such as [^"]*. I analyzed the strange error message
about EquivalenceLookAhead that came with 'Literal'. It dawned on me
that REx must have been parsing the EBNF with a REx-generated parser,
for which there must be an EBNF, and there it is:
I saw that EquivalenceLookAhead also starts with '[', and then I thought
"there must be a switch token in an EBNF that allows patterns like [^"]*
to appear, and without that token everything that starts with '[' will
be expected to be an EquivalenceLookAhead". And then I remembered that I
already struggled with the <?TOKENS?> PI when editing an EBNF for CSS.
All the terminals (but also other rules that depend on them, I guess)
need to be defined after this token.
After I fixed it I noticed another issue that REx is not to blame for:
Many productions such as NCName were used but not defined in your XPath
1 schema. I copied the corresponding definitions from the XQuery schema.
After that, there were different messages, some of them declared as
errors, but there was still no output.
It seems that you need to move not only all terminals after <?TOKENS?>,
but also most (but not all) productions that directly or indirectly
depend on the terminals.
I finally managed to get *something* out of REx and I filed a pull
request for that.(https://github.com/wendellpiez/metaschema/pull/2).
I think the use and the overall necessity of the <?TOKENS?> PI in and
EBNF need to be documented better in REx.
On 31.03.2020 21:36, Wendell Piez wapiez(_at_)wendellpiez(_dot_)com wrote:
Last week readers helped me with this interesting question of parsing
a formal language (specifically XPath) in XSLT. A couple of you (John
L, Christophe) pointed me to Gunther Rademacher's awesome work on the
REx parser generator.
This is good stuff and I was indeed able to get XPath 2.0 parsing
running very readily. Fantastic!
What I haven't managed to do yet is get XPath 1.0 parsing.
For that, I need a formal grammar in EBNF that will work in Gunther's
tool. Conveniently, his other tool that draws railroad diagrams offers
one -- https://www.bottlecaps.de/rr/ui -- which indeed appears to be
pulled straight out of the XPath 1.0 Recommendation (see its initial
comment). Sounds good.
However, while it makes a pretty railroad diagram, this EBNF doesn't
work in REx. (There is no good reason to think, I suppose, that it
should, but it is hard not to hope. :-) Possibly it is only partial.
In any case I need either an EBNF that works, or an education, to
provide me with the skills to repair this one.
Do you have any helpful hints? What should implementers be looking at,
for formal descriptions of XPath 1.0 (assuming they want to do that
today, as I do)? In particular might there be somewhere a
complete-and-working variant of the XPath 1.0 grammar such as REx can
consume, or should it actually be pretty easy to make?
PS - If anyone wishes to try the XPath 1.0 EBNF I have copied down
(which does not work :-):
- REx parser generator: https://www.bottlecaps.de/rex/
- non-functioning EBNF:
Maybe it is not that far off. REx chokes on the production for "Literal".
Thanks ! wap
On Thu, Mar 26, 2020 at 7:16 PM Liam R. E. Quin liam(_at_)fromoldbooks(_dot_)org
On Thu, 2020-03-26 at 22:49 +0000, Christophe Marchand
I've used REx parser (exactly the URL mentioned by John) during XML
Prague to convert XQuery code into syntax hilighted code in slides,
for a XQuery course.
Yes - i used it in XSLT at one point for some simple XSLT coverage
checking. (perhaps i should talk about that a bit in the course on
Liam Quin, https://www.delightfulcomputing.com/
Available for XML/Document/Information Architecture/XSLT/
XSL/XQuery/Web/Text Processing/A11Y training, work & consulting.
Barefoot Web-slave, antique illustrations: http://www.fromoldbooks.org
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com