match¶
Macro input pattern matching utilities.
- class macro_polo.match.DelimitedMacroMatcher¶
A delimited macro match pattern.
- __init__(delimiter, matcher)¶
- Parameters:
delimiter (Delimiter)
matcher (MacroMatcher)
- Return type:
None
- match(tokens)¶
Attempt to match against a token sequence.
- Parameters:
- Return type:
MacroMatch | None
- matcher: MacroMatcher¶
The inner matcher.
- class macro_polo.match.MacroMatch¶
Result of a successful macro match.
- captures: MacroMatchCaptures¶
Captured tokens.
- exception macro_polo.match.MacroMatchError¶
Exception raised for macro matching errors.
- class macro_polo.match.MacroMatcher¶
A macro match pattern.
- full_match(tokens)¶
Attempt to match against an entire token sequence.
- Parameters:
- Return type:
MacroMatch | None
- match(tokens)¶
Attempt to match against a token sequence.
- Parameters:
- Return type:
MacroMatch | None
- class macro_polo.match.MacroMatcherEmptyCapture¶
An empty macro capture.
Preserves nesting depth information, primarily to enable better transcription error messages.
- class macro_polo.match.MacroMatcherNegativeLookahead¶
A negative lookahead macro match.
Matches zero tokens only if
MacroMatcherwould fail to match, and fails to match otherwise.- match(tokens)¶
Attempt to match against a token sequence.
- Parameters:
- Return type:
MacroMatch | None
- class macro_polo.match.MacroMatcherRepeater¶
A repeated sub-matcher.
- __init__(matcher, mode, sep=None)¶
- Parameters:
matcher (MacroMatcher)
mode (MacroMatcherRepeaterMode)
sep (Token | None)
- Return type:
None
- property base_captures: Mapping[str, MacroMatcherEmptyCapture]¶
Get a set of empty captures for this matcher.
This is used to provide empty capture lists for matchers that match zero times, allowing transcribers to handle empty captures properly.
- match(tokens)¶
Attempt to match against a token sequence.
- Parameters:
- Return type:
MacroMatch | None
- matcher: MacroMatcher¶
The matcher to repeat.
- mode: MacroMatcherRepeaterMode¶
The repitition mode.
- class macro_polo.match.MacroMatcherRepeaterMode¶
Matcher repeat mode.
- ONE_OR_MORE = '+'¶
Match ≥1 times.
- ZERO_OR_MORE = '*'¶
Match ≥0 times.
- ZERO_OR_ONE = '?'¶
Match ≤1 times.
- class macro_polo.match.MacroMatcherUnion¶
A union of macro matchers.
The first sub-matcher to match is used.
- static __new__(cls, *args)¶
Create a new MacroMatcherUnion.
- match(tokens)¶
Attempt to match against a token sequence.
- Parameters:
- Return type:
MacroMatch | None
- class macro_polo.match.MacroMatcherVar¶
A capture-variable in a macro matcher.
- __init__(name, type)¶
- Parameters:
name (str)
type (MacroMatcherVarType)
- Return type:
None
- match(tokens)¶
Attempt to match against a token sequence.
- Parameters:
- Return type:
MacroMatch | None
- type: MacroMatcherVarType¶
The type of token(s) to match.
- class macro_polo.match.MacroMatcherVarType¶
Capture-variable type.
- NAME = 'name'¶
Any
token.NAMEtoken.
- NUMBER = 'number'¶
Any
token.NUMBERtoken.
- STRING = 'string'¶
Any
token.STRINGtoken.
- TOKEN = 'token'¶
Any non-delimiter token.
- TOKEN_TREE = 'tt'¶
Any non-delimiter token or a delimited sequence of tokens.