summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2022-01-08 14:31:47 -0500
committerJesse Luehrs <doy@tozt.net>2022-01-08 14:31:47 -0500
commit7b932969d69dc99b49f1a7a7ec7e5d87024bcfe2 (patch)
treebb2b69901986a8865d790d76bd6e49a3ad79ccb3
parent83de263441105e669acf79498788e1b66c6e3945 (diff)
downloadnbsh-7b932969d69dc99b49f1a7a7ec7e5d87024bcfe2.tar.gz
nbsh-7b932969d69dc99b49f1a7a7ec7e5d87024bcfe2.zip
there's no reason to eval at all in the main shell
-rw-r--r--src/parse.rs16
-rw-r--r--src/parse/ast.rs15
-rw-r--r--src/shell/history/mod.rs3
3 files changed, 7 insertions, 27 deletions
diff --git a/src/parse.rs b/src/parse.rs
index f147892..f2bee2c 100644
--- a/src/parse.rs
+++ b/src/parse.rs
@@ -1,30 +1,14 @@
pub mod ast;
#[derive(Debug)]
-pub struct Commands {
- pipelines: Vec<Pipeline>,
-}
-
-impl Commands {
- pub fn pipelines(&self) -> &[Pipeline] {
- &self.pipelines
- }
-}
-
-#[derive(Debug)]
pub struct Pipeline {
exes: Vec<Exe>,
- input_string: String,
}
impl Pipeline {
pub fn into_exes(self) -> impl Iterator<Item = Exe> {
self.exes.into_iter()
}
-
- pub fn input_string(&self) -> &str {
- &self.input_string
- }
}
#[derive(Debug)]
diff --git a/src/parse/ast.rs b/src/parse/ast.rs
index f9f7483..55a71f4 100644
--- a/src/parse/ast.rs
+++ b/src/parse/ast.rs
@@ -25,14 +25,8 @@ impl Commands {
))
}
- pub fn eval(self, env: &Env) -> super::Commands {
- super::Commands {
- pipelines: self
- .pipelines
- .into_iter()
- .map(|pipeline| pipeline.eval(env))
- .collect(),
- }
+ pub fn pipelines(&self) -> &[Pipeline] {
+ &self.pipelines
}
pub fn input_string(&self) -> &str {
@@ -71,10 +65,13 @@ impl Pipeline {
pub fn eval(self, env: &Env) -> super::Pipeline {
super::Pipeline {
exes: self.exes.into_iter().map(|exe| exe.eval(env)).collect(),
- input_string: self.input_string,
}
}
+ pub fn input_string(&self) -> &str {
+ &self.input_string
+ }
+
fn build_ast(pipeline: pest::iterators::Pair<Rule>) -> Self {
assert!(matches!(pipeline.as_rule(), Rule::pipeline));
let input_string = pipeline.as_str().to_string();
diff --git a/src/shell/history/mod.rs b/src/shell/history/mod.rs
index 5b7f5f0..9e1d1fd 100644
--- a/src/shell/history/mod.rs
+++ b/src/shell/history/mod.rs
@@ -299,8 +299,7 @@ fn run_commands(
}
};
- let commands = ast.eval(&env);
- for pipeline in commands.pipelines() {
+ for pipeline in ast.pipelines() {
env.set_pipeline(pipeline.input_string().to_string());
match run_pipeline(&pty, &mut env, event_w.clone()).await {
Ok((pipeline_status, done)) => {