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!