Skip to content

Commit

Permalink
fix: allow usually-operator chars in regex parens (#224)
Browse files Browse the repository at this point in the history
Relax the parser's restrictions on which typically-parsed-as-operator tokens may be allowed in a parenthesized context of a regex in an extended test command.
  • Loading branch information
reubeno authored Oct 24, 2024
1 parent 733eff4 commit 02fb19e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
6 changes: 5 additions & 1 deletion brush-parser/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,11 @@ peg::parser! {
rule regex_word_piece() =
word() {} /
specific_operator("|") {} /
specific_operator("(") inner:regex_word() specific_operator(")") {}
specific_operator("(") parenthesized_regex_word()* specific_operator(")") {}

rule parenthesized_regex_word() =
regex_word_piece() /
!specific_operator(")") !specific_operator("]]") [_]

rule name() -> &'input str =
w:[Token::Word(_, _)] { w.to_str() }
Expand Down
5 changes: 5 additions & 0 deletions brush-shell/tests/cases/extended_tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,11 @@ cases:
echo "Matches"
fi
- name: "Regex with special chars in parens"
stdin: |
[[ "<" =~ (<) ]] && echo "1. Matched"
[[ ">" =~ (<) ]] && echo "2. Matched"
- name: "Empty and space checks"
stdin: |
check() {
Expand Down

0 comments on commit 02fb19e

Please sign in to comment.