Welcome to the SqlScriptDOM documentation! This folder contains comprehensive guides for understanding, developing, and debugging the SQL Server T-SQL parser.
New to the project? Start here:
- Read copilot-instructions.md - Main project documentation
- Browse debugging_workflow.guidelines.instructions.md - Visual quick reference
Fixing a bug? Start here:
- Open debugging_workflow.guidelines.instructions.md - Identify bug type
- Follow the flowchart to the appropriate guide
- Use the step-by-step instructions
copilot-instructions.md - START HERE
Purpose: Main project documentation and overview
Contains:
- Project structure and key files
- Build and test commands
- Developer workflow
- Bug fixing triage
- Debugging tips
- Grammar gotchas and pitfalls
When to read: First time working on the project, or for general context
debugging_workflow.guidelines.instructions.md - QUICK REFERENCE
Purpose: Visual guide for quick bug diagnosis
Contains:
- Diagnostic flowchart
- Error pattern recognition
- Investigation steps
- Testing commands reference
- Key files reference
- Common pitfalls
When to use: When you have a bug and need to quickly identify what type of fix is needed
Validation_fix.guidelines.instructions.md - Most Common Fix Type β
Purpose: Fixing validation-based bugs
When to use:
- β Error: "Option 'X' is not valid..." or "Feature not supported..."
- β Same syntax works in different context (e.g., ALTER INDEX vs ALTER TABLE)
- β SQL Server version-specific features
Contains:
- Real-world example (ALTER TABLE ADD CONSTRAINT RESUMABLE)
- Version flag patterns
- Validation logic modification
- Testing strategy
Complexity: β Easy
Typical time: 1-2 hours
bug_fixing.guidelines.instructions.md - Grammar Changes
Purpose: Adding new syntax or modifying parser grammar
When to use:
- β Error: "Incorrect syntax near..." or "Unexpected token..."
- β Parser doesn't recognize new T-SQL features
- β Need to add new keywords, operators, or statements
Contains:
- Complete bug-fixing workflow
- Grammar modification process
- AST updates
- Script generator changes
- Baseline generation
- Decision tree for bug types
Complexity: βββ Medium to Hard
Typical time: 4-8 hours
Purpose: Fixing parentheses recognition issues
When to use:
- β
WHERE PREDICATE(...)works - β
WHERE (PREDICATE(...))fails with syntax error - β Identifier-based boolean predicates
Contains:
IsNextRuleBooleanParenthesis()modification- Predicate detection patterns
- Real example (REGEXP_LIKE)
Complexity: ββ Easy-Medium
Typical time: 1-3 hours
Purpose: Common patterns for extending existing grammar
When to use:
- β Need to extend literal types to accept expressions
- β Adding new enum members
- β Creating new function/statement types
Contains:
- Literal to expression pattern
- Real example (VECTOR_SEARCH TOP_N)
- Context-specific grammar rules
- Shared rule warnings
Complexity: βββ Medium
Typical time: 3-6 hours
Purpose: Summary of documentation improvements
Contains:
- What was improved and why
- Before/after comparison
- Real-world validation (ALTER TABLE RESUMABLE)
- Lessons learned
When to read: If you want to understand the documentation structure and evolution
βββββββββββββββββββββββββββββββββββ
β You have a parsing bug β
βββββββββββββ¬ββββββββββββββββββββββ
β
βΌ
βββββββββββββββββ
β What's the β
β error message?β
βββββββββ¬ββββββββ
β
ββββββββββΌβββββββββ
β β β
βΌ βΌ βΌ
ββββββββ ββββββββ ββββββββ
βOptionβ βSyntaxβ βParensβ
βerror β βerror β βbreak β
ββββ¬ββββ ββββ¬ββββ ββββ¬ββββ
β β β
βΌ βΌ βΌ
ββββββββ ββββββββ ββββββββ
βVALID-β βBUG β βPARSERβ
βATION β βFIXINGβ βPRED β
βFIX β βGUIDE β βRECOG β
ββββββββ ββββββββ ββββββββ
| Error Message | Bug Type | Guide | Complexity |
|---|---|---|---|
| "Option 'X' is not valid in statement Y" | Validation | Validation_fix.guidelines.instructions.md | β Easy |
| "Feature 'X' not supported in version Y" | Validation | Validation_fix.guidelines.instructions.md | β Easy |
| "Incorrect syntax near keyword" | Grammar | bug_fixing.guidelines.instructions.md | βββ Medium |
| "Unexpected token" | Grammar | bug_fixing.guidelines.instructions.md | βββ Medium |
| Syntax error with parentheses only | Predicate Recognition | parser.guidelines.instructions.md | ββ Easy-Medium |
| Need to extend literal to expression | Grammar Extension | GRAMMAR_EXTENSION_PATTERNS | βββ Medium |
Example: ALTER TABLE ... WITH (RESUMABLE = ON) fails
Likely Issue: Validation blocking the option
Start With: VALIDATION_FIX_GUIDE.md
Example: CREATE EXTERNAL TABLE not recognized
Likely Issue: Grammar doesn't have rules for this syntax
Start With: BUG_FIXING_GUIDE.md
Example: WHERE REGEXP_LIKE(...) fails
Likely Issue: Predicate recognition
Start With: PARSER_PREDICATE_RECOGNITION_FIX.md
Example: TOP_N = @parameter should work
Likely Issue: Need to extend from literal to expression
Start With: GRAMMAR_EXTENSION_PATTERNS.md
# Build parser
dotnet build SqlScriptDom/Microsoft.SqlServer.TransactSql.ScriptDom.csproj -c Debug
# Run specific test
dotnet test --filter "FullyQualifiedName~YourTest" -c Debug
# Run ALL tests (CRITICAL before committing!)
dotnet test Test/SqlDom/UTSqlScriptDom.csproj -c Debug
# Search for error code
grep -r "SQL46057" SqlScriptDom/
# Search for option usage
grep -r "RESUMABLE" Test/SqlDom/TestScripts/- Total Guides: 6 comprehensive guides
- Bug Types Covered: 3 main types (validation, grammar, predicate recognition)
- Real-World Examples: 4 detailed examples with code
- Code Samples: 50+ practical bash/C#/SQL examples
- Quick References: 3 tables and 2 flowcharts
- copilot-instructions.md - Read "Key points" section
- debugging_workflow.guidelines.instructions.md - Understand bug types
- Validation_fix.guidelines.instructions.md - Follow ALTER TABLE RESUMABLE example
- Try fixing a validation bug yourself
Time: 2-3 hours
- Review beginner path first
- bug_fixing.guidelines.instructions.md - Complete workflow
- grammer.guidelines.instructions.md - Common patterns
- copilot-instructions.md - "Grammar Gotchas" section
- Try adding a simple new keyword
Time: 4-6 hours
- Master beginner and intermediate paths
- bug_fixing.guidelines.instructions.md - AST modifications
- grammer.guidelines.instructions.md - All patterns
- Study existing complex features (e.g., VECTOR_SEARCH)
- Implement a new statement type
Time: 8-16 hours
- β Run full test suite before committing (1,100+ tests)
- β Check Microsoft docs for exact version support
- β Search for error messages first before coding
- β Create context-specific rules instead of modifying shared ones
- β Test across all SQL Server versions in test configuration
- β Modify shared grammar rules without understanding impact
- β Skip running the full test suite
- β Assume version support - always verify documentation
- β Edit generated files in
obj/directory - β Commit without testing baseline generation
When improving these docs:
- Use real examples from actual bugs
- Include complete code samples (not pseudo-code)
- Add bash commands that actually work
- Cross-reference related guides
- Update this README if adding new guides
If stuck:
- Search error message in codebase:
grep -r "your error" - Check similar working syntax:
grep -r "keyword" Test/SqlDom/ - Review relevant guide based on bug type
- Check Git history for similar fixes:
git log --grep="RESUMABLE"
You know you've succeeded when:
- β Your specific test passes
- β ALL 1,100+ tests pass (critical!)
- β Baseline matches generated output
- β Version-specific behavior is correct
- β No regressions in existing functionality
Last Updated: Based on ALTER TABLE RESUMABLE fix (October 2025)
Contributors: Documentation improved based on practical bug-fixing experience
Feedback: These guides are living documents. Please update them when you discover new patterns or better approaches!