From 96b45b2d3dd1ff0ee9312150f2a642058df7668b Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Sat, 8 Jan 2022 19:02:28 -0500 Subject: fix for loop parsing --- src/parse/ast.rs | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'src/parse/ast.rs') diff --git a/src/parse/ast.rs b/src/parse/ast.rs index f33734b..d71f6a3 100644 --- a/src/parse/ast.rs +++ b/src/parse/ast.rs @@ -48,7 +48,7 @@ pub enum Command { Pipeline(Pipeline), If(Pipeline), While(Pipeline), - For(String, Pipeline), + For(String, Vec), End, } @@ -71,10 +71,11 @@ impl Command { let mut inner = ty.into_inner(); let var = inner.next().unwrap(); assert!(matches!(var.as_rule(), Rule::bareword)); - Self::For( - var.as_str().to_string(), - Pipeline::build_ast(inner.next().unwrap()), - ) + let list = inner.next().unwrap(); + assert!(matches!(list.as_rule(), Rule::list)); + let vals = + list.into_inner().map(Word::build_ast).collect(); + Self::For(var.as_str().to_string(), vals) } Rule::control_end => Self::End, _ => unreachable!(), @@ -174,12 +175,19 @@ impl Exe { } #[derive(Debug, Clone, PartialEq, Eq)] -struct Word { +pub struct Word { parts: Vec, } impl Word { - fn eval(self, env: &Env) -> String { + fn build_ast(pair: pest::iterators::Pair) -> Self { + assert!(matches!(pair.as_rule(), Rule::word)); + Self { + parts: pair.into_inner().map(WordPart::build_ast).collect(), + } + } + + pub fn eval(self, env: &Env) -> String { self.parts .into_iter() .map(|part| part.eval(env)) -- cgit v1.2.3-54-g00ecf