Skip to content

Commit

Permalink
fix: realign newline parsing with spec (#99)
Browse files Browse the repository at this point in the history
  • Loading branch information
reubeno authored Jun 28, 2024
1 parent 919cf16 commit c310b0b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
9 changes: 4 additions & 5 deletions brush-parser/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ impl<R: std::io::BufRead> Parser<R> {
///
/// # Arguments
///
/// * `stop_on_unescaped_newline` - Whether or not to stop parsing when an unescaped newline is encountered.
/// * `stop_on_unescaped_newline` - Whether or not to stop parsing when an unescaped newline is
/// encountered.
pub fn parse(
&mut self,
stop_on_unescaped_newline: bool,
Expand Down Expand Up @@ -620,13 +621,11 @@ peg::parser! {
word()

rule newline_list() -> () =
newline()* {}
newline()+ {}

// N.B. We don't need to add a '?' to the invocation of the newline_list()
// rule because it already allows 0 newlines.
rule linebreak() -> () =
quiet! {
newline_list() {}
newline()* {}
}

rule separator_op() -> ast::SeparatorOperator =
Expand Down
5 changes: 5 additions & 0 deletions brush-shell/tests/cases/compound_cmds/subshell.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ cases:
stdin: |
(echo hi)
- name: "Subshells in sequence"
ignore_stderr: true
stdin: |
(echo hi)(echo there)
- name: "Subshell env usage"
stdin: |
(subshell_var=value && echo "subshell_var: ${subshell_var}")
Expand Down

0 comments on commit c310b0b

Please sign in to comment.