This looks like it would be relatively straight forward to do w/
semantic. Are you intending to create an interpreter for XPATH, or
just collect tags from it?
If you are trying to make an interpreter for XPATH you may want to
use David Ponce's wisent parser (a bison port to Emacs Lisp) which
comes with a calculator example for your interpreter. It is in
CVS, and I'm certain you would get help on this mailing list for
it. It will become a primary parser in versions of semantic after
1.4 is released. My recommendation for using the CVS only `wisent'
parser is that it handles precedence properly.
>>> Alex Schroeder <kensanata@...> seems to think that:
>I'm writing an XPATH implementation and I'm wondering wether using
>semantic would help me. The language seems quite simple so if it is a
>lot of overhead, I might be better off writing the parser myself. Can
>you help me decide that?
>Here are some examples using the language, from the spec itself:
> * child::para[position()=1] selects the first para child of the context node
> * child::para[position()=last()] selects the last para child of the context node
> * child::para[position()=last()-1] selects the last but one para child of the
> context node
> * child::para[position()>1] selects all the para children of the context node
> other than the first para child of the context node
> * following-sibling::chapter[position()=1] selects the next chapter sibling of
> the context node
> * preceding-sibling::chapter[position()=1] selects the previous chapter sibling
> of the context node
> * /descendant::figure[position()=42] selects the forty-second figure element in
> the document
> * /child::doc/child::chapter[position()=5]/child::section[position()=2] selects
> the second section of the fifth chapter of the doc document element
> * child::para[attribute::type="warning"] selects all para children of the
> context node that have a type attribute with value warning
> * child::para[attribute::type='warning'][position()=5] selects the fifth para
> child of the context node that has a type attribute with value warning
>The spec contains EBNF. Here's some examples from the spec.
> LocationPath ::= RelativeLocationPath
> | AbsoluteLocationPath
> AbsoluteLocationPath ::= '/' RelativeLocationPath?
> | AbbreviatedAbsoluteLocationPath
> RelativeLocationPath ::= Step
> | RelativeLocationPath '/' Step
> | AbbreviatedRelativeLocationPath
> Predicate ::= '[' PredicateExpr ']'
> PredicateExpr ::= Expr
> Expr ::= OrExpr
> PrimaryExpr ::= VariableReference
> | '(' Expr ')'
> | Literal
> | Number
> | FunctionCall
> RelationalExpr ::= AdditiveExpr
> | RelationalExpr '<' AdditiveExpr
> | RelationalExpr '>' AdditiveExpr
> | RelationalExpr '<=' AdditiveExpr
> | RelationalExpr '>=' AdditiveExpr
>I already have code to do single steps in all of this. Here are some
>(tested and working) examples; using M-x occur in my source file. :)
> 88:(defun xpath-ancestor-axis (node)
> 103:(defun xpath-ancestor-or-self-axis (node)
> 112:(defun xpath-attribute-axis (node)
> 120:(defun xpath-child-axis (node)
> 127:(defun xpath-descendant-axis (node)
> 145:(defun xpath-descendant-or-self-axis (node)
> 153:(defun xpath-following-axis (node)
> 181:(defun xpath-following-sibling-axis (node)
> 190:(defun xpath-parent-axis (node)
> 198:(defun xpath-preceding-axis (node)
> 224:(defun xpath-preceding-sibling-axis (node)
> 242:(defun xpath-self-axis (node)
> 249:(defun xpath-name-filter (node-list name)
> 257:(defun xpath-text-filter (node-list)
> 297:(defun xpath-last-function ()
> 302:(defun xpath-position-function ()
> 307:(defun xpath-count-function (node-set)
> 311:(defun xpath-name-function (&optional node-set)
>Thus I am reasonably sure that I can implement something like the
>following example. The predicates in the square brackets can become
>very complex, however. This is where I wonder wether Semantic will
>If it helps for the predicates, of course, then I'd want to use if for
>the rest of XPATH as well.
>What do you think?
Eric Ludlam: zappo@..., eric@...
Home: http://www.ultranet.com/~zappo Siege: http://www.siege-engine.com
Emacs: http://cedet.sourceforge.net GNU: http://www.gnu.org