#[derive(Debug, Clone, PartialEq)]
pub struct Ast {
pub blueprint: BlueprintBlock,
}
#[derive(Debug, Clone, PartialEq)]
pub struct BlueprintBlock {
pub name: String,
pub items: Vec<AstItem>,
}
#[derive(Debug, Clone, PartialEq)]
pub enum AstItem {
Property(Property),
Block(Block),
Line(RawLine),
}
#[derive(Debug, Clone, PartialEq)]
pub struct Property {
pub key: String,
pub value: PropertyValue,
pub line: usize,
}
#[derive(Debug, Clone, PartialEq)]
pub enum PropertyValue {
String(String),
Int(i64),
Float(f64),
Bool(bool),
MultiLine(String),
}
impl PropertyValue {
pub fn as_str(&self) -> Option<&str> {
match self {
PropertyValue::String(s) | PropertyValue::MultiLine(s) => Some(s),
_ => None,
}
}
pub fn as_i64(&self) -> Option<i64> {
match self {
PropertyValue::Int(n) => Some(*n),
_ => None,
}
}
pub fn as_bool(&self) -> Option<bool> {
match self {
PropertyValue::Bool(b) => Some(*b),
_ => None,
}
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct Block {
pub block_type: String,
pub name: Option<String>,
pub items: Vec<AstItem>,
pub line: usize,
}
#[derive(Debug, Clone, PartialEq)]
pub struct RawLine {
pub content: String,
pub line: usize,
}