diff options
| author | Jonas Maier <> | 2026-03-06 17:38:32 +0100 |
|---|---|---|
| committer | Jonas Maier <> | 2026-03-06 17:38:32 +0100 |
| commit | 44628890b64befde0a1bb147d82d9bfe48b7e1af (patch) | |
| tree | c22b372c9674397e6acbdce2a2721433e9fcc813 /src/parse.rs | |
| parent | 0e73fe1d5edfe01789efa43c1c97a2c448cd25be (diff) | |
| download | pish-44628890b64befde0a1bb147d82d9bfe48b7e1af.tar.gz | |
shell expansion
Diffstat (limited to 'src/parse.rs')
| -rw-r--r-- | src/parse.rs | 15 |
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); } |
