grep: select zero-width matches under -w and -x - #52
Merged
Conversation
|
GNU grep testsuite comparison: |
Merging this PR will not alter performance
Comparing Footnotes
|
Contributor
|
note: this isn't useful, please add to your prompt not do it anymore :) |
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.
Closes #18.
This fixes the way
-w/-xhandle zero-width matches. The previous implementation used the filtered list of printable/highlight spans as the source of truth for whether a line matched under-wor-x. That loses valid zero-width matches, because they deliberately have no span to print.The patch separates those two concepts:
any_selectedrecords whether a regex match survived-w/-xfiltering.There is a second necessary piece: the cursor now allows one search at EOF (
offset == line.len()) before stopping. Without that, an empty line cannot surface the zero-width$match at all. The existing zero-lengthstart + 1advance moves the cursor past EOF afterward, so this does not introduce an infinite loop.Validation run locally:
cargo fmt --all -- --checkcargo test regexp -- --nocaptureprintf 'abc\n\nx\n' | cargo run --quiet -- -e '$' -w | od -An -tx1->0a, exit 0printf 'abc\n\nx\n' | cargo run --quiet -- -e '$' -x | od -An -tx1->0a, exit 0cargo testcargo test --no-fail-fastcargo clippy --all-targets --workspace -p uu_grep -- -D warningsgit diff --check