Skip to content

Commit 2b2fa56

Browse files
h3n4lclaude
andauthored
feat: add Snowflake SQL parser to monorepo (#24)
Add ANTLR4-based Snowflake SQL parser from snowsql-parser repository into the parser monorepo. Changes: - Add snowflake/ directory with grammar files (SnowflakeLexer.g4, SnowflakeParser.g4) - Add Makefile with build and test targets following the pattern of other parsers - Include 25 SQL test examples covering various Snowflake syntax features - Update package name and import paths to github.com/bytebase/parser/snowflake - Add snowflake to CI workflow to run tests automatically - All 25 test cases passing 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude <[email protected]>
1 parent d526c43 commit 2b2fa56

38 files changed

+204219
-1
lines changed

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434
id: set-matrix
3535
run: |
3636
# List of all available parsers
37-
ALL_PARSERS="redshift postgresql cql"
37+
ALL_PARSERS="redshift postgresql cql snowflake"
3838
# Add more parsers here as they are added to the repository
3939
# ALL_PARSERS="redshift mysql postgresql"
4040

snowflake/Makefile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
all: build test
2+
3+
build:
4+
python3 build_id_contains_non_reserved_keywords.py && antlr -Dlanguage=Go -package snowflake -visitor -o . SnowflakeLexer.g4 SnowflakeParser.g4
5+
6+
test:
7+
go test -v -run TestSnowflakeSQLParser

snowflake/README.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
The plsql-parser is a parser for Snowflake. It is based on the [ANTLR4](https://github.com/antlr/antlr4) and use the grammar from [antlr4-grammars-plsql](https://github.com/antlr/grammars-v4/tree/master/sql/snowflake).
2+
3+
## Build
4+
5+
Before build, you need to install the ANTLR4.
6+
7+
requirements:
8+
- https://github.com/antlr/antlr4/blob/master/doc/getting-started.md
9+
- https://github.com/antlr/antlr4/blob/master/doc/go-target.md
10+
11+
```bash
12+
./build.sh
13+
```
14+
15+
## Update grammar
16+
17+
### Manually change the grammar file in this project
18+
19+
1. run `./build.sh` to generate the parser code.
20+
21+
### From antlr4-grammars-plsql
22+
23+
1. Clone the `SnowflakeLexer.g4` and `SnowflakeParser.g4` grammar files from https://github.com/antlr/grammars-v4/tree/master/sql/snowflake.
24+
1. run `./build.sh` to generate the parser code.
25+
26+
## Test the parser
27+
28+
Run `TestSnowflakeSQLParser` in `parser_test.go` to test the parser.
29+
30+
```bash
31+
go test -v
32+
```
33+
34+
## References
35+
36+
- ANTLR4 Getting Started https://github.com/antlr/antlr4/blob/master/doc/getting-started.md
37+
- ANTLR4 Go Garget https://github.com/antlr/antlr4/blob/master/doc/go-target.md

snowflake/SnowflakeLexer.g4

Lines changed: 1202 additions & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)