Module

parser.blocks.functions

Function block parsing for Kida parser.

Provides mixin for parsing function related statements (def, call, slot).

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

Classes

FunctionBlockParsingMixin 6
Mixin for parsing function blocks. Host attributes and cross-mixin dependencies are declared via i…

Mixin for parsing function blocks.

Host attributes and cross-mixin dependencies are declared via inline TYPE_CHECKING blocks. Inherits block stack management from BlockStackMixin.

Methods

Internal Methods 6
_parse_type_annotation 0 str | None
Parse an optional type annotation after a parameter name. Called when the curr…
def _parse_type_annotation(self) -> str | None

Parse an optional type annotation after a parameter name.

Called when the current token is COLON (indicating a type follows). Consumes the colon and type expression tokens, returning the raw annotation string.

Grammar::

type_expr := NAME [ '|' NAME ]* [ '[' type_expr (',' type_expr)* ']' ]

Handles:str, int, list, str | None, dict[str, int], MyModel.

Returns
str | None Raw annotation string, or None if no colon follows.
_parse_type_annotation_inner 0 str
Parse a single type inside brackets (for generic parameters).
def _parse_type_annotation_inner(self) -> str
Returns
str Type string (e.g. "str", "str | None").
_parse_def 0 Def
Parse {% def name(args) %}...{% end %} or {% enddef %. Kida functions with tru…
def _parse_def(self) -> Def

Parse {% def name(args) %}...{% end %} or {% enddef %.

Kida functions with true lexical scoping (can access outer scope). Uses stack-based parsing for proper nested block handling.

Supports optional type annotations on parameters::

{% def card(title: str, items: list, footer: str | None = None) %}
    ...
{% end %}
Returns
Def
_parse_call 0 CallBlock
Parse {% call name(args) %}body{% end %} or {% endcall %. Call a function/def …
def _parse_call(self) -> CallBlock

Parse {% call name(args) %}body{% end %} or {% endcall %.

Call a function/def with body content that fills {% slot %}. Supports named slots: {% slot name %}...{% end %} assigns to slot name; content outside slot blocks goes to default.

Returns
CallBlock
_parse_call_body 0 dict[str, Sequence[Node]]
Parse call block body into slots dict. When {% slot name %}...{% end %} appear…
def _parse_call_body(self) -> dict[str, Sequence[Node]]

Parse call block body into slots dict.

When {% slot name %}...{% end %} appears, content goes to slots[name]. Other content goes to slots["default"].

Returns
dict[str, Sequence[Node]]
_parse_slot 0 Slot | SlotBlock
Parse {% slot %} or {% slot name %} — context-dependent. Inside {% call %}: pa…
def _parse_slot(self) -> Slot | SlotBlock

Parse {% slot %} or {% slot name %} — context-dependent.

Inside {% call %}: parse {% slot name %}...{% end %} as SlotBlock. Inside {% def %}: parse self-closing {% slot %} or {% slot name %} as Slot.

Returns
Slot | SlotBlock