textmate_grammar.engine.matcher¶
Port of vscode-textmate’s src/matcher.ts.
Scope selectors such as
text.html.php - (meta.embedded | meta.tag), L:text.html.php meta.tag are
parsed into small composable predicate functions evaluated against a scope
path. The semantics are intentionally 1:1 with the TypeScript source; comments
throughout this module reference the corresponding sections of matcher.ts
(and of grammar.ts/theme.ts where matcher.ts delegates the name-matching
logic).
Note on ordering: the only ordering information matcher.ts itself produces
is the L: (priority -1) / R: (priority 1) selector prefix, surfaced as
MatcherWithPriority.priority. Sorting injections by that priority
happens in grammar.ts (task 3b); specificity ordering of theme rules lives
in theme.ts and is out of this plan’s scope.
Module Contents¶
Classes¶
matcher.ts |
|
The parent-linked scope chain matchers are evaluated against. |
Functions¶
Port of matcher.ts |
|
Port of grammar.ts |
|
Port of grammar.ts |
|
Name matcher over a |
Data¶
API¶
- textmate_grammar.engine.matcher.T = 'TypeVar(...)'¶
- textmate_grammar.engine.matcher.Matcher = None¶
- textmate_grammar.engine.matcher.MatchesName = None¶
- textmate_grammar.engine.matcher.Priority = None¶
- class textmate_grammar.engine.matcher.MatcherWithPriority¶
Bases:
typing.NamedTuplematcher.ts
interface MatcherWithPriority<T> { matcher; priority }.matcheris a predicate over whatever input the caller evaluates against (grammar.ts uses the flat scope-name list of the current token);priorityis the parsedL:/R:prefix.- matcher: collections.abc.Callable[[Any], bool] = None¶
- priority: textmate_grammar.engine.matcher.Priority = None¶
- class textmate_grammar.engine.matcher.ScopePath¶
Bases:
typing.ProtocolThe parent-linked scope chain matchers are evaluated against.
A scope path is a linked chain of scope names: the node a caller holds is the innermost scope,
.nameits scope name and.parentpoints towards the shallower scope; the root scope hasparent = None. Materialized root-first this equalstheme.ts’ScopeStack.getSegments()(i.e.grammar.ts’getScopeNames()). Minimal on purpose; the state stack built in task 3a satisfies this protocol structurally.- parent: textmate_grammar.engine.matcher.ScopePath | None = None¶
- textmate_grammar.engine.matcher.create_matchers(selector: str, matches_name: textmate_grammar.engine.matcher.MatchesName[textmate_grammar.engine.matcher.T]) list[textmate_grammar.engine.matcher.MatcherWithPriority]¶
Port of matcher.ts
createMatchers.Parses
selectorinto its comma-separated branches and returns oneMatcherWithPriorityper branch. Callers treat the branch matchers as alternatives (matcher.ts consumers usematchers.some(...)). Onlyprioritycarries ordering information; the matchers are pure predicates.
- textmate_grammar.engine.matcher.scopes_are_matching(scope_name: str, selector_scope: str) bool¶
Port of grammar.ts
scopesAreMatching(matcher.ts delegates to it).True when the stack scope
scope_nameequalsselector_scopeor extends it at a.boundary:text.htmlmatchestext.html.phpbut nottext.htmlx.
- textmate_grammar.engine.matcher.match_scope_identifiers(identifiers: list[str], scopes: list[str]) bool¶
Port of grammar.ts
nameMatcher, thematches_namematcher.ts is fed.Every identifier must occur as a subsequence of
scopes, scanning strictly left to right: identifier order matters and each identifier consumes its position (repeated identifiers need repeated scopes). A stack scope matches an identifier viascopes_are_matching().
- textmate_grammar.engine.matcher.match_scope_names(identifiers: list[str], scopes_path: textmate_grammar.engine.matcher.ScopePath | None) bool¶
Name matcher over a
ScopePathparent chain.Equivalent to grammar.ts
nameMatcherfedgetScopeNames(): the chain is collected from the innermost node through the parents and then reversed to root-first order (theme.tsScopeStack.getSegments()).