From 1c2486a55c21b323f73c72c0128def0fcac061eb Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Fri, 31 Dec 2021 03:36:33 -0500 Subject: basic implementation of pipes --- src/parse.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src/parse.rs') 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, + input_string: String, } impl Pipeline { + pub fn parse(pipeline: &str) -> Result { + 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) -> 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, -- cgit v1.2.3-54-g00ecf