Repository navigation
Fix tag and expression parsing bugs, make parentheses optional, and speed up rendering - #11
Merged
Merged
Conversation
- Conditions like if (a) or (b) parse: a tag's parentheses no longer have to wrap the whole condition. log(a) | uppercase works for the same reason. - foreach accepts any whitespace around 'in'. - if x and foreach x in y explain that they need parentheses. - x IN [c] reads [c] as a list, not the case-insensitive flag. - Only decimal text reads as a number, so 'inf', 'nan' and '0x10' don't. - default(...) also replaces an empty list or dictionary. - Function calls allocate one array instead of two. - The last if branch no longer emits a jump when there's no else. - Reading a date from text tries only the ISO 8601 forms it could be in.
{% if count > 2 %} and {% foreach item in items %} now work alongside the
parenthesized forms. A bare {% if %} or {% foreach %} is still a key.
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:
{% if (a) or (b) %}and{% log(a) | uppercase %}failed to parse,{% if x %}failed with "Unexpected x",foreach(item inwith a newline beforeitemswas rejected,x IN [c]failed,"inf" + 1renderedinfand"0x10" + 1rendered17, andtags | default("none")ignored an empty list.After: all of these work.
if,elseifandforeachno longer need parentheses, as in{% if count > 2 %}and{% foreach item in items %}. Rendering the list benchmark is about 14% faster (156 → 134 µs per render, Linux, Swift 6.0).How:
)that matches the opening((skipping quoted text). When that)ends the tag, it strips the pair as before. Otherwise the whole(...) ...remainder is the expression.if,elseif,else ifandforeachtake the rest of the tag as the expression after a space. A bare{% if %}or{% foreach %}is still a key.logkeeps requiring parentheses, so{% log | escape %}still renders a key namedlog.foreachfindsinwith any whitespace on either side.[c]/[d]after a comparison counts as flags only when an operand follows. Otherwise it's a list.Double(String)also acceptsnan,infand hex. Such text now joins as text with+, so"inf" + 1givesinf1.defaultalso falls back for an empty list or dictionary.ifbranch skips an unneeded jump,@sumonly computes the floating-point total when it's needed, and reading a date from text tries only the ISO 8601 forms it could be in, since each failed parse throws.Tests: 105 pass on Linux with Swift 6.0.3, including new cases for each fix.