Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

treesitter-typespec

Scannerless Tree-sitter grammar (ABI 15) for TypeSpec, targeting TypeSpec 1.0+ and 2026 language additions.

Supported syntax

  • 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 / #deprecated directives.
  • 2026 TypeSpec additions: union ... extends ..., extern fn declarations, fn(...) => ... function type expressions, call expressions, internal and auto modifiers, 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, and void / never / unknown.

Targets

  • //:parser — C11 static library (src/parser.c).
  • //:libtree_sitter_typespec.so — shared library exporting tree_sitter_typespec for dynamic consumers such as ast-grep customLanguages.
  • //:generate — hermetic write_source_files target (with built-in drift tests) regenerating src/parser.c, src/grammar.json, and src/node-types.json from grammar.js.
  • //bindings/rust:treesitter_typespec — Rust library exposing LANGUAGE (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 running test/corpus/*.txt S-expression expectations under Bazel.
  • //bindings/rust/upstream_corpus:upstream_spec_corpus_test — Rust test validating zero parse errors across all stdlib .tsp files from //:node_modules/@typespec/*.

Using with ast-grep

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: '$'

Regenerating src/parser.c

bazel run //:generate
bazel test //...

License

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.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages