Skip to content

Add foreach else, strict mode, dictionary loops, text indexing and comments - #13

Merged
mierau merged 1 commit into
mainfrom
claude/project-thread-aa6quc
Oct 11, 2026
Merged

mierau merged 1 commit into
mainfrom
claude/project-thread-aa6quc

Conversation

@mierau

@mierau mierau commented Oct 11, 2026

Copy link
Copy Markdown
Owner

Before: an empty list needed an if around the loop to show a fallback, a misspelled key rendered as nothing with no hint, looping over a dictionary or indexing text (name[0]) silently rendered nothing, and there was no way to leave a note in a template.

After:

  • {% foreach item in items %}…{% else %}No items.{% endforeach %} runs the else when there's nothing to loop over. Loop variables are out of scope in the else.
  • Rendering with features: [.log, .strict] logs every key a tag asks for that the context doesn't have, once per tag, with its line: line 3: no value for 'naem' in person.naem. A key present with a nil value isn't reported, and the right side of and/or is only checked when it would be evaluated.
  • foreach over a dictionary gets each entry as key and value, in key order.
  • text[0], text[FIRST] and text[LAST] give characters; out of range is nil.
  • {%# a note %} is a comment and renders nothing.

How: the parser now tracks each tag's line incrementally and the program keeps a line per instruction. Strict mode is a separate pass over an expression before it's evaluated, so renders without it pay nothing: the list benchmark renders in 130 µs, same as main (an earlier version that checked inline cost about 10%). README and the DocC syntax article cover all five. 139 tests pass on Swift 6.0 (Linux), 23 of them new.


Generated by Claude Code

…mments.

- An else inside foreach runs when there's nothing to loop over.
- RenderFeatures.strict logs keys the context doesn't have, with the
  tag's line, from a separate pass so normal renders pay nothing.
- foreach over a dictionary gets each entry as key and value, in key order.
- text[0], text[FIRST] and text[LAST] give characters.
- {%# ... %} is a comment.
@mierau mierau self-assigned this Oct 11, 2026
@mierau
mierau merged commit 27ba60b into main Oct 11, 2026
2 checks passed
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