Apply Megaparsec best practices to parser error handling#7505
Merged
Apply Megaparsec best practices to parser error handling#7505
Conversation
d833dc6 to
f0b9041
Compare
Contributor
|
Note also #7391. |
zeme-wana
approved these changes
Jan 12, 2026
Remove redundant try wrappers: - symbol is auto-backtracking since Megaparsec 4.4.0 - Removed 10 redundant try wrappers from keyword and delimiter parsing - Fixed duplicate "constr" entry bug Add strategic labels for better error messages: - Use <?> operator for two-level labeling (delimiters + keywords) - Replace explicit fail with <?> in type parser (more idiomatic) - Labels provide clearer context in parse errors Refactor to use between combinator: - Cleaner, more declarative code structure - Standard Megaparsec pattern for delimited parsing - Eliminates intermediate bindings Expand test coverage: - Add 6 new error message tests covering common error scenarios - Extract testParseError helper to reduce duplication - Organize error tests into dedicated test group - Verify labels appear correctly in error messages All 2,973 tests pass (781 UPLC + 1,864 PLC + 328 PlutusIR)
f0b9041 to
ec31d16
Compare
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.
This PR applies Megaparsec best practices to improve the parser error handling implementation from PR #7489.
Summary of Improvements
1. Remove Redundant
tryWrapperstry (symbol ...)despitesymbolbeing auto-backtracking since Megaparsec 4.4.0 (current version: 9.7.0)trywrappers from keyword and delimiter parsing2. Fix Duplicate Entry Bug
"constr"keyword appeared twice in choice list (lines 118 and 123)3. Add Strategic Labels for Better Error Messages
<?>operator"opening parenthesis '('","closing bracket ']'""term keyword (builtin, lam, ...)"4. Replace
failwith<?>in Type Parserfailinstead of idiomatic<?>5. Refactor to Use
betweenCombinatorbetweencombinator6. Expand Test Coverage
testParseErrorhelper to eliminate duplication