Skip to content

Commit

Permalink
Merge pull request #1215 from kuzudb/issue-1205
Browse files Browse the repository at this point in the history
Add scripts to generate cypher parser
  • Loading branch information
andyfengHKU committed Jan 30, 2023
2 parents 2d50c42 + 147926a commit 89fba7c
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 5 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,9 @@ __pycache__/
*$py.class
cmake-build-debug/
test/unittest_temp/

# antlr4 jar
scripts/antlr4/antlr4.jar

# macOS
.DS_Store
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Kùzu is being actively developed at University of Waterloo as a feature-rich an
## Build
To build from source code, Kùzu requires Cmake(>=3.11), Python 3, and a compiler that supports `C++20`.
- Perform a full clean build without tests and benchmark:
- `make clean && make`
- `make clean && make release`
- Perform a full clean build with tests and benchmark (optional):
- `make clean && make all`
- Run tests (optional):
Expand Down
2 changes: 2 additions & 0 deletions scripts/antlr4/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Antlr4 Parser
To generate antlr4 parser, simply run `./generate_grammar.sh`
39 changes: 39 additions & 0 deletions scripts/antlr4/generate_grammar.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/bash

# the root directory of the project
ROOT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )/../../" >/dev/null 2>&1 && pwd )"

# download antlr4.jar if not exists
if [ ! -e antlr4.jar ]
then
echo "Downloading antlr4.jar"
curl --url 'https://www.antlr.org/download/antlr-4.9-complete.jar'\
--output './antlr4.jar'
fi

# create the directory for the generated grammar
mkdir -p ./generated

# move grammar file to current directory
cp $ROOT_DIR/src/antlr4/Cypher.g4 ./Cypher.g4

# generate grammar
java -jar antlr4.jar -Dlanguage=Cpp -no-visitor -no-listener Cypher.g4 -o ./generated

# rename include path
sed 's/#include "CypherLexer.h"/#include "cypher_lexer.h"/g' ./generated/CypherLexer.cpp > ./generated/cypher_lexer.cpp
sed 's/#include "CypherParser.h"/#include "cypher_parser.h"/g' ./generated/CypherParser.cpp > ./generated/cypher_parser.cpp
mv ./generated/CypherLexer.h ./generated/cypher_lexer.h
mv ./generated/CypherParser.h ./generated/cypher_parser.h

# move generated files to the right place
mv ./generated/cypher_lexer.h $ROOT_DIR/third_party/antlr4_cypher/include/cypher_lexer.h
mv ./generated/cypher_lexer.cpp $ROOT_DIR/third_party/antlr4_cypher/cypher_lexer.cpp
mv ./generated/cypher_parser.h $ROOT_DIR/third_party/antlr4_cypher/include/cypher_parser.h
mv ./generated/cypher_parser.cpp $ROOT_DIR/third_party/antlr4_cypher/cypher_parser.cpp

# remove the generated directory
rm -rf ./generated

# remove the grammar file
rm ./Cypher.g4
2 changes: 1 addition & 1 deletion third_party/antlr4_cypher/cypher_lexer.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

// Generated from src/antlr4/Cypher.g4 by ANTLR 4.9
// Generated from Cypher.g4 by ANTLR 4.9


#include "cypher_lexer.h"
Expand Down
2 changes: 1 addition & 1 deletion third_party/antlr4_cypher/cypher_parser.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

// Generated from src/antlr4/Cypher.g4 by ANTLR 4.9
// Generated from Cypher.g4 by ANTLR 4.9



Expand Down
2 changes: 1 addition & 1 deletion third_party/antlr4_cypher/include/cypher_lexer.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

// Generated from src/antlr4/Cypher.g4 by ANTLR 4.9
// Generated from Cypher.g4 by ANTLR 4.9

#pragma once

Expand Down
2 changes: 1 addition & 1 deletion third_party/antlr4_cypher/include/cypher_parser.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

// Generated from src/antlr4/Cypher.g4 by ANTLR 4.9
// Generated from Cypher.g4 by ANTLR 4.9

#pragma once

Expand Down

0 comments on commit 89fba7c

Please sign in to comment.