Skip to content

Commit d1abae3

Browse files
committed
Add TsqlAstParser documentation to CLAUDE.md
Document how to use the TsqlAstParser C# tool to generate ast.json files for test cases. Include prerequisites (.NET SDK, NuGet package), usage examples, and limitations (unsupported SQL Server 170 features, Fabric DW syntax, deprecated/error test cases).
1 parent 9db8f34 commit d1abae3

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

CLAUDE.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,52 @@ Each test in `parser/testdata/` contains:
6464
## Important Rules
6565

6666
- **NEVER modify `ast.json` files** - These are golden files containing the expected output. If tests fail due to JSON mismatches, fix the Go code to match the expected output, not the other way around.
67+
68+
## Generating ast.json with TsqlAstParser
69+
70+
The `TsqlAstParser/` directory contains a C# tool that generates `ast.json` files using Microsoft's official T-SQL parser (ScriptDom).
71+
72+
### Prerequisites
73+
74+
1. Install .NET 8.0 SDK:
75+
```bash
76+
curl -sSL https://dot.net/v1/dotnet-install.sh | bash /dev/stdin --channel 8.0 --install-dir ~/.dotnet
77+
```
78+
79+
2. Download the NuGet package (if `packages/` directory is empty):
80+
```bash
81+
mkdir -p packages
82+
curl -L -o packages/microsoft.sqlserver.transactsql.scriptdom.170.128.0.nupkg \
83+
"https://api.nuget.org/v3-flatcontainer/microsoft.sqlserver.transactsql.scriptdom/170.128.0/microsoft.sqlserver.transactsql.scriptdom.170.128.0.nupkg"
84+
```
85+
86+
3. Build the tool:
87+
```bash
88+
~/.dotnet/dotnet build TsqlAstParser -c Release
89+
```
90+
91+
### Usage
92+
93+
Generate `ast.json` for a single test:
94+
```bash
95+
~/.dotnet/dotnet run --project TsqlAstParser -c Release -- parser/testdata/TestName/query.sql parser/testdata/TestName/ast.json
96+
```
97+
98+
Generate `ast.json` for all tests missing it:
99+
```bash
100+
for dir in parser/testdata/*/; do
101+
if [ -f "$dir/query.sql" ] && [ ! -f "$dir/ast.json" ]; then
102+
~/.dotnet/dotnet run --project TsqlAstParser -c Release -- "$dir/query.sql" "$dir/ast.json"
103+
fi
104+
done
105+
```
106+
107+
### Limitations
108+
109+
TsqlAstParser uses TSql160Parser (SQL Server 2022) and cannot parse:
110+
- SQL Server 170+ features (VECTOR indexes, AI functions, JSON enhancements)
111+
- Fabric DW-specific syntax (CLONE TABLE, CLUSTER BY)
112+
- Deprecated syntax removed in newer versions
113+
- Intentionally invalid SQL (error test cases)
114+
115+
Tests for unsupported syntax will not have `ast.json` files generated.

0 commit comments

Comments
 (0)