macros¶
Submodules
High-level macro utilities.
- class macro_polo.macros.types.ParameterizedMacro(*args, **kwargs)[source]¶
Macro that takes additional parameters.
- class macro_polo.macros.types.PartialMatchMacro(*args, **kwargs)[source]¶
Transforms the beginning of a token sequence.
- class macro_polo.macros.super.LoopingMacro(*args)[source]¶
A super-macro that repeatedely applies its inner macros until none match.
- class macro_polo.macros.super.MultiMacro(*args)[source]¶
A super-macro that applies each of its inner macros in sequence.
- class macro_polo.macros.super.ScanningMacro(*args)[source]¶
A super-macro that scans input and applies its inner macros as they match.
This macro will only perform a single pass on the input. It can be combined with
LoopingMacroto recursively expand macros.- Parameters:
args (PartialMatchMacro)
- Return type:
- class macro_polo.macros.importer.ImporterMacro(function_macros=<factory>, module_macros=<factory>, decorator_macros=<factory>)[source]¶
Imports macros from other modules.
This macro expects its parameters to be in one of two forms: 1.
module_name2.macro_name1, macro_name2, ... from module_nameIn the first case all macros from the target module will be imported.
Imported macros are added to
function_macros,module_macros, anddecorator_macrosas appropriate.- Parameters:
module_macros (dict[str, ParameterizedMacro])
decorator_macros (dict[str, ParameterizedMacro])
- decorator_macros: dict[str, ParameterizedMacro]¶
Imported decorator macros will be added to this dict.
It may be shared with other macros, such as a
DecoratorMacroInvokerMacro.
- function_macros: dict[str, Macro]¶
Imported function macros will be added to this dict.
It may be shared with other macros, such as a
FunctionMacroInvokerMacro.
- module_macros: dict[str, ParameterizedMacro]¶
Imported module macros will be added to this dict.
It may be shared with other macros, such as a
ModuleMacroInvokerMacro.
- class macro_polo.macros.function.FunctionMacroInvokerMacro(macros=<factory>)[source]¶
A macro that processes function-like macro invocations.
The syntax for invoking a function-style macro is:
macro_name!(input tokens)
or
macro_name![input tokens]
or
macro_name!{input tokens}or
macro_name!: input tokensImportant
Due to the way Python’s tokenizer works, indentation and newlines are only preserved by the last (block) style.
When invoked, the registered macro is called with a single argument, the token sequence passed as input.
Macros are defined by
macros(which can be updated after this class is instantiated).- macros: Mapping[str, Macro]¶
A mapping of names to function macros.
When a function macro is invoked, its name is looked up here.
This mapping may be shared with other macros, such as a
ImporterMacro.
- class macro_polo.macros.macro_rules.MacroRule(matcher, transcriber)[source]¶
A macro matcher/macro transcriber pair.
- Parameters:
matcher (MacroMatcher)
transcriber (MacroTranscriber)
- matcher: MacroMatcher¶
The rule’s matcher
- transcriber: MacroTranscriber¶
The rule’s transcriber
- class macro_polo.macros.macro_rules.MacroRulesParserMacro(macros=<factory>)[source]¶
A macro that parses
macro_rulesmacro definitions.Parsed macros are added to
macros.- macros: dict[str, Macro]¶
Parsed
macro_rulesmacros will be added to this dict.It may be shared with other macros, such as a
FunctionMacroInvokerMacro.
- class macro_polo.macros.module.ModuleMacroError(name, parameters, msg)[source]¶
Errors during invocation of module-level macros.
- class macro_polo.macros.module.ModuleMacroInvokerMacro(macros=<factory>)[source]¶
A macro that processes module-level macro invocations.
The syntax for invoking a module-level macro is
![name(parameters)]or]).Module-level macro invocations must come before all other code (with the exception of a docstring), and must each appear on their own line.
When invoked, the registered macro is called with two arguments:
parameters(as a token sequence)- the remainder of the module starting from the line immediately following the
invocation (as a token sequence).
Macros are defined by
macros(which can be updated after this class is instantiated).- Parameters:
macros (Mapping[str, ParameterizedMacro])
- macros: Mapping[str, ParameterizedMacro]¶
A mapping of names to module macros.
When a module macro is invoked, its name is looked up here.
This mapping may be shared with other macros, such as a
ImporterMacro.
- class macro_polo.macros.decorator.DecoratorMacroError(name, parameters, msg)[source]¶
Error during invocation of decorator-style macros.
- class macro_polo.macros.decorator.DecoratorMacroInvokerMacro(macros=<factory>)[source]¶
A macro that processes decorator-style macro invocations.
The syntax for invoking a decorator-style macro is
@![name(parameters)]or@]).Decorator-style macro invocations must immediately precede a “block”, defined as either a single newline-terminated line, or a line followed by an indented block.
When invoked, the registered macro is called with two arguments:
parameters(as a token sequence)the block immediately following the invocation (as a token sequence).
When multiple decorator-style macros are stacked, they are invoked from bottom to top.
Macros are defined by
macros(which can be updated after this class is instantiated).- Parameters:
macros (Mapping[str, ParameterizedMacro])
- macros: Mapping[str, ParameterizedMacro]¶
A mapping of names to decorator macros.
When a decorator macro is invoked, its name is looked up here.
This mapping may be shared with other macros, such as a
ImporterMacro.