Skip to content
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
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
id: set-matrix
run: |
# List of all available parsers
ALL_PARSERS="redshift postgresql cql snowflake"
ALL_PARSERS="redshift postgresql cql snowflake tsql"
# Add more parsers here as they are added to the repository
# ALL_PARSERS="redshift mysql postgresql"

Expand Down
7 changes: 7 additions & 0 deletions tsql/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
all: build test

build:
antlr -Dlanguage=Go -package tsql -visitor -o . TSqlLexer.g4 TSqlParser.g4

test:
go test -v -run TestTSQLParser
43 changes: 43 additions & 0 deletions tsql/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
The tsql-parser is a parser for T-SQL. 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/tsql).

## Build

Before build, you need to install the ANTLR4.

requirements:

- https://github.com/antlr/antlr4/blob/master/doc/getting-started.md
- https://github.com/antlr/antlr4/blob/master/doc/go-target.md

```bash
./build.sh
```

## Update grammar

### Manually change the grammar file in this project

1. run `./build.sh` to generate the parser code.

### From antlr4-grammars-tsql

1. Clone the `TSqlLexer.g4` and `TSqlParser.g4` grammar files from https://github.com/antlr/grammars-v4/tree/master/sql/snowflake.
2. Clone the examples[https://github.com/antlr/grammars-v4/tree/master/sql/tsql/examples], and use it for test.
3. run `./build.sh` to generate the parser code.

## Test the parser

Run `TestTSQLParser` in `parser_test.go` to test the parser.

```bash
go test -v
```

## References

- ANTLR4 Getting Started https://github.com/antlr/antlr4/blob/master/doc/getting-started.md
- ANTLR4 Go Garget https://github.com/antlr/antlr4/blob/master/doc/go-target.md

## Port

Port folder contains the ported code in another language.
1,303 changes: 1,303 additions & 0 deletions tsql/TSqlLexer.g4

Large diffs are not rendered by default.

Loading