Repository navigation
Add foreach else, strict mode, dictionary loops, text indexing and comments - #13
Merged
Merged
Conversation
…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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Before: an empty list needed an
ifaround 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.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 ofand/oris only checked when it would be evaluated.foreachover a dictionary gets each entry askeyandvalue, in key order.text[0],text[FIRST]andtext[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