fix: use greedy matching in FINAL pattern to handle nested parentheses#75
Merged
alexzhang13 merged 2 commits intoalexzhang13:mainfrom Jan 29, 2026
Merged
fix: use greedy matching in FINAL pattern to handle nested parentheses#75alexzhang13 merged 2 commits intoalexzhang13:mainfrom
alexzhang13 merged 2 commits intoalexzhang13:mainfrom
Conversation
Owner
|
Hm I see, yeah this is a good idea. There are some weird potential cases (e.g. FINAL(a) then FINAL(b)) but I don't think this should even happen in the first place. |
alexzhang13
approved these changes
Jan 29, 2026
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.
Summary
Fixes a bug in
find_final_answer()where non-greedy regex matching would incorrectly stop at the first closing parenthesis, breaking FINAL() patterns with nested parentheses.Problem
The old pattern
^\s*FINAL\((.*?)\)used non-greedy matching(.*?), which matched to the first)instead of the last). This caused incorrect parsing for:FINAL(func(arg1, arg2))→ capturedfunc(arg1, arg2(missing closing parenthesis)FINAL([1, 2, 3], (4, 5))→ captured[1, 2, 3], (4, 5(missing closing parenthesis)FINAL(calculate(10, 20) + process(data))→ only capturedcalculate(10, 20Solution
Changed regex pattern from
^\s*FINAL\((.*?)\)to^\s*FINAL\((.*)\)\s*$:(.*)matches to the last closing parenthesis\s*$anchor to ensure pattern matches to end of lineTesting
Added comprehensive test
test_final_with_nested_parentheses_greedy_matching()covering:All 135 existing tests pass.
Files Changed
rlm/utils/parsing.py: Updated FINAL regex pattern (2 lines modified)tests/test_parsing.py: Added nested parentheses test (27 lines added)