Scannerless Tree-sitter grammar (ABI 15) for TypeSpec, targeting TypeSpec 1.0+ and 2026 language additions.
- Core declarations:
import,using,namespace(block and blockless),model(extends,is, spread..., optional?, default values, quoted and backtick property names),scalar(extends,init),interface(extends,op),op,union,enum(spread..., string/numeric values),alias,const(with optional type annotations),extern dec,@@augment decorators, and#suppress/#deprecateddirectives. - 2026 TypeSpec additions:
union ... extends ...,extern fndeclarations,fn(...) => ...function type expressions, call expressions,internalandautomodifiers, and inline declaration expressions (model,enum,union,scalar). - Expressions and literals: union (
|, including leading|), intersection (&, including leading&), array (T[]),typeof,valueof, templates with positional and named arguments, member.and meta-property::selectors,#{}object literals,#[]array literals, tuples, quoted and triple-quoted multiline strings with${...}template substitutions, numeric/boolean literals, andvoid/never/unknown.
//:parser— C11 static library (src/parser.c).//:libtree_sitter_typespec.so— shared library exportingtree_sitter_typespecfor dynamic consumers such asast-grepcustomLanguages.//:generate— hermeticwrite_source_filestarget (with built-in drift tests) regeneratingsrc/parser.c,src/grammar.json, andsrc/node-types.jsonfromgrammar.js.//bindings/rust:treesitter_typespec— Rust library exposingLANGUAGE(tree_sitter_language::LanguageFn),NODE_TYPES, and bundled query strings (HIGHLIGHTS_QUERY,FOLDS_QUERY,INDENTS_QUERY,LOCALS_QUERY).//bindings/rust:treesitter_typespec_test— Rust unit tests verifying parsing and query compilation.//bindings/rust/corpus:corpus_test— Rust test runningtest/corpus/*.txtS-expression expectations under Bazel.//bindings/rust/upstream_corpus:upstream_spec_corpus_test— Rust test validating zero parse errors across all stdlib.tspfiles from//:node_modules/@typespec/*.
Build //:libtree_sitter_typespec.so and register it under customLanguages in sgconfig.yml:
customLanguages:
typespec:
libraryPath: bazel-bin/libtree_sitter_typespec.so
extensions: [tsp]
expandoChar: '$'bazel run //:generate
bazel test //...Apache-2.0 for the grammar and bindings; see LICENSE.
Bundled Tree-sitter C headers in src/tree_sitter/ are MIT-licensed; see src/tree_sitter/LICENSE.