refactor: simplify iterator.Try and remove unnecessary backtracking #47
Reference in New Issue
Block a user
Delete Branch "refactor/simplify-iterator-try"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Description
iterator.Trypreviously copied the entire iterator and synced it back on success, causing an unnecessary heap allocation on every call.This PR simplifies
Tryto save and restore the index directly, and removes the now-unusedCopyandSyncmethods.ScanRuneandParseRawTokenas peek-then-advance, eliminating the need forTryat leaf level.Trywrappers fromparseExpression,parseAbstraction,parseApplication,parseLet, andparseToken, which are already disambiguated by their callers.Tryonly where true backtracking is needed:parseStatement, which must choose betweenparseLetandparseDeclare.parseExpressionwhen the iterator is exhausted (addedDone()guard).Decisions
Trynow operates on the original iterator instead of a copy, removing the confusing pattern where the callback'siwas a different object than the caller'si.parseSoftBreakandparseHardBreakhelper functions sinceParseRawTokenno longer needsTrywrapping.Benefits
Trycall.ipattern.Tryis now only used at genuine choice points in the grammar.Checklist
<type>/<description>). Always use underscores.