types

Macro type definitions.

protocol macro_polo.macros.types.Macro

Transforms a token sequence.

Classes that implement this protocol must have the following methods / attributes:

abstractmethod __call__(tokens)

Transform a token sequence.

This method should return a new token sequence, or None if the input sequence fails to match or should be left unchanged.

Parameters:

tokens (Sequence[Token])

Return type:

Sequence[Token] | None

protocol macro_polo.macros.types.ParameterizedMacro

Macro that takes additional parameters.

Classes that implement this protocol must have the following methods / attributes:

abstractmethod __call__(parameters, tokens)

Transform a token sequence.

This method should return a new token sequence, or None if the input sequence fails to match.

Parameters:
Return type:

Sequence[Token] | None

protocol macro_polo.macros.types.PartialMatchMacro

Transforms the beginning of a token sequence.

Classes that implement this protocol must have the following methods / attributes:

abstractmethod __call__(tokens)

Transform the beginning of a token sequence.

This method should return a tuple of (token sequence, number of tokens matched).

Parameters:

tokens (Sequence[Token])

Return type:

tuple[Sequence[Token], int]