Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
yGuy opened this issue Aug 30, 2023 · 1 comment
Open

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

yGuy opened this issue Aug 30, 2023 · 1 comment

Comments

@yGuy
Copy link

yGuy commented Aug 30, 2023

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
Copy link
Author

yGuy commented Sep 1, 2023

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 yGuy changed the title Cypher ANTLR grammar file does not include sub queries Cypher ANTLR grammar file does not include newer Cypher features Sep 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant