macro_polo¶
Rust-style macros for Python.
- class macro_polo.Delimiter¶
Represents a delimiter which must be kept balanced.
- __init__(open_type, open_string, close_type, close_string)¶
- static from_token(token)¶
- matches_close(token)¶
Check if the given token matches the delimiter’s close token.
- exception macro_polo.MacroError¶
Base class for macro-processing errors.
- class macro_polo.Token¶
Minimal representation of a token.
- static __new__(_cls, type, string)¶
Create new instance of Token(type, string)
- class macro_polo.TokenTree¶
A delimited sequence of tokens.
- exception macro_polo.TranscriptionError¶
Exception raised for macro transcription errors.
- macro_polo.lex(source)¶
Create a simplified token stream from source code.
- Some simplifications are applied to make matching easier:
Semantically innert tokens, such as NL and COMMENT, are stripped.
NEWLINE-INDENT and NEWLINE-DEDENT pairs are reduced to INDENT and DEDENT, respectively. (This is reversed by :func:
desimplify.)INDENT and NEWLINE tokens’ strings are normalized.
The trailing NEWLINE and ENDMARKER are stripped.
- macro_polo.stringify(tokens)¶
Construct source code from a token stream.