# functions

URL: /kida/api/parser/blocks/functions/
Section: blocks
Description: 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

---

> For a complete page index, fetch /kida/llms.txt.

Open LLM text
(/kida/api/parser/blocks/functions/index.txt)

Share with AI

Ask Claude
(https://claude.ai/new?q=Please%20help%20me%20understand%20this%20documentation%3A%20%2Fkida%2Fapi%2Fparser%2Fblocks%2Ffunctions%2Findex.txt)

Ask ChatGPT
(https://chatgpt.com/?q=Please%20help%20me%20understand%20this%20documentation%3A%20%2Fkida%2Fapi%2Fparser%2Fblocks%2Ffunctions%2Findex.txt)

Ask Gemini
(https://gemini.google.com/app?q=Please%20help%20me%20understand%20this%20documentation%3A%20%2Fkida%2Fapi%2Fparser%2Fblocks%2Ffunctions%2Findex.txt)

Ask Copilot
(https://copilot.microsoft.com/?q=Please%20help%20me%20understand%20this%20documentation%3A%20%2Fkida%2Fapi%2Fparser%2Fblocks%2Ffunctions%2Findex.txt)

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

1Class

## Classes

`FunctionBlockParsingMixin`

10

▼

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
10

▼

`_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_region`

0

`Region`

▼

Parse {% region name(params) %}...{% end %} or {% endregion %}.

`def _parse_region(self) -> Region`

##### Returns

`Region`

`_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_let_bindings`

0

`list[tuple[str, Expr]]`

▼

Parse let:name=expr pairs for scoped slot bindings (def-side).

Grammar::
l…

`def _parse_let_bindings(self) -> list[tuple[str, Expr]]`

Parse let:name=expr pairs for scoped slot bindings (def-side).

Grammar::
let_binding := 'let' ':' NAME '=' expression
let_bindings := let_binding (',' let_binding)*

##### Returns

`list[tuple[str, Expr]]`

List of (name, expr) tuples.

`_parse_let_params`

0

`list[str]`

▼

Parse let:name declarations for scoped slot params (call-site).

Grammar::
…

`def _parse_let_params(self) -> list[str]`

Parse let:name declarations for scoped slot params (call-site).

Grammar::
let_param := 'let' ':' NAME
let_params := let_param (',' let_param)*

##### Returns

`list[str]`

List of parameter names.

`_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.
With scoped params: {% slot name let:item, let:index %}...{% end %}
Inside {% def %}: parse self-closing {% slot %} or {% slot name %} as Slot.
With scoped bindings: {% slot name let:item=expr, let:index=loop.index %}

##### Returns

`Slot | SlotBlock`

`_parse_yield`

0

`Slot`

▼

Parse {% yield %} or {% yield name %} — always a render reference.

Unlike {% s…

`def _parse_yield(self) -> Slot`

Parse {% yield %} or {% yield name %} — always a render reference.

Unlike {% slot %}, which becomes a SlotBlock inside {% call %} blocks,
{% yield %} always produces a Slot node. This makes it safe to use
inside nested {% call %} blocks when forwarding the enclosing def's
caller slots.

##### Returns

`Slot`
