This commit is contained in:
Jonathan Turner 2019-05-31 04:12:47 +12:00
commit 9bf279508e
2 changed files with 53 additions and 1 deletions

View file

@ -309,7 +309,8 @@ fn classify_command(
})) }))
} }
false => { false => {
let arg_list_strings: Vec<String> = args.iter().map(|i| i.print()).collect(); let arg_list_strings: Vec<String> =
args.iter().map(|i| i.as_external_arg()).collect();
Ok(ClassifiedCommand::External(ExternalCommand { Ok(ClassifiedCommand::External(ExternalCommand {
name: other.to_string(), name: other.to_string(),

View file

@ -64,6 +64,17 @@ impl Expression {
} }
} }
crate fn as_external_arg(&self) -> String {
match self {
Expression::Leaf(l) => l.as_external_arg(),
Expression::Parenthesized(p) => p.as_external_arg(),
Expression::Block(b) => b.as_external_arg(),
Expression::VariableReference(r) => r.as_external_arg(),
Expression::Path(p) => p.as_external_arg(),
Expression::Binary(b) => b.as_external_arg(),
}
}
crate fn as_string(&self) -> Option<String> { crate fn as_string(&self) -> Option<String> {
match self { match self {
Expression::Leaf(Leaf::String(s)) => Some(s.to_string()), Expression::Leaf(Leaf::String(s)) => Some(s.to_string()),
@ -82,6 +93,10 @@ impl Block {
fn print(&self) -> String { fn print(&self) -> String {
format!("{{ {} }}", self.expr.print()) format!("{{ {} }}", self.expr.print())
} }
fn as_external_arg(&self) -> String {
format!("{{ {} }}", self.expr.as_external_arg())
}
} }
#[derive(Debug, Clone, Ord, PartialOrd, Eq, PartialEq, new)] #[derive(Debug, Clone, Ord, PartialOrd, Eq, PartialEq, new)]
@ -93,6 +108,10 @@ impl Parenthesized {
fn print(&self) -> String { fn print(&self) -> String {
format!("({})", self.expr.print()) format!("({})", self.expr.print())
} }
fn as_external_arg(&self) -> String {
format!("({})", self.expr.as_external_arg())
}
} }
#[derive(Debug, Clone, Ord, PartialOrd, Eq, PartialEq, Getters, new)] #[derive(Debug, Clone, Ord, PartialOrd, Eq, PartialEq, Getters, new)]
@ -114,6 +133,16 @@ impl Path {
out out
} }
crate fn as_external_arg(&self) -> String {
let mut out = self.head.as_external_arg();
for item in self.tail.iter() {
out.push_str(&format!(".{}", item));
}
out
}
} }
#[derive(Debug, Clone, Ord, PartialOrd, Eq, PartialEq)] #[derive(Debug, Clone, Ord, PartialOrd, Eq, PartialEq)]
@ -133,6 +162,10 @@ impl Variable {
Variable::Other(s) => format!("${}", s), Variable::Other(s) => format!("${}", s),
} }
} }
fn as_external_arg(&self) -> String {
self.print()
}
} }
impl FromStr for Variable { impl FromStr for Variable {
@ -191,6 +224,15 @@ impl Leaf {
Leaf::Int(i) => format!("{}", i), Leaf::Int(i) => format!("{}", i),
} }
} }
fn as_external_arg(&self) -> String {
match self {
Leaf::String(s) => format!("{}", s),
Leaf::Bare(path) => format!("{}", path.to_string()),
Leaf::Boolean(b) => format!("{}", b),
Leaf::Int(i) => format!("{}", i),
}
}
} }
#[derive(Debug, Clone, Ord, PartialOrd, Eq, PartialEq, new)] #[derive(Debug, Clone, Ord, PartialOrd, Eq, PartialEq, new)]
@ -209,6 +251,15 @@ impl Binary {
self.right.print() self.right.print()
) )
} }
fn as_external_arg(&self) -> String {
format!(
"{} {} {}",
self.left.as_external_arg(),
self.operator.print(),
self.right.as_external_arg()
)
}
} }
#[derive(Debug, Clone)] #[derive(Debug, Clone)]