-
Notifications
You must be signed in to change notification settings - Fork 1
refactor(pest)!: greatly simplified grammar, removed expensive look-ahead that offer no real benefit #11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
lalvarezt
wants to merge
5
commits into
main
Choose a base branch
from
simplified-grammar
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
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
This comment was marked as outdated.
This comment was marked as outdated.
a936d14 to
c1e6fa5
Compare
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
5ddd68b to
a194856
Compare
Owner
Author
|
🚀 Benchmark comparison started Comparing:
Parameters:
Results will be posted here when complete... |
🔬 Benchmark Comparison ReportRequested by: @lalvarezt Comparison:
Parameters:
📊 Benchmark Comparison ReportInput Size: 10,000 paths Baseline Timestamp: 1762543388 Performance Comparison
Summary
✨ Performance Improvements
Legend
Triggered by /bench command |
…head that offer no real benefit expect some change in templates that relied on smart escaping, now it's more intentional
Reorganized operation alternatives based on actual benchmark usage patterns to optimize PEG parser performance. Most frequently used operations (split, join, upper, lower, trim, substring, reverse) are now tested first.
Add fast-path optimizations for filter, filter_not, and replace operations when patterns contain no regex metacharacters. This avoids unnecessary regex compilation and matching for simple literal string operations.
a194856 to
92ab5d1
Compare
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.
This PR 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.