Skip to content

Commit 9b89527

Browse files
committed
Expand CLAUDE.md with comprehensive development guide
Add detailed documentation including: - Next test workflow using cmd/next-test - Step-by-step implementation workflow - Test structure and flags documentation - TsqlAstParser setup and usage instructions - Important rules about not modifying ast.json files
1 parent cc6d5ec commit 9b89527

File tree

1 file changed

+99
-5
lines changed

1 file changed

+99
-5
lines changed

CLAUDE.md

Lines changed: 99 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,26 @@
1-
# Parser Development Notes
1+
# Claude Development Guide
2+
3+
## Next Steps
4+
5+
To find the next test to work on, run:
6+
7+
```bash
8+
go run ./cmd/next-test
9+
```
10+
11+
This tool finds all tests with `todo: true` in their metadata and returns the one with the shortest `query.sql` file.
12+
13+
## Workflow
14+
15+
1. Run `go run ./cmd/next-test` to find the next test to implement
16+
2. Check the test's `query.sql` to understand what SQL needs parsing
17+
3. Check the test's `ast.json` to understand the expected output format
18+
4. Implement the necessary AST types in `ast/`
19+
5. Add parser logic in `parser/parser.go`
20+
6. Add JSON marshaling functions in `parser/parser.go`
21+
7. Enable the test by removing `todo: true` from its `metadata.json` (set it to `{}`)
22+
8. Run `go test ./parser/... -timeout 5s` to verify
23+
9. Check if other todo tests now pass (see below)
224

325
## Running Tests
426

@@ -10,12 +32,84 @@ go test ./parser/... -timeout 5s
1032

1133
The tests are very fast. If a test is timing out, it indicates a bug (likely an infinite loop in the parser).
1234

13-
## Checking Skipped Tests
35+
## Checking for Newly Passing Todo Tests
1436

15-
After fixing parser issues, check if any skipped tests now pass:
37+
After implementing parser changes, run:
1638

1739
```bash
18-
go test ./parser -check-skipped -v 2>&1 | grep "PASSES NOW"
40+
go test ./parser/... -only-todo -v 2>&1 | grep "PASS:"
1941
```
2042

21-
Tests that output `PASSES NOW` can have their `todo` flag removed from `metadata.json`. This helps identify when parser improvements fix multiple tests at once.
43+
This shows any todo tests that now pass. Enable those tests by removing `todo: true` from their `metadata.json`.
44+
45+
Available test flags:
46+
47+
- `-only-todo` - Run only todo/invalid_syntax tests (find newly passing tests)
48+
- `-run-todo` - Run todo/invalid_syntax tests along with normal tests
49+
50+
## Test Structure
51+
52+
Each test in `parser/testdata/` contains:
53+
54+
- `metadata.json` - `{}` for enabled tests, `{"todo": true}` for pending tests, or `{"invalid_syntax": true}` for tests with invalid SQL
55+
- `query.sql` - T-SQL to parse
56+
- `ast.json` - Expected AST output
57+
58+
## Important Rules
59+
60+
**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.
61+
62+
## Generating ast.json with TsqlAstParser
63+
64+
The `TsqlAstParser/` directory contains a C# tool that generates `ast.json` files using Microsoft's official T-SQL parser (ScriptDom).
65+
66+
### Prerequisites
67+
68+
1. Install .NET 8.0 SDK:
69+
70+
```bash
71+
curl -sSL https://dot.net/v1/dotnet-install.sh | bash /dev/stdin --channel 8.0 --install-dir ~/.dotnet
72+
```
73+
74+
2. Download the NuGet package (if `packages/` directory is empty):
75+
76+
```bash
77+
mkdir -p packages
78+
curl -L -o packages/microsoft.sqlserver.transactsql.scriptdom.170.128.0.nupkg \
79+
"https://api.nuget.org/v3-flatcontainer/microsoft.sqlserver.transactsql.scriptdom/170.128.0/microsoft.sqlserver.transactsql.scriptdom.170.128.0.nupkg"
80+
```
81+
82+
3. Build the tool:
83+
84+
```bash
85+
~/.dotnet/dotnet build TsqlAstParser -c Release
86+
```
87+
88+
### Usage
89+
90+
Generate `ast.json` for a single test:
91+
92+
```bash
93+
~/.dotnet/dotnet run --project TsqlAstParser -c Release -- parser/testdata/TestName/query.sql parser/testdata/TestName/ast.json
94+
```
95+
96+
Generate `ast.json` for all tests missing it:
97+
98+
```bash
99+
for dir in parser/testdata/*/; do
100+
if [ -f "$dir/query.sql" ] && [ ! -f "$dir/ast.json" ]; then
101+
~/.dotnet/dotnet run --project TsqlAstParser -c Release -- "$dir/query.sql" "$dir/ast.json"
102+
fi
103+
done
104+
```
105+
106+
### Limitations
107+
108+
TsqlAstParser uses TSql160Parser (SQL Server 2022) and cannot parse:
109+
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)