#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Span {
pub start: usize,
pub end: usize,
}
impl Span {
pub fn new(start: usize, end: usize) -> Self {
Self { start, end }
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Node {
Element(Element),
Fragment(Fragment),
}
impl Node {
pub fn span(&self) -> Span {
match self {
Node::Element(element) => element.span,
Node::Fragment(fragment) => fragment.span,
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Element {
pub name: ElementName,
pub attributes: Vec<Attribute>,
pub children: Vec<Child>,
pub span: Span,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Fragment {
pub children: Vec<Child>,
pub span: Span,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ElementName {
Simple(String),
Member(Vec<String>),
}
impl ElementName {
pub fn as_written(&self) -> String {
match self {
ElementName::Simple(name) => name.clone(),
ElementName::Member(parts) => parts.join("."),
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Attribute {
Named {
name: String,
value: AttributeValue,
span: Span,
},
Spread { expression: String, span: Span },
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum AttributeValue {
Expression(String),
StringLiteral(String),
Boolean,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Child {
Node(Node),
Expression {
expression: String,
span: Span,
},
Text {
text: String,
span: Span,
},
Comment {
luau: String,
span: Span,
},
}
impl Child {
pub fn span(&self) -> Span {
match self {
Child::Node(node) => node.span(),
Child::Expression { span, .. }
| Child::Text { span, .. }
| Child::Comment { span, .. } => *span,
}
}
}