Skip to content

Implement injection grammar support in the tokenizer#30

Merged
ivan-magda merged 11 commits into
mainfrom
27-implement-injection-grammar-support-in-the-tokenizer
Feb 22, 2026
Merged

Implement injection grammar support in the tokenizer#30
ivan-magda merged 11 commits into
mainfrom
27-implement-injection-grammar-support-in-the-tokenizer

Conversation

@ivan-magda
Copy link
Copy Markdown
Owner

Summary

  • Port matcher.ts scope selector parser as InjectionSelectorParser — parses TextMate injection selectors (L:, R:, comma OR, space AND, negation, parenthesized expressions) into matcher functions
  • Add InjectionRule type and Grammar.getInjections() collecting both inline (grammar.injections map) and external (injectionSelector) injection grammars, with lazy caching and priority sorting
  • Add matchRuleOrInjections / matchInjections to the tokenizer — scans injection rules at each position, merges with normal match using start-position + L:/R: priority semantics
  • Wire injectionLookup in Registry.loadGrammar so registered injection grammars are automatically discovered
  • Copy all missing first-mate fixture grammars (20 new) from local vscode-textmate clone and unlock injection conformance tests (TEST #47: JS+hyperlink, TEST #49: Ruby+todo)

Test Plan

  • InjectionSelectorParserTest — 11 tests covering prefix matching, dotted identifiers, OR/AND/negation, priority, edge cases
  • InjectionGrammarTest — 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 test
  • FirstMateConformanceTest — TEST #47 and #49 now pass (injection filter removed)
  • Full :core:test suite green, no regressions
  • :benchmark:smokeBenchmark — no performance regression (fast path for grammars without injections)

Closes #27.

…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.
@ivan-magda ivan-magda self-assigned this Feb 22, 2026
Wrap MatchInjectionsResult around MatchRuleResult instead of duplicating
fields, rename bestRating to bestMatchStart, extract createRegistry and
tokenText helpers in tests, eliminate mutable targetScopeFromPath.
@ivan-magda ivan-magda merged commit ab774d6 into main Feb 22, 2026
1 check passed
@ivan-magda ivan-magda deleted the 27-implement-injection-grammar-support-in-the-tokenizer branch February 22, 2026 19:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement injection grammar support in the tokenizer

1 participant