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

Add scripts to generate cypher parser #1215

Merged
merged 1 commit into from
Jan 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
andyfengHKU marked this conversation as resolved.
Show resolved Hide resolved
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