Implement injection grammar support in the tokenizer#30
Merged
ivan-magda merged 11 commits intoFeb 22, 2026
Conversation
…ection flavors Includes Registry wiring of injectionLookup (required for external injection tests).
Remove force-unwraps in parseOperand, flatten with early null return, fix isIdentifier to use matches() with hyphen-aware regex, remove dead loadFixture helper from test.
Copy all missing first-mate fixture grammars from local vscode-textmate clone. Remove grammarInjections filter now that injection mechanism is in place. Update loadGrammarForTest to pre-load grammars via addGrammar for injection discovery. TEST #47: JavaScript + hyperlink — URLs in comments get markup.underline.link scope. TEST #49: Ruby + todo — TODO keywords in comments get storage.type.class.todo scope. Closes #27.
Wrap MatchInjectionsResult around MatchRuleResult instead of duplicating fields, rename bestRating to bestMatchStart, extract createRegistry and tokenText helpers in tests, eliminate mutable targetScopeFromPath.
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.
Summary
matcher.tsscope selector parser asInjectionSelectorParser— parses TextMate injection selectors (L:,R:, comma OR, space AND, negation, parenthesized expressions) into matcher functionsInjectionRuletype andGrammar.getInjections()collecting both inline (grammar.injectionsmap) and external (injectionSelector) injection grammars, with lazy caching and priority sortingmatchRuleOrInjections/matchInjectionsto the tokenizer — scans injection rules at each position, merges with normal match using start-position + L:/R: priority semanticsinjectionLookupinRegistry.loadGrammarso registered injection grammars are automatically discoveredTest Plan
InjectionSelectorParserTest— 11 tests covering prefix matching, dotted identifiers, OR/AND/negation, priority, edge casesInjectionGrammarTest— 11 tests covering getInjections (caching, self-injection, inline/external flavors) and tokenizer integration (hyperlink in C comment, L-priority, inline injection, fast path)RegistryTest— injection wiring testFirstMateConformanceTest— TEST #47 and #49 now pass (injection filter removed):core:testsuite green, no regressions:benchmark:smokeBenchmark— no performance regression (fast path for grammars without injections)Closes #27.