"""Macro type definitions."""fromabcimportabstractmethodfromcollections.abcimportSequencefromtypingimportProtocolfrom..tokensimportToken
[docs]classMacro(Protocol):"""Transforms a token sequence."""@abstractmethoddef__call__(self,tokens:Sequence[Token])->Sequence[Token]|None:"""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. """
[docs]classPartialMatchMacro(Protocol):"""Transforms the beginning of a token sequence."""@abstractmethoddef__call__(self,tokens:Sequence[Token])->tuple[Sequence[Token],int]:"""Transform the beginning of a token sequence. This method should return a tuple of (token sequence, number of tokens matched). """
[docs]classParameterizedMacro(Protocol):"""Macro that takes additional parameters."""@abstractmethoddef__call__(self,parameters:Sequence[Token],tokens:Sequence[Token])->Sequence[Token]|None:"""Transform a token sequence. This method should return a new token sequence, or ``None`` if the input sequence fails to match. """