summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2022-01-18 01:40:43 -0500
committerJesse Luehrs <doy@tozt.net>2022-01-18 01:40:43 -0500
commit4b76cb2100fdefecff79e2999b2a648eb149018b (patch)
treef6b06d49d2751a731ef27967815cc65b4aa066fc /src
parentd53e7af40835b06a391bd8780edaa0160eec2411 (diff)
downloadnbsh-4b76cb2100fdefecff79e2999b2a648eb149018b.tar.gz
nbsh-4b76cb2100fdefecff79e2999b2a648eb149018b.zip
support redirects with subshells
Diffstat (limited to 'src')
-rw-r--r--src/parse/ast.rs6
-rw-r--r--src/shell.pest4
2 files changed, 7 insertions, 3 deletions
diff --git a/src/parse/ast.rs b/src/parse/ast.rs
index bd177a4..e2d5840 100644
--- a/src/parse/ast.rs
+++ b/src/parse/ast.rs
@@ -155,8 +155,10 @@ impl Exe {
fn build_ast(pair: pest::iterators::Pair<Rule>) -> Self {
assert!(matches!(pair.as_rule(), Rule::subshell | Rule::exe));
if matches!(pair.as_rule(), Rule::subshell) {
- let commands = pair.into_inner().next().unwrap();
+ let mut iter = pair.into_inner();
+ let commands = iter.next().unwrap();
assert!(matches!(commands.as_rule(), Rule::commands));
+ let redirects = iter.map(Redirect::build_ast).collect();
return Self {
exe: Word {
parts: vec![WordPart::SingleQuoted(
@@ -177,7 +179,7 @@ impl Exe {
)],
},
],
- redirects: vec![],
+ redirects,
};
}
let mut iter = pair.into_inner();
diff --git a/src/shell.pest b/src/shell.pest
index d2c96b8..0c63802 100644
--- a/src/shell.pest
+++ b/src/shell.pest
@@ -47,7 +47,9 @@ redir_prefix = @{
redirect = ${ redir_prefix ~ w? ~ word }
exe = ${ (redirect | word) ~ (w ~ (redirect | word))* }
-subshell = ${ "(" ~ w? ~ commands ~ w? ~ ")" }
+subshell = ${
+ "(" ~ w? ~ commands ~ w? ~ ")" ~ (w? ~ redirect ~ (w ~ redirect)*)?
+}
list = ${ word ~ (w ~ word)* }
pipeline = ${ (subshell | exe) ~ (w? ~ "|" ~ w? ~ (subshell | exe))* }