aboutsummaryrefslogtreecommitdiffstats
path: root/src/parse.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/parse.rs')
-rw-r--r--src/parse.rs15
1 files changed, 9 insertions, 6 deletions
diff --git a/src/parse.rs b/src/parse.rs
index c30206a..2ed0dbf 100644
--- a/src/parse.rs
+++ b/src/parse.rs
@@ -19,10 +19,10 @@ impl Stage for PostExpansion {
type Res<T, E> = std::result::Result<T, E>;
-trait Expander {
+pub trait Expander {
type Error;
- fn expand_var(&mut self, v: VarName) -> Res<BString, Self::Error>;
- fn expand_cmd(&mut self, c: Ast<PreExpansion>) -> Res<BString, Self::Error>;
+ fn expand_var(&mut self, v: BString) -> Res<BString, Self::Error>;
+ fn expand_cmd(&mut self, c: Ast<PostExpansion>) -> Res<BString, Self::Error>;
}
#[derive(Debug, Clone)]
@@ -80,7 +80,7 @@ impl StringPart {
}
}
-#[derive(Debug)]
+#[derive(Debug, Clone)]
/// `"hi ${var} $(cmd) "` gets mapped to `[Boring("hi "), Var("var"), String(" "), Cmd(...), Boring(" ")]`
pub struct ExpString {
parts: Vec<StringPart>,
@@ -92,8 +92,11 @@ impl ExpString {
for part in self.parts.into_iter() {
let mut x = match part {
StringPart::Boring(items) => items,
- StringPart::Var(v) => e.expand_var(v)?,
- StringPart::Cmd(ast) => e.expand_cmd(ast)?,
+ StringPart::Var(v) => e.expand_var(v.name)?,
+ StringPart::Cmd(ast) => {
+ let exp = ast.expand(e)?;
+ e.expand_cmd(exp)?
+ }
};
out.append(&mut x);
}