Module

parser.blocks.control_flow

Control flow block parsing for Kida parser.

Provides mixin for parsing if/for control flow statements.

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

Classes

ControlFlowBlockParsingMixin 9
Mixin for parsing control flow blocks. Host attributes and cross-mixin dependencies are declared v…

Mixin for parsing control flow blocks.

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

Methods

Internal Methods 9
_parse_unless 0 If
Parse {% unless cond %} as {% if not cond %}. Part of RFC: kida-modern-syntax-…
def _parse_unless(self) -> If

Parse {% unless cond %} as {% if not cond %}.

Part of RFC: kida-modern-syntax-features. Supports {% end %}, {% endif %}, and {% endunless %}.

Returns
If
_parse_break 0 Break
Parse {% break %} loop control. Part of RFC: kida-modern-syntax-features.
def _parse_break(self) -> Break
Returns
Break
_parse_continue 0 Continue
Parse {% continue %} loop control. Part of RFC: kida-modern-syntax-features.
def _parse_continue(self) -> Continue
Returns
Continue
_parse_while 0 While
Parse {% while cond %}...{% end %} or {% endwhile %}. Kida-native while loop f…
def _parse_while(self) -> While

Parse {% while cond %}...{% end %} or {% endwhile %}.

Kida-native while loop for condition-based iteration.

Syntax:

{% while items | length > 0 %}
    {{ items | pop }}
{% end %}

Part of RFC: kida-2.0-moonshot (While Loops).

Returns
While
_parse_if 0 If
Parse {% if %} ... {% end %} or {% endif %}. Supports unified {% end %} as wel…
def _parse_if(self) -> If

Parse {% if %} ... {% end %} or {% endif %}.

Supports unified {% end %} as well as explicit {% endif %}. Also handles {% elif %} and {% else %} clauses.

Returns
If
_parse_async 0 AsyncFor
Parse {% async for %} — dispatcher for async constructs. Two-token lookahead: …
def _parse_async(self) -> AsyncFor

Parse {% async for %} — dispatcher for async constructs.

Two-token lookahead: consumes 'async', expects 'for' next. Part of RFC: rfc-async-rendering.

Returns
AsyncFor
_parse_async_for 1 AsyncFor
Parse {% async for %} ... {% end %} or {% endfor %}. Mirrors _parse_for() but …
def _parse_async_for(self, start: Token) -> AsyncFor

Parse {% async for %} ... {% end %} or {% endfor %}.

Mirrors _parse_for() but produces an AsyncFor node for native async iteration. Supports inline if filter and {% empty %} clause. Does not support recursive loops.

Part of RFC: rfc-async-rendering.

Parameters
Name Type Description
start
Returns
AsyncFor
_parse_for 0 For
Parse {% for %} ... {% end %} or {% endfor %. Supports unified {% end %} as we…
def _parse_for(self) -> For

Parse {% for %} ... {% end %} or {% endfor %.

Supports unified {% end %} as well as explicit {% endfor %}. Also handles {% else %} and {% empty %} clauses. Supports inline if filter: {% for x in items if x.visible %} Part of RFC: kida-modern-syntax-features (inline if).

Returns
For
_parse_match 0 Match
Parse {% match expr %}{% case pattern %}...{% end %}. Pattern matching for cle…
def _parse_match(self) -> Match

Parse {% match expr %}{% case pattern %}...{% end %}.

Pattern matching for cleaner branching than if/elif chains. Reuses the existing _parse_body infrastructure for case bodies.

Syntax:

{% match page.type %}
    {% case "post" %}...
    {% case "gallery" %}...
    {% case _ %}...
{% end %}

Valueless match (switch-true): {% match %} {% case _ if user.is_admin %}Admin {% case _ %}Member {% end %}

The underscore (_) is the wildcard/default case.

Returns
Match