parsing xpath expressions
I want to parse XPath expressions I an looking for a lexer/parser implementation in C++ or Python
Here is all the information about XPath parsers I manage to gather :
- ANTLR grammar for XPath 1 & 2 ( from Parse XPath Expressions )
- the Python parser & lexer from PDIS
- severa开发者_开发知识库l python implementations from Towards a Standard Parser Generator
Does anyone knows other implementations ? in C++ ?
PS : I don't want to evaluate XPath expressions but to tokenise them
Based on a comment by OP,
I am working on XPath queries rewriting and equivalence
what he needs is a parser that builds abstract syntax trees, and ways to analyze those trees and transform them. Analyzers and "rewriting" can then be done procedurally by walking/modifying the AST; this is the traditional way to do it.
But it seems that the focus should be OP's goals. For that he needs analysis and rewriting. But that doesn't have to be entirely done in the traditional, procedural way. Rather, it would be nice if the analysis/rewrites can be done directly using XPath notation.
I suggest he look at our DMS Software Reengineering Toolkit which parses, builds ASTs, but in particular enables "rewriting" on the ASTs using the surface syntax. Then XPath "rewrites" could be written directly as equivalences over XPath expressions. A motivating example of how this works can be seen as Rewriting algebra equations using DMS. It should be obvious from that example that a grammar for XPath is easily defined.
Checkout XQilla http://xqilla.sourceforge.net/HomePage
Xerces has an offshoot, xalan-c, for doing this:
http://xml.apache.org/xalan-c/overview.html
精彩评论