Skip to content

Cypher ANTLR grammar file does not include newer Cypher features #142

@yGuy

Description

@yGuy

I tried the cypher antlr grammar:

https://github.com/neo4j/cypher-editor/blob/6f476d6e4d73eacb12f922ebe5e6d2c7e11d67df/packages/antlr4/src/Cypher.g4#L149C14-L149C14

It seems the grammar is outdated and does not consider subqueries. It fails to parse the following queries, e.g.:

UNWIND [0, 1, 2] AS x
CALL {
  RETURN 'hello' AS innerReturn
}
RETURN innerReturn

(from https://neo4j.com/docs/cypher-manual/current/clauses/call-subquery/ )

as well as

MATCH (person:Person)
WHERE EXISTS {
    (person)-[:HAS_DOG]->(:Dog)
}
RETURN person.name AS name

and

MATCH (person:Person)
WHERE EXISTS {
  MATCH (person)-[:HAS_DOG]->(dog:Dog)
  WHERE person.name = dog.name
}
RETURN person.name AS name

(from https://neo4j.com/docs/cypher-manual/current/syntax/expressions/#existential-subquery-simple-case )

Suggestion:
Include subqueryclauses like this

subqueryClause :  CALL SP? '{' SP? query? SP? '}' ;

and add the exists sub query to the expressions:

expression : orExpression | existsSubQuery;

existsSubQuery : EXISTS SP? existsSubQueryBody;

existsSubQueryBody: subquery | subqueryPatternBody ;

subqueryPatternBody: '{' SP? pattern ( hint )* ( SP? where )? SP? '}' ;

Note that I am not a cypher expert so the above may be wrong or incomplete.

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