Repository navigation
feat(lexers): add TypeSpec lexer - #1524
Merged
Merged
Conversation
Adds a lexer for TypeSpec (https://typespec.io), the API description language, for *.tsp files (aliases: typespec, tsp). It covers declarations (model, scalar, interface, union, enum, alias, op, dec, fn, const, namespace, using, import), decorators and augment decorators, directives, doc comments with tags, single and triple quoted strings with escapes and ${} interpolation, number literals, built-in scalar types, object and tuple literals, and backtick identifiers. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
A TypeSpec string cannot span lines, so an unterminated one no longer colours the rest of the file as a string. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
alecthomas
approved these changes
Nov 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds a lexer for TypeSpec, the API description language:
*.tspfiles, aliasestypespecandtsp. Pygments has no TypeSpec lexer, so this one is hand written. Chroma currently renderstypespecandtspcode blocks without any highlighting.It covers declarations (
model,scalar,interface,union,enum,alias,op,dec,fn,const,namespace,using,import), decorators and augment decorators (@@), directives (#suppress), doc comments with their@tags, single and triple quoted strings with escapes and${}interpolation, number literals, the built-in scalar types, object and tuple literals (#{},#[]) and backtick identifiers.How it was checked
lexers/testdata/typespec.actualexercises each construct, with the recordedtypespec.expected.typespec.tmLanguage, from@typespec/compiler1.18.0) on 22 production.tspfiles, about 156 KB and 18,000 tokens. No Error tokens from this lexer, and no disagreement on comments, strings, numbers, keywords, decorators, directives or function names. The grammar scopes every type reference asentity.name.type, so the comparison treats those as equivalent.NameClass, and a name followed by:or?:is a plainName. Enum members written without a value (Red,) are therefore coloured as types.go test ./lexers/... .passes, andlexers_gen.gois regenerated.🤖 Generated with Claude Code