use std::ops::Deref;
#[derive(Eq, PartialEq, Debug, Clone)]
pub(crate) enum PathStep {
Name(String),
Index(String, usize),
}
impl Deref for PathStep {
type Target = str;
fn deref(&self) -> &Self::Target {
match self {
PathStep::Name(s) => s,
PathStep::Index(s, _) => s,
}
}
}
pub(crate) type Path = Vec<PathStep>;
pub(crate) type PathSlice<'a> = &'a [PathStep];
#[derive(Eq, PartialEq, Debug, Clone)]
pub(crate) enum Instruction {
Literal(String),
Value(Path),
FormattedValue(Path, String),
Branch(Path, bool, usize),
PushNamedContext(Path, String),
PushIterationContext(Path, String),
PopContext,
Iterate(usize),
Goto(usize),
Call(String, Path),
}
pub(crate) fn path_to_str(path: PathSlice) -> String {
let mut path_str = "".to_string();
for (i, step) in path.iter().enumerate() {
if i > 0 {
path_str.push('.');
}
path_str.push_str(step);
}
path_str
}