DotGram.Sql
0.1.0
dotnet add package DotGram.Sql --version 0.1.0
NuGet\Install-Package DotGram.Sql -Version 0.1.0
<PackageReference Include="DotGram.Sql" Version="0.1.0" />
<PackageVersion Include="DotGram.Sql" Version="0.1.0" />
<PackageReference Include="DotGram.Sql" />
paket add DotGram.Sql --version 0.1.0
#r "nuget: DotGram.Sql, 0.1.0"
#:package DotGram.Sql@0.1.0
#addin nuget:?package=DotGram.Sql&version=0.1.0
#tool nuget:?package=DotGram.Sql&version=0.1.0
DotGram.Sql
SQL parsers written in .gram, with typed syntax trees and SQL writers. Where an
example shows one feature, a parser here is written against a whole specification.
They are ordinary C# libraries. .Gram generates the parsers into this assembly at compile time, so nothing here carries a parser runtime, and neither does anything that references it.
The dialects
Each dialect has a directory, a namespace and a grammar of its own. SQL-92 and T-SQL use
the records in DotGram.Sql, with SqlWriter
to print them back and SqlWalker
to visit them. SQL:2023 uses the separate tree in DotGram.Sql.Ast and Sql2023Writer.
| Parser | Namespace | What it reads |
|---|---|---|
SqlStandardParser |
DotGram.Sql.Standard |
ISO SQL:2023, in part: its lexical elements, names, scalar expressions, aggregates and window functions, the JSON functions, query expressions with row pattern recognition, predicates, the data change statements, the whole schema — tables, views, domains, sequences, privileges, routines, triggers, user-defined types, casts, orderings, transforms, character sets and collations — and the transaction, session, connection, diagnostics, dynamic and direct statements |
Sql92Parser |
DotGram.Sql.Standard |
SQL-92 as the standard writes it |
TransactSqlParser |
DotGram.Sql.TransactSql |
SQL Server's T-SQL, as the engine reads it |
The third names the second — [GramInclude(typeof(Sql92Parser), As = "Sql92")] — and
rebinds the rules where T-SQL differs, so what the two languages share is written once and the
dialect is the size of the difference.
TransactSqlParser builds the T-SQL tree, and Sql92Parser the expressions in it that the two share.
SqlStandardParser builds the SQL:2023 tree in
Sql2023Ast.cs:
names, literals, data types, expressions, queries, data change statements, schema definitions,
and the other statements listed above. Its published productions return typed values.
Sql2023Writer
writes the tree back as SQL; tests parse that text again and compare the trees.
SqlStandardParser publishes the standard's productions under their own names —
ParseValueExpression, ParseSearchCondition, ParseQueryExpression, ParseSQLSchemaStatement
and the rest listed at the end of its grammar. TransactSqlParser publishes ParseSelect,
ParseQuery, ParseSearchCondition, ParseValueExpression, ParseStatement, ParseSql and
ParseScript, each with its TryParse….
Sql92Parser and TransactSqlParser read through a lexical split (Lexical = true): a lexical
half makes tokens, and the syntactic half above it decides each choice by the token in front of
it, which is what a parser written by hand does.
using DotGram.Sql;
using DotGram.Sql.TransactSql;
var match = TransactSqlParser.TryParseSelect("select name from Users where id > @id");
var select = (Statement.Select)match.Value;
var query = (Query.Specification)select.Of;
query.From[0]; // TableReference.Named { Table = "Users" }
A database's compatibility level gates a small part of what SQL Server reads — the WINDOW
clause from 160, OPENJSON's schema from 130. TransactSqlParser.ParseStatement130 reads what
the engine reads at level 130, and so on from 100 to 170; ParseStatement names no level and
reads them all. The levels are one grammar and one machine, told apart by a number, and what each
gates is held against SQL Server.
TransactSqlParser.ParseStatement reads one statement. TransactSqlParser.ParseSql reads a text
of them — what a client sends the server in one call — and gives back a Statement[]: each ended
by a ; or by nothing, except before a WITH, which needs the statement before it ended, as the
server does. ParseSql100 to ParseSql170 are its levels.
GO is not T-SQL: it is the line a client cuts a script at, and the server never sees it.
TransactSqlParser.ParseScript reads a script — batches cut apart at the lines that say GO, the
way ScriptDom and the management tools cut them — and gives back a Batch[], each with its
statements and the GO line that ended it. GO 5, a batch sent five times, is read too.
ParseScript100 to ParseScript170 are its levels. ParseSql is one batch, and a GO in it is
refused.
Where each node was written is there for whoever asks for it. TransactSqlParser.Located is the
same grammar compiled with LocationType = typeof(ISqlSpan) —
TransactSqlParser.Located.TryParseStatement — and every node it builds carries in Span the
range of text it was read from. TransactSqlParser itself pays nothing for them.
The tree they build is described in docs/ast.md.
What they read is held against SQL Server itself, against a corpus of somebody else's SQL and
against a round trip — parse, print, and compare the two readings — which catches a parser that
answers yes and builds the wrong thing.
Taking one
<PackageReference Include="DotGram.Sql" Version="0.1.0" />
There is no companion runtime package, and no generator to install alongside it: the parsers were generated when this assembly was compiled.
The package targets netstandard2.0 and net10.0. On netstandard2.0 it depends on
System.Memory; on net10.0 it has no package dependencies.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- System.Memory (>= 4.6.3)
-
net10.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 0.1.0 | 51 | 9/15/2026 |
First release: SQL:2023 parsing with a typed syntax tree and SQL writer; SQL-92 and T-SQL sharing a separate tree, writer and walker, with T-SQL parsers for SQL Server compatibility levels from 100 to 170.