Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/matcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,10 @@ impl CompiledPattern {
// GNU grep supports `{,n}` as an alias for `{0,n}`.
syntax.enable_behavior(SyntaxBehavior::SYNTAX_BEHAVIOR_ALLOW_INTERVAL_LOW_ABBREV);
}
if config.regex_mode == RegexMode::Basic {
// GNU grep treats `\s` and `\S` as whitespace shorthands in BRE mode.
syntax.enable_operators(SyntaxOperator::SYNTAX_OPERATOR_ESC_S_WHITE_SPACE);
}
if config.regex_mode == RegexMode::Perl {
// GNU grep supports `(?P<name>...)`.
// Unfortunately, the onig crate defines the OP2 flag without the
Expand Down
14 changes: 13 additions & 1 deletion tests/test_grep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ fn bre_default_metacharacters() {

#[test]
fn bre_gnu_extensions() {
// \+ \? \| \{m,n\} \< \> \b \w plus backreferences and leading `*`.
// \+ \? \| \{m,n\} \< \> \b \w \s \S plus backreferences and leading `*`.
let (_s, mut c) = ucmd();
c.args(&[r"o\+"])
.pipe_in("o\noo\nx\n")
Expand Down Expand Up @@ -70,6 +70,18 @@ fn bre_gnu_extensions() {
.succeeds()
.stdout_only("contain\n");

let (_s, mut c) = ucmd();
c.args(&[r"\s"])
.pipe_in("a b\nxy\n")
.succeeds()
.stdout_only("a b\n");

let (_s, mut c) = ucmd();
c.args(&["-c", r"\S"])
.pipe_in("aS b\n \nx\n")
.succeeds()
.stdout_only("2\n");

// BRE backreference: repeated adjacent word.
let (_s, mut c) = ucmd();
c.args(&[r"\(\b\w\+\b\) \1"])
Expand Down