Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
03-11-2021 10:19 AM
Hi all! I was wondering: Is there a way to produce a AST from a Cypher query ? Like a Cypher Parser or something like that?
03-11-2021 11:53 PM
Hello @daniel_amigos !
The best resources for a Cypher language parser are available over on http://www.opencypher.org .
You'll find grammar definitions and such there.
There's a reference implementation in Java that you can find here:
Cheers,
ABK
03-12-2021 07:35 AM
Not strictly an AST ( more of a parse tree) but when you combine it with the symbol tree, you get close.
Start with this Cypher.g4.txt (22.6 KB)
The ANTLR site ( and the two books on it) gives pretty good descriptions on generating the files. Unless you plan to do a lot, the python generated is pretty easy to use, the java and typescript are good.
Once you have a parser/lexer, you will need to write a visitor. Easy enough. OR if your needs are simpler, look at generating a .dot file (Graphviz) which is a very simple parse tree/ast.
We incorporated it into our product easily. Its not a wildly complex language and it does parse well.
All the sessions of the conference are now available online