Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
reubeno committed May 30, 2024
1 parent b43de31 commit a9950bc
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 18 deletions.
7 changes: 7 additions & 0 deletions cli/tests/cases/compound_cmds/case.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,10 @@ cases:
}
myfunc
- name: "Case with non-dsemi"
stdin: |
case "b" in
a) echo "a";;
b) echo "b"
esac
24 changes: 6 additions & 18 deletions parser/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -402,27 +402,15 @@ peg::parser! {

// TODO: validate if this should call non_reserved_word() or word()
pub(crate) rule case_clause() -> ast::CaseClauseCommand =
specific_word("case") w:non_reserved_word() linebreak() _in() linebreak() c:(case_list() / case_list_ns()) specific_word("esac") {
ast::CaseClauseCommand { value: ast::Word::from(w), cases: c }
} /
specific_word("case") w:non_reserved_word() linebreak() _in() linebreak() specific_word("esac") {
ast::CaseClauseCommand{ value: ast::Word::from(w), cases: vec![] }
}
specific_word("case") w:non_reserved_word() linebreak() _in() linebreak() first_items:case_item()* last_item:case_item_ns()? specific_word("esac") {
let mut cases = first_items;

rule case_list_ns() -> Vec<ast::CaseItem> =
first:case_list()? last:case_item_ns() {
let mut items = vec![];
if let Some(mut first) = first {
for item in first.into_iter() {
items.push(item);
}
if let Some(last_item) = last_item {
cases.push(last_item);
}
items.push(last);
items
}

rule case_list() -> Vec<ast::CaseItem> =
c:case_item()+
ast::CaseClauseCommand { value: ast::Word::from(w), cases }
}

pub(crate) rule case_item_ns() -> ast::CaseItem =
specific_operator("(")? p:pattern() specific_operator(")") c:compound_list() {
Expand Down

0 comments on commit a9950bc

Please sign in to comment.