summaryrefslogtreecommitdiffstats
path: root/src/parse.rs
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2021-12-31 03:36:33 -0500
committerJesse Luehrs <doy@tozt.net>2021-12-31 03:36:33 -0500
commit1c2486a55c21b323f73c72c0128def0fcac061eb (patch)
treed290d26aa6dc6462aee08f8620159980b43f80c3 /src/parse.rs
parentd82cd70272ea300fcfd98110f674580b835ffab2 (diff)
downloadnbsh-1c2486a55c21b323f73c72c0128def0fcac061eb.tar.gz
nbsh-1c2486a55c21b323f73c72c0128def0fcac061eb.zip
basic implementation of pipes
Diffstat (limited to 'src/parse.rs')
-rw-r--r--src/parse.rs17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/parse.rs b/src/parse.rs
index dc0ec0a..526b6ce 100644
--- a/src/parse.rs
+++ b/src/parse.rs
@@ -62,17 +62,33 @@ impl Exe {
#[derive(Debug, Clone)]
pub struct Pipeline {
exes: Vec<Exe>,
+ input_string: String,
}
impl Pipeline {
+ pub fn parse(pipeline: &str) -> Result<Self, Error> {
+ Ok(Self::build_ast(
+ Shell::parse(Rule::pipeline, pipeline)
+ .map_err(|e| Error::new(pipeline, anyhow::anyhow!(e)))?
+ .next()
+ .unwrap(),
+ ))
+ }
+
pub fn exes(&self) -> &[Exe] {
&self.exes
}
+ 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();
Self {
exes: pipeline.into_inner().map(Exe::build_ast).collect(),
+ input_string,
}
}
}
@@ -117,6 +133,7 @@ impl Commands {
}
}
+#[derive(Debug)]
pub struct Error {
input: String,
e: anyhow::Error,