Wednesday, November 29, 2017

XPATH in ANTLR4 with Cpp runtime

Leave a Comment

I can't find a way to work properly with Xpath in the cpp runtime of ANTLR4. Precisely, I have noticed that the path.split(..) function always returns an empty vector. As a result the function path.evaluate(context) always returns the unmodified (input) context parameter.

I was expecting to get at least two Xpath elements (root // and wildecar *) with the following code :

  const std::string xpath_str  ="//*/ID";                                                  antlr4::tree::xpath::XPath path(&parser, xpath_str);   std::vector<tree::xpath::XPathElement>  elements = path.split(xpath_str);   std::cout << "Nb XpAth Elements :"<< elements.size() << std::endl; 

but it returns 0 elements.

Can you help me with this ?

ps: I raised an issue about it on Github because I'm not sure whether the problem is in the cpp runtime or not.


EDIT

I found a minor bug in the current release of the Cpp runtime.

The code in xPath.cpp :

std::vector<XPathElement> XPath::split(const std::string &path) {   ANTLRFileStream in(path);   

should be replaced by :

std::vector<XPathElement> XPath::split(const std::string &path) {   ANTLRInputStream in(path);   

otherwise the split function doesn't behave as in other runtime (it expect a file instead of a string).

I have made a pull request.

However the Xpath feature still doesn't work.

The following code always return an empty string (I'm sure of the value of the xpath as it works with the c# runtime)

     const std::string xpath_enum = "*//enumerator/Identifier";      antlr4::tree::xpath::XPath finder(_parser, xpath_enum);      std::vector<antlr4::tree::ParseTree *>subtrees = finder.evaluate(context); 

Can anyone help me with this ?

0 Answers

If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment