Skip to content

Commit 31ad3d0

Browse files
h3n4lclaude
andauthored
feat: add T-SQL parser to monorepo (#25)
Add ANTLR4-based T-SQL (Transact-SQL) parser from tsql-parser repository into the parser monorepo. Changes: - Add tsql/ directory with grammar files (TSqlLexer.g4, TSqlParser.g4) - Add Makefile with build and test targets following the pattern of other parsers - Include 143 SQL test examples covering comprehensive T-SQL features - Update package name and import paths to github.com/bytebase/parser/tsql - Add tsql to CI workflow to run tests automatically - Include helper files (keyword_map.go, tsql_base_lexer.go) for lexer functionality - All test cases passing Test coverage includes: - DDL statements (CREATE, ALTER, DROP for databases, tables, views, indexes, etc.) - DML statements (SELECT, INSERT, UPDATE, DELETE, MERGE) - Stored procedures and functions - Control flow statements - Built-in functions (date, string, math, cryptographic, JSON, etc.) - T-SQL specific features (DBCC, hints, transactions, triggers, etc.) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude <[email protected]>
1 parent 2b2fa56 commit 31ad3d0

File tree

156 files changed

+291032
-1
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

156 files changed

+291032
-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 snowflake"
37+
ALL_PARSERS="redshift postgresql cql snowflake tsql"
3838
# Add more parsers here as they are added to the repository
3939
# ALL_PARSERS="redshift mysql postgresql"
4040

tsql/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+
antlr -Dlanguage=Go -package tsql -visitor -o . TSqlLexer.g4 TSqlParser.g4
5+
6+
test:
7+
go test -v -run TestTSQLParser

tsql/README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
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).
2+
3+
## Build
4+
5+
Before build, you need to install the ANTLR4.
6+
7+
requirements:
8+
9+
- https://github.com/antlr/antlr4/blob/master/doc/getting-started.md
10+
- https://github.com/antlr/antlr4/blob/master/doc/go-target.md
11+
12+
```bash
13+
./build.sh
14+
```
15+
16+
## Update grammar
17+
18+
### Manually change the grammar file in this project
19+
20+
1. run `./build.sh` to generate the parser code.
21+
22+
### From antlr4-grammars-tsql
23+
24+
1. Clone the `TSqlLexer.g4` and `TSqlParser.g4` grammar files from https://github.com/antlr/grammars-v4/tree/master/sql/snowflake.
25+
2. Clone the examples[https://github.com/antlr/grammars-v4/tree/master/sql/tsql/examples], and use it for test.
26+
3. run `./build.sh` to generate the parser code.
27+
28+
## Test the parser
29+
30+
Run `TestTSQLParser` in `parser_test.go` to test the parser.
31+
32+
```bash
33+
go test -v
34+
```
35+
36+
## References
37+
38+
- ANTLR4 Getting Started https://github.com/antlr/antlr4/blob/master/doc/getting-started.md
39+
- ANTLR4 Go Garget https://github.com/antlr/antlr4/blob/master/doc/go-target.md
40+
41+
## Port
42+
43+
Port folder contains the ported code in another language.

tsql/TSqlLexer.g4

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

0 commit comments

Comments
 (0)