npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

tree-sitter-mssql

v0.1.6

Published

Tree-sitter grammar for Microsoft SQL Server T-SQL

Readme

tree-sitter-mssql

A tree-sitter grammar for Microsoft SQL Server Transact-SQL (T-SQL).

Scope: T-SQL only. This is not a general or multi-dialect SQL grammar. PostgreSQL, MySQL, SQLite, Hive, Spark, and Snowflake syntax are out of scope; the rule set inherited from the upstream's other dialects has been removed rather than maintained.

SQL Server versions. One grammar accepts the union of every version's syntax, from what SQL Server 2008 accepted through the current release and Azure SQL. A tree-sitter parser has no runtime switch, and a consumer meets a file on disk without knowing the server it targets, so the grammar never refuses a construct on version grounds. Deprecated syntax that still executes (SETUSER, READTEXT, the bare (NOLOCK) hint) is in scope, since a linter has to see it to flag it. A version-specific construct gets its own node kind so a downstream rule can flag it against a target version, and the corpus test that introduces one names the minimum version.

Status: Procedure, function, and trigger bodies (DML, DDL and logon triggers), control flow (IF/ELSE, WHILE, TRY/CATCH, RETURN, GOTO), transactions, variables and table variables, cursors, MERGE, OUTPUT, CROSS/OUTER APPLY, PIVOT/UNPIVOT, FOR XML/JSON, OFFSET/FETCH, RAISERROR/THROW, table and query hints, TOP, the full CREATE/ALTER/DROP surface for tables, constraints, indexes, views, types, sequences, synonyms, schemas, users, logins and roles, GRANT/REVOKE/DENY, the SSMS script header and GO, SMO-scripted objects with no statement separators, and bracketed parameterized types all parse. Not yet consumed by any downstream project.

This project started as a fork of tree-sitter-sql by Derek Stride (MIT licensed; see LICENSE and NOTICE). The general-SQL core — expression precedence, SELECT, CTEs, joins, window functions — comes from that project largely unchanged. The T-SQL-specific surface is added on top, and the upstream's other-dialect surface is gone.

Building

npx [email protected] -- tree-sitter generate
cargo build

The generated parser (src/parser.c, src/grammar.json, src/node-types.json) is committed, so consumers can build the C parser through cc during cargo build without needing the tree-sitter CLI themselves. Regenerate and commit the diff after any grammar.js change.

The block comment is lexed by src/scanner.c rather than a regex, because T-SQL block comments nest and a regex cannot match balanced nesting. src/scanner.c must be compiled alongside src/parser.c — vendoring one without the other produces a link error or a parser that cannot lex a block comment.

generate takes under a minute on this grammar. Run it with a time cap and read the exit code, and check that src/parser.c's modification time moved before trusting a test run — a failed generate leaves the previous parser in place.

Testing

tree-sitter test

On a machine without MSVC, point the CLI at another C compiler:

CC=gcc CXX=g++ tree-sitter test

test/corpus/ holds the per-construct tree assertions.

License

MIT — see LICENSE and NOTICE.