Welcome and thank you for your interest in contributing to Sql Script DOM! Before contributing to this project, please review this document for policies and procedures which will ease the contribution and review process for everyone.
This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.
Before filing an issue, please make sure that the issue has not been submitted before in our public repository Sql Script DOM.
To report a new issue please add the bug tag and use the enhancement tag for new feature proposals.
Please create an issue per bug and include the version of Sql Script DOM where you are experiencing the issue, the steps to repro the bug, include error messages if applicable, and add a description of the expected result versus the actual result.
Please create an issue per feature request and describe the current and desired behavior. If you have a proposed solution, please include it in the issue as well as whether you'd like to contribute the change.
This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.
When you submit a pull request, a CLA bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g. status check, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.
-
Download .NET SDKS from https://dotnet.microsoft.com/download/visual-studio-sdks
- .NET Framework SDK (4.6.2 or higher)
- .NET 6 SDK (see global.json for latest version)
-
Install Visual Studio 2022 or newer. (Optional)
-
Install the SlnGen tool. (Optional Visual Studio generator)
dotnet tool install --global Microsoft.VisualStudio.SlnGen.Tool
-
Run DisableStrongName script as administrator: disableStrongName.ps1 This step only needs to be done once.
-
Clone the repository
git clone https://github.com/microsoft/SqlScriptDOM
-
Download .NET SDKS from https://dotnet.microsoft.com/download/visual-studio-sdks
- .NET 6 SDK (see global.json for latest version)
-
Install the Java runtime (JRE)
- macOS:
brew install openjdk - Linux: see https://openjdk.org/install/
- macOS:
-
Install PowerShell Core
- macOS:
brew install powershell/tap/powershell - Linux: see https://learn.microsoft.com/powershell/scripting/install/installing-powershell-on-linux
- macOS:
-
Clone the repository
git clone https://github.com/microsoft/SqlScriptDOM
Navigate to the root of the source code:
cd SqlScriptDOMOptional, Windows-only - Generate and open Visual Studio solution. This step is not required to build the project.
slngenRestore project dependencies:
dotnet restoreTo build:
dotnet buildYou can run tests directly in Visual Studio Text Explorer or by using the dotnet test command.
Example: To run all priority 0 tests
dotnet test --filter Priority=0If you make ANY changes to grammar files (.g files) or AST definitions (Ast.xml), you MUST run the complete test suite to ensure no regressions:
dotnet test Test/SqlDom/UTSqlScriptDom.csproj -c DebugWhy this is critical for parser changes:
- Grammar changes can have far-reaching effects on seemingly unrelated functionality
- Shared grammar rules are used in multiple contexts throughout the parser
- AST modifications can affect script generation and visitor patterns across the entire codebase
- Token recognition changes can impact parsing of statements that don't even use the modified feature
Example of unexpected failures:
- Modifying a shared rule like
identifierColumnReferenceExpressioncan cause other tests to fail because the rule now accepts syntax that should be rejected in different contexts - Changes to operator precedence can affect unrelated expressions
- Adding new AST members without proper script generation support can break round-trip parsing
Always verify that all ~557 tests pass before submitting your changes.
Before sending a Pull Request, please do the following:
- For parser changes (grammar/AST modifications): Run the complete test suite (
dotnet test Test/SqlDom/UTSqlScriptDom.csproj -c Debug) and ensure all ~557 tests pass. Grammar changes can have unexpected side effects. - Ensure builds are still successful and tests, including any added or updated tests, pass prior to submitting the pull request.
- Update any documentation, user and contributor, that is impacted by your changes.
- Include your change description in
CHANGELOG.mdfile as part of pull request. - You may merge the pull request in once you have the sign-off of two other developers, or if you do not have permission to do that, you may request the second reviewer to merge it for you.
-
For changing the DOM classes, modify the XML file (the C# code is generated based on this during the build process)
SqlScriptDom\Parser\TSql\Ast.xml. Change Ast.xml to put the class pieces on their appropriate statements.- The build process is defined in
SqlScriptDom\GenerateFiles.props(Target Name="CreateAST") - The generated files are dropped in
obj\SqlScriptDom\AnyCPU\<Debug|Release>\<TargetPlatform>\Microsoft.SqlServer.TransactSql.ScriptDom.csproj\
When you modify
Source\SqlDom\SqlScriptDom\Parser\TSql\Ast.xmlor anyTSql<#>.ggrammar file, the C# parser and DOM sources are produced by MSBuild generation targets (for exampleCreateAST). These targets are invoked automatically during a normal build, so in most cases you can simply run:dotnet build Source\SqlDom\SqlScriptDom\Microsoft.SqlServer.TransactSql.ScriptDom.csproj -c DebugIf you only want to run generation targets (no compile) or need more detailed generation logs, invoke the MSBuild targets directly:
dotnet msbuild Source\SqlDom\SqlScriptDom\Microsoft.SqlServer.TransactSql.ScriptDom.csproj -t:GLexerParserCompile;GSqlTokenTypesCompile;CreateAST -p:Configuration=Debug
Generated files are written into the
objfolder for that project (for exampleobj\SqlScriptDom\AnyCPU\<Debug|Release>\<TargetPlatform>\Microsoft.SqlServer.TransactSql.ScriptDom.csproj\). If antlr or related tools are missing, seeDirectory.Build.propsforAntlrLocationand follow the repo guidance to supply the binaries. - The build process is defined in
-
For changing the parser, modify the .g file here:
SqlScriptDom\Parser\TSql\TSql<#>.gwhere # is the version (ie - 100, 120, 130). This will usually be the latest number if adding new grammar. Change the Tsql(xxx).g file to parse the new syntax.- The build process is defined in
SqlScriptDom\GenerateFiles.props(Target Name="CreateAST") - The generated files are dropped in
obj\SqlScriptDom\AnyCPU\<Debug|Release>\<TargetPlatform>\Microsoft.SqlServer.TransactSql.ScriptDom.csproj\
- The build process is defined in
-
For changing the ScriptGenerator, modify the appropriate file (i.e. Visitor that accepts the modified DOM class) in here:
SqlScriptDom\ScriptDom\SqlServer\ScriptGenerator.- Change The visitors SqlScriptGenerator.X to use the new piece from AST.XML
- If you're adding syntax that's Azure-only or Standalone-only, implement appropriate Versioning Visitor for your constructs.
-
To extend the tests do the following:
- Baselines# needs to be updated or added with the appropriate .sql file as expected results.
- The Only#SyntaxTests.cs needs to be extended or added to specify the appropriate TestScripts script.
- Positive tests go in Only#SyntaxTests.cs if adding new grammar.
- Create a \TestScripts script that is the input for the test. (This is what is run and is checked against the .sql files in Baselines#)
- Negative tests go in ParserErrorsTests.cs.