Skip to content

Commit 447d15b

Browse files
committed
add ScriptDOM code
1 parent 7f19e55 commit 447d15b

2,232 files changed

Lines changed: 354239 additions & 23 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.build/AssemblyInfo.props‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project>
3+
<PropertyGroup>
4+
<Description>
5+
SQL Script DOM is a .NET library that provides formatting and parsing capabilities to analyze SQL Scripts. It can be used by Powershell and C#.
6+
</Description>
7+
<Authors>Microsoft</Authors>
8+
<Company>Microsoft Corporation</Company>
9+
<BaseProduct>Microsoft Sql Server</BaseProduct>
10+
<Copyright>© Microsoft Corporation. All rights reserved.</Copyright>
11+
</PropertyGroup>
12+
</Project>

‎.build/Signing.props‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
2+
<!-- Import this props file for signing properties -->
3+
<PropertyGroup>
4+
<!-- By default we delay sign our assemblies, so they are ready tof real signing at a later stage. -->
5+
<!-- Individual project (like the ancillary tools that we use during the build which do no ship) typically override these values so they can run normally during the build, without having to disbale SNV. -->
6+
<DelaySign>true</DelaySign>
7+
<SignAssembly>true</SignAssembly>
8+
<!-- This SNK file is used to sign almost all DacFx binaries (SQLDOM uses a different one) -->
9+
<LinkKeyFile>$(EnlistmentRoot)\Externals\VS12\VS10_FinalPublicKey.snk</LinkKeyFile>
10+
<AssemblyOriginatorKeyFile>$(EnlistmentRoot)\Externals\VS12\VS10_FinalPublicKey.snk</AssemblyOriginatorKeyFile>
11+
<ShippingScope>External</ShippingScope>
12+
</PropertyGroup>
13+
</Project>

‎.gitignore‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,3 +348,12 @@ MigrationBackup/
348348

349349
# Ionide (cross platform F# VS Code tools) working folder
350350
.ionide/
351+
352+
# Project solution
353+
*.sln
354+
355+
# Project output folder
356+
out/
357+
358+
# Project packages folder
359+
.packages/

‎CONTRIBUTING.md‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
3+
---
4+
5+
# Contributing
6+
7+
Welcome and thank you for your interest
8+
in contributing to **Sql Script DOM**! Before contributing to this
9+
project, please review this document for policies and procedures which
10+
will ease the contribution and review process for everyone.
11+
12+
## Issues and Feature Requests
13+
14+
Before filing an issue, please make sure that the issue has not been submitted before in our public repository [Sql Script DOM](https://github.com/microsoft/SqlScriptDOM/issues).
15+
16+
To report a new issue please add the **bug** tag and use the **enhancement** tag for new feature proposals.
17+
18+
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.
19+
20+
## Pull Request Process
21+
22+
If you are interested in fixing issues and adding new features, please follow our [README.md](./README.md) page to set up your environment.
23+
24+
Before sending a Pull Request, please do the following:
25+
26+
1. Ensure builds are still successful and tests, including any added or updated tests, pass prior to submitting the pull request.
27+
2. Update any documentation, user and contributor, that is impacted by your changes.
28+
3. Include your change description in `CHANGELOG.md` file as part of pull request.
29+
4. 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.
30+
31+
## License Information
32+
Copyright (c) Microsoft Corporation. All rights reserved.
33+
34+
Licensed under the [Source MIT](LICENSE).

‎Directory.Build.props‎

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
This root MSBuild file is automatically imported for all projects in the tree by MSBuild 15.0.
4+
You can have a hierarchy of imports but make sure that this file is still imported.
5+
-->
6+
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
7+
<PropertyGroup Label="Global locations">
8+
<!--
9+
$(MSBuildAllProjects) is a list of files that determine if a project is up-to-date or not. By including this
10+
file in the list, it ensures that all projects will be rebuilt if it changes.
11+
-->
12+
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
13+
14+
<!-- By default we build the XMLDOC files -->
15+
<GenerateDocumentationFile>true</GenerateDocumentationFile>
16+
17+
<!--
18+
Enlistment root is based off of wherever this file is. Be sure not to set this property anywhere else.
19+
-->
20+
<EnlistmentRoot>$(MSBuildThisFileDirectory.TrimEnd('\\'))</EnlistmentRoot>
21+
<!-- .build folder path, which can also be used for other purpose in future, this path is used to import the props file-->
22+
<BuildPropsDir>$(EnlistmentRoot)\.build</BuildPropsDir>
23+
24+
<!-- This is the location where we restore/install the nuget packages -->
25+
<RestorePackagesPath>$(EnlistmentRoot)\.packages</RestorePackagesPath>
26+
27+
<!-- This is the default target framework for all the projects.
28+
Individual projects may specify additional target frameworks -->
29+
<NetfxVersion>net462</NetfxVersion>
30+
<NetStandardVersion>netstandard2.1</NetStandardVersion>
31+
<NetCoreVersion>net6.0</NetCoreVersion>
32+
33+
<TargetFrameworks>$(NetStandardVersion);$(NetfxVersion);$(NetCoreVersion)</TargetFrameworks>
34+
<PreviewRelease Condition="'$(PreviewRelease)' == ''">false</PreviewRelease>
35+
<VersionProductName>Microsoft SQL Script DOM</VersionProductName>
36+
37+
<!-- Use this property for convenience to build a path starting from the root of the repository. -->
38+
39+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
40+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
41+
42+
<TargetFolder Condition="'$(TargetFolder)'==''">out</TargetFolder>
43+
<BaseOutputPath Condition="'$(BaseOutputPath)'==''">$(EnlistmentRoot)\$(TargetFolder)</BaseOutputPath>
44+
<OutputPath>$(BaseOutputPath)\$(Configuration)</OutputPath>
45+
46+
<!-- Path for tools output files, .exe executable generated files for tools can be found here -->
47+
<BuildToolsPath>$(BaseOutputPath)\tools\$(NetfxVersion)</BuildToolsPath>
48+
49+
<!-- put obj files in a mirror tree off the root to keep the src folder tree cleaner -->
50+
<BaseIntermediateOutputPath Condition=" '$(BaseIntermediateOutputPath)' == '' ">$(EnlistmentRoot)\obj\$([MSBuild]::MakeRelative('$(EnlistmentRoot)\', $(MSBuildProjectDirectory)))</BaseIntermediateOutputPath>
51+
</PropertyGroup>
52+
53+
<PropertyGroup>
54+
<NoWarn>1591</NoWarn>
55+
</PropertyGroup>
56+
57+
<Import Project="$(BuildPropsDir)\AssemblyInfo.props" />
58+
<Import Project="$(BuildPropsDir)\Signing.props" />
59+
</Project>

‎Directory.Build.targets‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<!-- This SDK is for using packages.props for Nuget references: https://github.com/Microsoft/MSBuildSdks/tree/main/src/CentralPackageVersions -->
2+
<Project Sdk="Microsoft.Build.CentralPackageVersions">
3+
</Project>
160 Bytes
Binary file not shown.

‎Packages.props‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<!-- This repo relies on the CentralPackageVersions SDK
2+
See https://github.com/Microsoft/MSBuildSdks/tree/main/src/CentralPackageVersions
3+
This file lists every nuget PackageReference dependency and its required version.
4+
Do not put Version attributes on PackageReference tags in individual projects.
5+
-->
6+
<Project>
7+
<PropertyGroup>
8+
<DotNetPackagesVersion>4.7.0</DotNetPackagesVersion>
9+
</PropertyGroup>
10+
<ItemGroup>
11+
<PackageReference Update="System.Buffers" Version="4.5.1" />
12+
<PackageReference Update="System.Diagnostics.DiagnosticSource" Version="5.0.0" />
13+
<PackageReference Update="System.Drawing.Common" Version="6.0.0" />
14+
<PackageReference Update="System.Runtime.CompilerServices.Unsafe" Version="5.0.0" />
15+
<PackageReference Update="System.Text.Encodings.Web" Version="5.0.1" />
16+
<PackageReference Update="System.Threading.Tasks.Dataflow" Version="4.9.0" />
17+
<PackageReference Update="System.Threading.Tasks.Extensions" Version="4.5.4" />
18+
<PackageReference Update="System.ValueTuple" Version="4.5.0" />
19+
20+
<!-- Test -->
21+
<PackageReference Update="Microsoft.NET.Test.Sdk" Version="17.3.0" />
22+
<PackageReference Update="MSTest.TestAdapter" Version="2.2.10" />
23+
<PackageReference Update="MSTest.TestFramework" Version="2.2.10" />
24+
</ItemGroup>
25+
</Project>

‎README.md‎

Lines changed: 103 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,113 @@
1-
# Project
1+
---
2+
ArtifactType: nupkg
3+
Documentation: URL
4+
Language: csharp, powershell
5+
Platform: dotnet
6+
Stackoverflow: URL
7+
Tags: ScriptDOM, SqlDOM
8+
---
29

3-
> This repo has been populated by an initial template to help get you started. Please
4-
> make sure to update the content to build a great experience for community-building.
10+
# SQL ScriptDOM
511

6-
As the maintainer of this project, please make a few updates:
12+
SQL Script DOM is a .NET library that provides formatting and parsing capabilities to analyze SQL Scripts. It can be used by Powershell and C#.
713

8-
- Improving this README.MD file to provide a great experience
9-
- Updating SUPPORT.MD with content about this project's support experience
10-
- Understanding the security reporting process in SECURITY.MD
11-
- Remove this section from the README
14+
Script DOM is used by DacFX and as an standalone library for client applications.
1215

16+
## Getting Started
17+
18+
1. Install Visual Studio 2022 or newer.
19+
20+
2. Download .NET SDKS from https://dotnet.microsoft.com/download/visual-studio-sdks
21+
- .NET Framework SDK (4.6.2 or higher)
22+
- .NET 6 SDK (see [global.json](./global.json) for latest version)
23+
3. Install the [SlnGen](https://microsoft.github.io/slngen/) tool.
24+
```cmd
25+
dotnet tool install --global Microsoft.VisualStudio.SlnGen.Tool
26+
```
27+
4. Install antlr-2.7.5.exe from https://www.antlr2.org/download.html
28+
29+
5. Create environment variable named Antlr2Exe pointing to the installation path.
30+
31+
6. Clone the repository
32+
```
33+
git clone https://github.com/microsoft/SqlScriptDOM
34+
```
35+
36+
### Building
37+
38+
Navigate to the root of the source code:
39+
```cmd
40+
cd C:\SqlScriptDOM\
41+
```
42+
Open Visual Studio solution
43+
```cmd
44+
slngen
45+
```
46+
47+
Restore project dependencies:
48+
```cmd
49+
msbuild /t:Restore
50+
```
51+
52+
To build:
53+
```cmd
54+
msbuild
55+
```
1356
## Contributing
57+
Notes for SQLDOM extensions:
58+
59+
1. Make the changes in
60+
For changing the DOM classes, modify the XML file (the C# code is generated based on this during the build process)
61+
$(EnlistmentRoot)\Source\SqlDom\SqlScriptDom\Parser\TSql\Ast.xml
62+
Change Ast.xml to put the class pieces on their appropriate statements
63+
64+
Note for above:
65+
1. The build process is defined in ```$(EnlistmentRoot)\Source\SqlDom\SqlScriptDom\SqlScriptDom.props``` (Target Name="CreateAST")
66+
2. The generated files are dropped in ```$(EnlistmentRoot)\obj\<x64|x86>\<Debug|Release>\SqlScriptDom.csproj\```
67+
68+
For changing the parser, modify the .g file here:
69+
```$(EnlistmentRoot)\Source\SqlDom\SqlScriptDom\Parser\TSql\TSql<#>.g``` where # is the version (ie - 100, 120, 130). This will usually be the latest number if adding new grammar.
70+
Change the Tsql(xxx).g file to parse the new syntax.
71+
72+
Note for above:
73+
1. The build process is defined in ```$(EnlistmentRoot)\Source\SqlDom\SqlScriptDom\SqlScriptDom.props``` (Target Name="CreateAST")
74+
2. The generated files are dropped in ```$(EnlistmentRoot)\obj\x86|x64\Debug|Release\sqlscriptdom.csproj\```
75+
76+
For changing the ScriptGenerator, modify the appropriate file
77+
(i.e. Visitor that accepts the modified DOM class) in here
78+
```$(EnlistmentRoot)\Source\SqlDom\SqlScriptDom\ScriptDom\SqlServer\ScriptGenerator```
79+
To add a new ScriptGenerator, you need to add the file to ```$(EnlistmentRoot)\Source\SqlDom\SqlScriptDom\SqlScriptDom.props```
80+
Change The visitors SqlScriptGenerator.X to use the new piece from AST.XML
81+
If you're adding syntax that's Azure-only or Standalone-only, implement appropriate Versioning Visitor for your constructs.
1482

15-
This project welcomes contributions and suggestions. Most contributions require you to agree to a
16-
Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us
17-
the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.
83+
2. When adding/removing new files please add/remove an entry to/from ```$(EnlistmentRoot)\Source\SqlDom\SqlScriptDom\SqlScriptDom.csproj```
84+
85+
3. To extend the tests do the following:
86+
a. Baselines# needs to be updated or added with the appropriate .sql file as expected results.
87+
b. The Only#SyntaxTests.cs needs to be extended or added to specify the appropriate TestScripts script.
88+
c. Positive tests go in Only#SyntaxTests.cs if adding new grammar.
89+
d. 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#)
90+
e. Negative tests go in ParserErrorsTests.cs.
91+
92+
## Running the tests
93+
94+
You can run tests directly in Visual Studio Text Explorer or by using the ```dotnet test``` command.
95+
96+
Example: To run all priority 0 tests
97+
```cmd
98+
dotnet test --filter Priority=0
99+
```
100+
101+
## Built With
102+
* https://www.antlr.org/
103+
* https://www.gnu.org/software/sed/manual/sed.html
104+
105+
## Contributing
18106

19-
When you submit a pull request, a CLA bot will automatically determine whether you need to provide
20-
a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions
21-
provided by the bot. You will only need to do this once across all repos using our CLA.
107+
Please read our [CONTRIBUTING.md](CONTRIBUTING.md) which outlines all of our policies, procedures, and requirements for contributing to this project.
22108

23-
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
24-
For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or
25-
contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
109+
## License
26110

27-
## Trademarks
111+
Copyright (c) Microsoft Corporation. All rights reserved.
28112

29-
This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft
30-
trademarks or logos is subject to and must follow
31-
[Microsoft's Trademark & Brand Guidelines](https://www.microsoft.com/en-us/legal/intellectualproperty/trademarks/usage/general).
32-
Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship.
33-
Any use of third-party trademarks or logos are subject to those third-party's policies.
113+
Licensed under the [Source MIT](LICENSE).

0 commit comments

Comments
 (0)