Skip to content

missing children from OC_ComparisonExpressionContext in cpp-runtime of ANTLR #529

@chakpongchung

Description

@chakpongchung

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,

MATCH (p1:Person)-->(p2:Person)
WHERE p1.id < p2.id
RETURN p1.id, p2.id

I see a child missing for the parent node OC_ComparisonExpressionContext in the visitor pattern:

    antlrcpp::Any visitOC_ComparisonExpression(CypherParser::OC_ComparisonExpressionContext *ctx) override {
        cout<<ctx->children.size()<<endl;
        return visitChildren(ctx);
    }


    antlrcpp::Any
    visitOC_PartialComparisonExpression(CypherParser::OC_PartialComparisonExpressionContext *ctx) override {
        return visitChildren(ctx);
    }

Here the ctx->children.size() shows 1 but it indeed has 3 children from the parse tree generated which one of them is oC_PartialComparisonExpression. With this problem, visitOC_PartialComparisonExpression is not called because visitChildren(ctx) from visitOC_ComparisonExpression() will not get to this missing child.

(oC_Cypher 
        (oC_Statement 
            (oC_Query 
                (oC_RegularQuery 
                    (oC_SingleQuery 
                        (oC_SinglePartQuery 
                            (oC_ReadingClause 
                                (oC_Match MATCH   
                                    (oC_Pattern 
                                        (oC_PatternPart 
                                            (oC_AnonymousPatternPart 
                                                (oC_PatternElement 
                                                    (oC_NodePattern ( 
                                                        (oC_Variable 
                                                            (oC_SymbolicName p1)) 
                                                        (oC_NodeLabels 
                                                            (oC_NodeLabel : 
                                                                (oC_LabelName 
                                                                    (oC_SchemaName 
                                                                        (oC_SymbolicName Person))))) )) 
                                                    (oC_PatternElementChain 
                                                        (oC_RelationshipPattern 
                                                            (oC_Dash -) 
                                                            (oC_Dash -) 
                                                            (oC_RightArrowHead >)) 
                                                        (oC_NodePattern ( 
                                                            (oC_Variable 
                                                                (oC_SymbolicName p2)) 
                                                            (oC_NodeLabels 
                                                                (oC_NodeLabel : 
                                                                    (oC_LabelName 
                                                                        (oC_SchemaName 
                                                                            (oC_SymbolicName Person))))) ))))))) \n 
                                    (oC_Where WHERE   
                                        (oC_Expression 
                                            (oC_OrExpression 
                                                (oC_XorExpression 
                                                    (oC_AndExpression 
                                                        (oC_NotExpression 
                                                            (oC_ComparisonExpression 
                                                                (oC_AddOrSubtractExpression 
                                                                    (oC_MultiplyDivideModuloExpression 
                                                                        (oC_PowerOfExpression 
                                                                            (oC_UnaryAddOrSubtractExpression 
                                                                                (oC_StringListNullOperatorExpression 
                                                                                    (oC_PropertyOrLabelsExpression 
                                                                                        (oC_Atom 
                                                                                            (oC_Variable 
                                                                                                (oC_SymbolicName p1))) 
                                                                                        (oC_PropertyLookup . 
                                                                                            (oC_PropertyKeyName 
                                                                                                (oC_SchemaName 
                                                                                                    (oC_SymbolicName id))))))))))   
                                                                (oC_PartialComparisonExpression <   
                                                                    (oC_AddOrSubtractExpression 
                                                                        (oC_MultiplyDivideModuloExpression 
                                                                            (oC_PowerOfExpression 
                                                                                (oC_UnaryAddOrSubtractExpression 
                                                                                    (oC_StringListNullOperatorExpression 
                                                                                        (oC_PropertyOrLabelsExpression 
                                                                                            (oC_Atom 
                                                                                                (oC_Variable 
                                                                                                    (oC_SymbolicName p2))) 
                                                                                            (oC_PropertyLookup . 
                                                                                                (oC_PropertyKeyName 
                                                                                                    (oC_SchemaName 
                                                                                                        (oC_SymbolicName id)))))))))))))))))))) \n 
                            (oC_Return RETURN 
                                (oC_ProjectionBody   
                                    (oC_ProjectionItems 
                                        (oC_ProjectionItem 
                                            (oC_Expression 
                                                (oC_OrExpression 
                                                    (oC_XorExpression 
                                                        (oC_AndExpression 
                                                            (oC_NotExpression 
                                                                (oC_ComparisonExpression 
                                                                    (oC_AddOrSubtractExpression 
                                                                        (oC_MultiplyDivideModuloExpression 
                                                                            (oC_PowerOfExpression 
                                                                                (oC_UnaryAddOrSubtractExpression 
                                                                                    (oC_StringListNullOperatorExpression 
                                                                                        (oC_PropertyOrLabelsExpression 
                                                                                            (oC_Atom 
                                                                                                (oC_Variable 
                                                                                                    (oC_SymbolicName p1))) 
                                                                                            (oC_PropertyLookup . 
                                                                                                (oC_PropertyKeyName 
                                                                                                    (oC_SchemaName 
                                                                                                        (oC_SymbolicName id))))))))))))))))) ,   
                                        (oC_ProjectionItem 
                                            (oC_Expression 
                                                (oC_OrExpression 
                                                    (oC_XorExpression 
                                                        (oC_AndExpression 
                                                            (oC_NotExpression 
                                                                (oC_ComparisonExpression 
                                                                    (oC_AddOrSubtractExpression 
                                                                        (oC_MultiplyDivideModuloExpression 
                                                                            (oC_PowerOfExpression 
                                                                                (oC_UnaryAddOrSubtractExpression 
                                                                                    (oC_StringListNullOperatorExpression 
                                                                                        (oC_PropertyOrLabelsExpression 
                                                                                            (oC_Atom 
                                                                                                (oC_Variable 
                                                                                                    (oC_SymbolicName p2))) 
                                                                                            (oC_PropertyLookup . 
                                                                                                (oC_PropertyKeyName 
                                                                                                    (oC_SchemaName 
                                                                                                        (oC_SymbolicName id))))))))))))))))))))))))) <EOF>)

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions