Re: compiling XPath to Scheme source code

"Dmitry Lizorkin" <[email protected]> Tue, 30 Nov 2004 14:10:37 +0300
Newsgroups gmane.lisp.scheme.ssax-sxml
Message-ID <[email protected]>
Hello,

>   There is an advantage of Scheme source code over AST. AST is fixed
> and so it can't provide additional functionality. Scheme source code
> is flexible, so we can do tricks.
>
>   For example, consider XPath "elem[position()<3]".
>  ...
>   In case of the Scheme code it's possible to change "scxpath-filter"
> to some "take-until". In case of the AST we can't perform such change
> without extending AST.

The same optimization can be implemented above AST as well. Moreover, this
optimization is _already_ implemented. Please take a look at the function
   ddo:check-special-predicate
in "ddo-txpath.scm"

Also note that AST is SXML, so it can be processed by conventional SXML
tools.

>   Another issue is documentation. Scheme code is documented (R5RS)
> much better than AST. (Is AST documented at all?)

The grammar for AST is as follows:

{1} <LocationPath> ::= <RelativeLocationPath>
                       | <AbsoluteLocationPath>
{2} <AbsoluteLocationPath> ::= (absolute-location-path  <Step>* )
{3} <RelativeLocationPath> ::= (relative-location-path  <Step>+ )
{4} <Step> ::= (step  <AxisSpecifier> <NodeTest> <Predicate>* )
               | (range-to  (expr <Expr>)  <Predicate>* )
    + added by sxpath native syntax:
               | <FilterExpr>
               | (lambda-step  <Scheme-lambda> )
{5} <AxisSpecifier> ::= (axis-specifier  <AxisName> )
{6} <AxisName> ::= (ancestor)
                   | (ancestor-or-self)
                   | (attribute)
                   | (child)
                   | (descendant)
                   | (descendant-or-self)
                   | (following)
                   | (following-sibling)
                   | (namespace)
                   | (parent)
                   | (preceding)
                   | (preceding-sibling)
                   | (self)
    + axes added by SXLink:
                   | (arc)
                   | (traverse)
                   | (traverse-arc)
{7} <NodeTest> ::= (node-test (*))
                   | (node-test (namespace-uri  <String> ))
                   | (node-test (namespace-uri  <String> )?
                                (local-name  <String> ))
                   | (node-test (comment))
                   | (node-test (text))
                   | (node-test (pi <String>? ))
                   | (node-test (point))
                   | (node-test (range))
    + added by sxpath native syntax:
                   | (node-test (equal?  <SXML-node> ))
                   | (node-test (eq?  <SXML-node> ))
                   | (node-test (names  <String>+ ))
                   | (node-test (not-names  <String>+ ))s
{8} <Predicate> ::= (predicate  <Expr> )
{9} <Expr> ::= <OrExpr>
               | <AndExpr>
               | <EqualityExpr>
               | <RelationalExpr>
               | <AdditiveExpr>
               | <MultiplicativeExpr>
               | <UnionExpr>
               | <PathExpr>
               | <FilterExpr>
               | <VariableReference>
               | <Literal>
               | <Number>
               | <FunctionCall>
               | <LocationPath>
{10} <OrExpr> ::= (or <Expr> <Expr>+ )
{11} <AndExpr> ::= (and <Expr> <Expr>+ )
{12} <EqualityExpr> ::= (=  <Expr> <Expr> )
                        | (!=  <Expr> <Expr> )
{13} <RelationalExpr> ::= (<  <Expr> <Expr> )
                          | (>  <Expr> <Expr> )
                          | (<=  <Expr> <Expr> )
                          | (>=  <Expr> <Expr> )
{14} <AdditiveExpr> ::= (+  <Expr> <Expr> )
                        | (-  <Expr> <Expr>? )
{15} <MultiplicativeExpr> ::= (*  <Expr> <Expr> )
                              | (div  <Expr> <Expr> )
                              | (mod  <Expr> <Expr> )
{16} <UnionExpr> ::= (union-expr  <Expr> <Expr>+ )
{17} <PathExpr> ::= (path-expr  <FilterExpr> <Step>+ )
{18} <FilterExpr> ::= (filter-expr (primary-expr  <Expr> )
                                   <Predicate>* )
{19} <VariableReference> ::= (variable-reference  <String> )
{20} <Literal> ::= (literal  <String> )
{21} <Number> :: (number  <Number> )
{22} <FunctionCall> ::= (function-call (function-name  <String> )
                                       (argument  <Expr> )* )

The mapping from XPath grammar to AST isn't documented yet. On the other
hand, I believe that the code in "xpath-ast.scm" that performs the mapping
considered is self-describing enough.

Regards,
Dmitry






-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now. 
http://productguide.itmanagersjournal.com/