syntect-tmlanguage
Load real TextMate (.tmLanguage/.tmLanguage.json) grammars into syntect's own SyntaxDefinition data model, so syntect-based tools gain TextMate grammar support without abandoning syntect's own regex-matching and highlighting engine.
TextMate/VS Code grammars are the most widely available syntax-highlighting grammar format. syntect only loads .sublime-syntax (YAML) natively — this crate bridges the gap.
How it works
syntect::parsing::ContextReference (and its sibling types) is #[non_exhaustive] with no public constructor, so direct struct construction from outside syntect isn't possible. Instead, this crate translates a parsed .tmLanguage.json grammar into .sublime-syntax-shaped YAML text and hands it to syntect's own SyntaxDefinition::load_from_str — the same, stable, public entry point real .sublime-syntax files go through.
Usage
use SyntaxSetBuilder;
let definition = load_file?;
let mut builder = new;
builder.add;
let syntax_set = builder.build;
# Ok::
Add the result to a syntect::parsing::SyntaxSetBuilder the same way you would a hand-written .sublime-syntax file — this crate doesn't wrap that step. For build-time bundling (convert once, ship a fast-loading artifact), either save to_sublime_syntax_yaml's output as a .sublime-syntax file directly, or cache a built SyntaxSet with syntect::dumps::dump_to_file/from_dump_file.
What's supported
matchrules (scope,captures)begin/endrules, includingapplyEndPatternLast,name/contentName,beginCaptures/endCaptures, and end-pattern backreferences tobegin's own capture groupsinclude:#name(repository),$self/$base, and external scope references — the mechanism real structural embedding (e.g. a fenced code block including another language's grammar) relies on- Runtime loading of an arbitrary local grammar file (
load_file), and in-memory loading from a string (load)
Known limitations
These are gaps in syntect itself, not just this crate — a grammar that needs them fails translation with a specific error rather than being silently mistranslated:
begin/whilerules (used by e.g. VS Code's ownmarkdown.tmLanguage.jsonfor blockquotes and fenced code blocks) —syntecthas no engine-level equivalent at all.\Ganchors — confirmed to never match at all throughsyntect'sonigbackend, in any position (seeexamples/g_anchor_never_matches.rs). Used by e.g. VS Code'sshell-unix-bash.tmLanguage.jsonandhtml.tmLanguage.jsonin commonly-exercised paths.- True selector-based injections (VS Code's
injectionSelector/ the grammar'sinjectionskey) —syntecthas no support for scope-selector-triggered pattern injection at all.
This crate uses syntect's regex-onig feature (real Oniguruma via a C binding), matching syntect's own default. This means it does not cross-compile to wasm32-unknown-unknown as-is.
License
Licensed under either of Apache License, Version 2.0 or MIT license at your option.