diff options
author | Jesse Luehrs <doy@tozt.net> | 2022-01-17 01:19:08 -0500 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2022-01-17 01:23:08 -0500 |
commit | 9b1595b795121d233cd0cf32537661839e318914 (patch) | |
tree | 26edb4376ed189373e8a4f3b3d41da6c27d23bf4 /src/parse/ast.rs | |
parent | 1327c2a7ba3b81fe69e4126270b2cfe24c8aa4ee (diff) | |
download | nbsh-9b1595b795121d233cd0cf32537661839e318914.tar.gz nbsh-9b1595b795121d233cd0cf32537661839e318914.zip |
basic subshell implementation
Diffstat (limited to 'src/parse/ast.rs')
-rw-r--r-- | src/parse/ast.rs | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/src/parse/ast.rs b/src/parse/ast.rs index bac40c8..9d74331 100644 --- a/src/parse/ast.rs +++ b/src/parse/ast.rs @@ -141,7 +141,36 @@ impl Exe { } fn build_ast(pair: pest::iterators::Pair<Rule>) -> Self { - assert!(matches!(pair.as_rule(), Rule::exe)); + assert!(matches!(pair.as_rule(), Rule::subshell | Rule::exe)); + if matches!(pair.as_rule(), Rule::subshell) { + return Self { + exe: Word { + parts: vec![WordPart::SingleQuoted( + std::env::current_exe() + .unwrap() + .to_str() + .unwrap() + .to_string(), + )], + }, + args: vec![ + Word { + parts: vec![WordPart::SingleQuoted("-c".to_string())], + }, + Word { + parts: vec![WordPart::SingleQuoted( + pair.as_str() + .strip_prefix('(') + .unwrap() + .strip_suffix(')') + .unwrap() + .to_string(), + )], + }, + ], + redirects: vec![], + }; + } let mut iter = pair.into_inner(); let exe = match WordOrRedirect::build_ast(iter.next().unwrap()) { WordOrRedirect::Word(word) => word, |