cypher-editor icon indicating copy to clipboard operation
cypher-editor copied to clipboard

Cypher ANTLR grammar file does not include newer Cypher features

Open yGuy opened this issue 2 years ago • 1 comments

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.

yGuy avatar Aug 30 '23 10:08 yGuy

I found that the grammar also does not support node label expressions (patterns) and relationship type patterns as in:

MATCH (p:Person|(!Organization))-[:(KNOWS&!HURTS)]->(:Person) RETURN p

also function calls in a RETURN are not working when the function names use "keywords":

MATCH (p) RETURN p, labels(p), types(p)

I think I was able to improve the grammar for my purposes but I lost some of the original functionality, so this is merely a note about the shortcomings of the current file. I don't require a fix anymore, but others may do.

yGuy avatar Sep 01 '23 09:09 yGuy