Module

parser.blocks.core

Core block stack management for Kida parser.

Provides base mixin for managing block stack and unified {% end %} syntax.

Uses inline TYPE_CHECKING declarations for host attributes. See: plan/rfc-mixin-protocol-typing.md

Classes

BlockStackMixin 8
Mixin for block stack management. Host attributes and cross-mixin dependencies are declared via in…

Mixin for block stack management.

Host attributes and cross-mixin dependencies are declared via inline TYPE_CHECKING blocks.

Attributes

Name Type Description
_END_KEYWORDS frozenset[str]
_CONTINUATION_KEYWORDS frozenset[str]
_LOOP_BLOCKS frozenset[str]

Methods

Internal Methods 5
_push_block 2
Push a block onto the stack when opening it.
def _push_block(self, block_type: str, token: Token | None = None) -> None
Parameters
Name Type Description
block_type

Type of block (if, for, def, etc.)

token

Token for error reporting (defaults to current token)

Default:None
_pop_block 1 str
Pop a block from the stack when closing it.
def _pop_block(self, expected: str | None = None) -> str
Parameters
Name Type Description
expected

If provided, validates that the closing block matches. Use None to accept any block type (unified {% end %}).

Default:None
Returns
str The block type that was popped.
_format_open_blocks 0 str
Format the current block stack for error messages.
def _format_open_blocks(self) -> str
Returns
str
_in_loop 0 bool
Check if currently inside a loop block. Used by break/continue to validate the…
def _in_loop(self) -> bool

Check if currently inside a loop block.

Used by break/continue to validate they are inside a loop. Part of RFC: kida-modern-syntax-features.

Returns
bool
_consume_end_tag 1
Consume an end tag ({% end %} or {% endXXX %}) and pop from stack.
def _consume_end_tag(self, block_type: str) -> None
Parameters
Name Type Description
block_type

The expected block type being closed. This method handles both unified {% end %} and explicit {% endif %} etc.