From 4b76cb2100fdefecff79e2999b2a648eb149018b Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Tue, 18 Jan 2022 01:40:43 -0500 Subject: support redirects with subshells --- src/parse/ast.rs | 6 ++++-- src/shell.pest | 4 +++- 2 files changed, 7 insertions(+), 3 deletions(-) (limited to 'src') 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) -> 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))* } -- cgit v1.2.3-54-g00ecf