-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Import named regex captures as fish variables #7459
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
Closed
Closed
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
f113ba0
Get rid of magic numbers in report_match() result
mqudsi 4f9d938
Add support for importing named regex matches
mqudsi 215a7b6
Add tests for regex variable import
mqudsi 0e1e577
fixup! Add support for importing named regex matches
mqudsi 1e19312
fixup! Add support for importing named regex matches
mqudsi e4eeb8b
fixup! Add support for importing named regex matches
mqudsi 5da1c72
fixup! Add tests for regex variable import
mqudsi e68b04d
Add documentation for regex import
mqudsi 314c865
Add named capture groups to changelog
mqudsi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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 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 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 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| #RUN: %fish %s | ||
| # Tests for importing named regex groups as fish variables | ||
|
|
||
| # Capture first match | ||
| echo "hello world" | string match --regex -q -- '(?<words>[^ ]+) ?' | ||
| printf "%s\n" $words | ||
| # CHECK: hello | ||
|
|
||
| # Capture multiple matches | ||
| echo "hello world" | string match --regex -q --all -- '(?<words>[^ ]+) ?' | ||
| printf "%s\n" $words | ||
| # CHECK: hello | ||
| # CHECK: world | ||
|
|
||
| # Capture multiple variables | ||
| echo "hello world" | string match -rq -- '^(?<word1>[^ ]+) (?<word2>.*)$' | ||
| printf "%s\n" $word1 $word2 | ||
| # CHECK: hello | ||
| # CHECK: world | ||
|
|
||
| # Clear variables on no match | ||
| set foo foo | ||
| echo "foo" | string match -rq -- '^(?<foo>bar)$' | ||
| echo $foo | ||
| # CHECK: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd expect |
||
|
|
||
| # Named group may be empty in some of the matches | ||
| set word | ||
| set punctuation | ||
| echo "hello world, boy!" | string match -a -qr -- '(?<word>[^ .,!;]+)(?<punctuation>[.,!;])?' | ||
| echo $word | ||
| # CHECK: hello world boy | ||
| printf "%s\n" $punctuation | ||
| # CHECK: | ||
| # CHECK: , | ||
| # CHECK: ! | ||
|
|
||
| # Verify read-only variables may not be imported | ||
| echo hello | string match -rq "(?<version>.*)" | ||
| # CHECKERR: Modification of read-only variable "version" is not allowed | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Usually member variables have the underscore. So the parameter would be
parserand the member variable would beparser_.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ridiculousfish I agree, but was sticking to the local convention (see parameter
argv0_). Would you like me to change them all?