[xsl] Grammars for XPath 2.0: which to use?

Subject: [xsl] Grammars for XPath 2.0: which to use?
From: "Dimitre Novatchev" <dnovatchev@xxxxxxxxx>
Date: Thu, 12 Jul 2007 21:12:08 -0700
Recently I've been having fun with parsing context-free languages
using a general parser for LR languages, written in XSLT 2.0.

The first and easier language was JSON, leading to the addition of two
new functions to FXSL:
     f:json-document()
and
    f:json-file-document()

as reported in this list and in my blog.

The second language I played with was XPath. As I mentioned earlier in
this list, it was almost straightforward and non-problematic to create
a working parser (right now constructing just a parse tree for an
XPath expression). The reason for this easiness is that Dr. Kay's
XPath 2.0 book is an excellent reference material both in describing
the terminal symbols (lexical tokens) of the language and its grammar.

My question is whether the XPath 2.0 grammar as described in the book
is still equivalent to the one described in the XPath 2.0
recommendation (http://www.w3.org/TR/xpath20/#id-grammar)

or if there are any differences?

Certainly, I could try comparing both grammars myself, but why not ask
and get this valuable information straight from the horse's mouth? I
believe this is also valuable to the readers of xsl-list.


As the official W3 XPath 2.0 recommendation is not so easy to read as Dr. Kay's book, I would prefer to be able to continue using the grammar from his book (possibly with appropriate modifications).

The same question can be asked about the definition of the terminal
symbols. Here we have:

1. Dr. Kay's book.

 2. The official W3 XPath 2.0 recommendation
(http://www.w3.org/TR/xpath20/#terminal-symbols)

 3. A seemingly outdated W3 document "Building a Tokenizer for XPath
or XQuery" (http://www.w3.org/TR/xquery-xpath-parsing/)

In implementing the lexical scanner (again in pure XSLT 2.0) I again
used Dr. Kay's book (1), found (2) quite confusing, and definitely
decided not to use any of the approaches described in (3). It might be
interesting to know that determining the next terminal symbol can be
accomplished based on a the evaluation of a single regular expression
(shall I call this "one-pass approach" ?).

--
Cheers,
Dimitre Novatchev
---------------------------------------
Truly great madness cannot be achieved without significant intelligence.
---------------------------------------
To invent, you need a good imagination and a pile of junk
-------------------------------------
You've achieved success in your field when you don't know whether what
you're doing is work or play

Current Thread