Skip to content
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

Preserve regex captures across stack frames #1447

Merged
merged 6 commits into from
Dec 18, 2023

Conversation

johnkerl
Copy link
Owner

@johnkerl johnkerl commented Dec 17, 2023

Regex captures for the =~ operator should belong to stack frames at the user-defined-function level.

Example:

mlr -n put '
func f() {
    if ("456 defg" =~ "([0-9]+) ([a-z]+)") {
        print "INNER: \1 \2";
    }
}
end {
    if ("123 abc" =~ "([0-9]+) ([a-z]+)") {
        print "OUTER PRE:  \1 \2";
        f();
        print "OUTER POST: \1 \2";
    }
}'

Before:

OUTER PRE:  123 abc
INNER: 456 defg
OUTER POST: 456 defg

After:

OUTER PRE:  123 abc
INNER: 456 defg
OUTER POST: 123 abc

To do: unit-test cases, and doc updates.

Context: second PR on #1401.

@johnkerl johnkerl marked this pull request as ready for review December 18, 2023 15:11
@johnkerl johnkerl merged commit 4053d76 into main Dec 18, 2023
6 checks passed
@johnkerl johnkerl deleted the kerl/regex-captures-by-frame branch December 18, 2023 15:21
This was referenced Dec 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant