Open chakpongchung opened 2 years ago
Hi,
Thank you for engaging with the openCypher grammar.
To your problem: Unfortunately, I cannot speak to the C++ specific part of it. If the behavior is indeed different between different host language (Java vs. C++) and different usage patterns, then it seems to be more an Antlr problem to me.
However, let me note something just in case you have miss it by accident.
oC_ComparisonExpression
s: One in the WHERE
clause under oC_Where
and two in the RETURN
clause, one in each projection item under oC_ProjectionItem
.oC_ComparisonExpression
under oC_Where
should have three children:
oC_AddOrSubtractExpression
, " "
(whitespace before "<"), and oC_PartialComparisonExpression
.oC_ComparisonExpression
under oC_ProjectionItem
should have one ParserRuleContext for oC_AddOrSubtractExpression
as its only child.(naming as in the Java variant)
Maybe you happen to look at the wrong oC_ComparisonExpression
?!? Just checking.
Another possibility is that you miss a method in your visitor or a return line in one of the methods, so that the visitor is no fully descending the parse tree under oC_Match
and never gets to the oC_ComparisonExpression
with three children in the first place. Have you tried to print out the fully parse tree with your visitor? Or checked by other means that is actually walks the whole tree?
Note that I am mostly guessing. You may have double checked all of that already. If so, I am sorry. Hope it helps, anyway.
@hvub
Thanks! the problem is resolved. I work on the openCypher implementation at KatanaGraph. I would like to know whether I can join the openCypher committee so we can officially contribute back to the community. I have implemented a majority part of the openCypher. I found there are several places where improvement of the grammar is needed to simplify the implementation.
How can we solve this missing-children problem?
I am trying to use the antlr4 c++ runtime for the openCypher grammar.
When I tried to parse the following query,
I see a child missing for the parent node
OC_ComparisonExpressionContext
in the visitor pattern:Here the
ctx->children.size()
shows1
but it indeed has3
children from the parse tree generated which one of them isoC_PartialComparisonExpression
. With this problem,visitOC_PartialComparisonExpression
is not called becausevisitChildren(ctx)
fromvisitOC_ComparisonExpression()
will not get to this missing child.I have tried the listener pattern and it has no this missing-child problem. Also, I have tried the Java runtime and this problem is not there.
To reproduce the problem in C++, I have provided the dependencies needed.
https://s3.amazonaws.com/artifacts.opencypher.org/M18/Cypher.g4