use crate::ast::TemplateAst::*;
use crate::expr::common::ExpressionIR;
use crate::expr::common::ExpressionIR::ItemValue;
use crate::value::TmplValue;
#[derive(Debug)]
pub enum CommandParam {
Keywords,
Assignment(Vec<String>),
Expression(ExpressionIR),
StaticValue(TmplValue),
}
#[derive(Debug)]
pub struct Branch {
pub key: String,
pub params: Vec<CommandParam>,
pub child_stages: Vec<TemplateAst>,
}
impl Branch {
pub fn new(key: &str, params: Vec<CommandParam>) -> Self {
Branch {
key: key.to_string(),
params,
child_stages: vec![],
}
}
}
#[derive(Debug)]
pub enum TemplateAst {
ItemExpr(ExpressionIR),
ItemBranch(String, Vec<Branch>, bool),
ItemCommand(String, Vec<CommandParam>),
}
impl TemplateAst {
pub fn get_tag(&self) -> Option<&str> {
match self {
ItemExpr(_) => None,
ItemBranch(e, _, _) => Some(e),
ItemCommand(e, _) => Some(e),
}
}
pub fn new_text(text: &str) -> TemplateAst {
ItemExpr(ItemValue(TmplValue::Text(text.to_string())))
}
}