Skip to content

feat: dictionary iteration and computed key access#3

Merged
RoboNET merged 11 commits intomainfrom
feat/dictionary-support
Feb 26, 2026
Merged

feat: dictionary iteration and computed key access#3
RoboNET merged 11 commits intomainfrom
feat/dictionary-support

Conversation

@RoboNET
Copy link
Copy Markdown
Owner

@RoboNET RoboNET commented Feb 26, 2026

Summary

  • ObjectValue iteration: type: each and {{#each}} auto-detect ObjectValue and iterate key-value pairs with @key, @index, @first, @last loop variables
  • Computed key access: dict[expr] postfix operator in Pratt parser — supports variables, string literals, expressions, filters, and nested brackets
  • Scope walking: ExpressionEvaluator walks parent scopes from innermost to root for variable resolution
  • Key trimming: ObjectValue trims keys at all entry points (indexer, ContainsKey, TryGetValue) + SetLoopKey

Test Plan

  • 7 TemplateContext tests (LoopKey, trimming, Scopes)
  • 3 ExpressionEvaluator tests (@key loop variable)
  • 7 TemplateExpander tests (ObjectValue iteration)
  • 5 TemplateProcessor tests (inline {{#each}} ObjectValue)
  • 10 parser tests (IndexAccessExpression)
  • 14 evaluator tests (index access evaluation)
  • 5 ObjectValue key trimming tests
  • E2E integration tests with scope walking
  • 5319 total tests pass on net8.0 + net10.0

@RoboNET RoboNET merged commit d32a7b2 into main Feb 26, 2026
6 checks passed
@RoboNET RoboNET deleted the feat/dictionary-support branch February 26, 2026 11:10
RoboNET added a commit that referenced this pull request Mar 11, 2026
* feat(ast): add LoopKey to TemplateContext for dictionary iteration

* feat(ast): add @key loop variable to ExpressionEvaluator

* feat(ast): add ObjectValue iteration to TemplateExpander

* feat(ast): add ObjectValue iteration to inline {{#each}} blocks

* feat(ast): trim keys in SetLoopKey to ensure clean @key values

* feat(ast): trim keys in ObjectValue for consistent key handling

* feat(ast): add computed key access [expr] to expression system

Add IndexAccessExpression AST node, Pratt parser postfix operator for
bracket notation, and evaluator support for dynamic key/index access
on ObjectValue and ArrayValue.

* test: add end-to-end integration tests for dictionary iteration with computed key access

Add scope walking to ExpressionEvaluator.Resolve so variables from
parent scopes (e.g. root data) are accessible inside each loops.
This enables patterns like {{values[@key]}} where @key comes from
the loop and values lives at root level.

* docs: fix inverted XML doc comment on TemplateContext.Scopes

* docs: add dictionary iteration and computed key access to wiki
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant