[
Lists Home |
Date Index |
Thread Index
]
Hi,
I'm not really a regex expert either (nor at anything else for that matter
;), but I have successfully implemented an XPath processor using a
recogniser generated directly from the BNF productions in the spec. The
generated parser uses my own generalised regular expression engine with
which to perform its wonders (implying that it should indeed be possible to
specify the whole thing as one ginormous regex). The only minor
fly-in-the-ointment came from the fact that many of the productions are
defined inductively, .e.g.
A ::= B | A '/' B | A '//' B
requiring them to first be refactored into
A ::= B ( ( '/' | '// ) B )*
to prevent infinite recursion.
I'm not au fait with the theory of all this so I would appreciate
comments/corrections from those more knowledgable than myself (Joe?) on the
following summary:
The BNFs as presented in the spec specify an LR(1) grammar - in that you
need 1-token lookahead to be able to effect the above refactoring. You can
easily manipulate the productions by hand to remove the lookahead
requirement which would then make it an LR(0), or context-free, grammar.
You could, in theory at least, then use simple algebraic substitution all
the way to remove all the intermediate non-terminals.
But then, in theory, you could also insert bamboo shoots under your
fingernails, which may be marginally less painful, and about equally as
useful! <g>
cheers,
gary
----- Original Message -----
From: "Niels Peter Strandberg" <nielspeter@npstrandberg.com>
To: <xml-dev@lists.xml.org>
Sent: Thursday, April 04, 2002 6:30 PM
Subject: [xml-dev] Validate an XPath with regex
> Shouldn't it be possible to validate the syntax of an XPath string using
> regular expressions. Im not a regex expert, so just want to ask you out
> there if it could be done.
>
> This is useful if you have a app that takes a XPath as argument, then
> you simply match the string against a regex to validate the syntax of
> the XPath string. This could also be used if you only support a subset
> of XPath in your app, by simply changing the regex! When the string is
> validated, you can send the XPath to parsing.
>
> Is the an regex expert, who want to gives this a try? I could try, but
> the result would not be pretty ;-)
>
>
> Niels Peter
>
>
> -----------------------------------------------------------------
> The xml-dev list is sponsored by XML.org <http://www.xml.org>, an
> initiative of OASIS <http://www.oasis-open.org>
>
> The list archives are at http://lists.xml.org/archives/xml-dev/
>
> To subscribe or unsubscribe from this list use the subscription
> manager: <http://lists.xml.org/ob/adm.pl>
>
>
|