Replies: 1 comment
-
|
@alexpasmantier any thoughts? |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Simplified Grammar: Why Less Complexity is Better
The refactor made in branch simplified-grammar simplifies the template parser by removing expensive lookahead operations and consolidating multiple context-specific argument parsers into a single, unified approach.
The Problem
The previous grammar implementation attempted to be "smart" by using context-specific parsing rules:
simple_argfor basic operations (append, prepend, join)regex_argfor regex patternssplit_argfor split separatorsmap_regex_argfor regex within map operationsEach parser had different lookahead logic to determine when special characters (
|,:,{,}) should be treated as literals versus syntax. This required extensiveoperation_keywordlookahead and complex negative assertions like:The Solution
The refactor introduces a single unified argument parser:
All operations now use the same escaping rules. Special characters require explicit escaping - no exceptions, no context-dependent behavior.
Why This is Better
Performance: Lookahead operations are expensive. Removing them provides immediate parsing performance improvements, especially for complex templates.
Maintainability: One set of rules to understand, test, and maintain instead of four context-specific parsers.
Predictability: Users now have clear, consistent rules. If a character is special (
|,:,{,},\), escape it. No need to understand parser internals or memorize context-specific exceptions.Explicitness: Templates become more intentional. Compare:
The second version clearly shows what's a separator and what's syntax.
Robustness: Fewer edge cases means fewer bugs. Complex lookahead logic often fails in corner cases that are hard to predict.
The Trade-off
This is a breaking change. Templates that previously relied on smart escaping need updates:
{split:|:0}→{split:\|:0}{regex_extract:Version: (\d+):1}→{regex_extract:Version\: (\d+):1}However, the migration path is straightforward, and the long-term benefits of a simpler, faster, more predictable parser far outweigh the one-time update cost.
Beta Was this translation helpful? Give feedback.
All reactions