use crate::ast::ChainOp;
use crate::span::Span;
#[derive(Debug, Clone)]
pub struct File {
pub stylesheet: Vec<StyleItem>,
pub stylesheet_span: Span,
pub instances: Vec<Child>,
pub links: Vec<Link>,
}
#[derive(Debug, Clone)]
pub enum StyleItem {
RootDecl(Decl),
Var(Decl),
Rule(Rule),
Define(Define),
Binding(FuncDef),
}
#[derive(Debug, Clone)]
pub struct FuncDef {
pub name: String,
pub params: Vec<String>,
pub body: String,
pub span: Span,
}
#[derive(Debug, Clone)]
pub struct Rule {
pub selector: Selector,
pub decls: Vec<Decl>,
pub span: Span,
}
#[derive(Debug, Clone)]
pub struct Selector {
pub units: Vec<SelUnit>,
}
#[derive(Debug, Clone)]
pub enum SelUnit {
Type { name: String, id: Option<String> },
Class(String),
Id(String),
Link,
Dimension,
}
#[derive(Debug, Clone)]
pub struct Define {
pub name: String,
pub base: String,
pub style: Vec<Decl>,
pub style_span: Option<Span>,
pub children: Vec<Child>,
pub links: Vec<Link>,
pub span: Span,
}
#[derive(Debug, Clone)]
pub struct Node {
pub id: Option<String>,
pub ty: Option<String>,
pub label: Option<TextNode>,
pub classes: Vec<String>,
pub style: Vec<Decl>,
pub style_span: Option<Span>,
pub children: Vec<Child>,
pub links: Vec<Link>,
pub span: Span,
}
#[derive(Debug, Clone)]
pub enum Child {
Box(Node),
Text(TextNode),
}
#[derive(Debug, Clone)]
pub struct TextNode {
pub text: String,
pub style: Vec<Decl>,
pub style_span: Option<Span>,
pub span: Span,
}
#[derive(Debug, Clone)]
pub struct Link {
pub chain: Vec<EndpointGroup>,
pub ops: Vec<ChainOp>,
pub classes: Vec<String>,
pub style: Vec<Decl>,
pub style_span: Option<Span>,
pub label: Option<TextNode>,
pub labels: Vec<TextNode>,
pub span: Span,
}
#[derive(Debug, Clone)]
pub struct EndpointGroup {
pub endpoints: Vec<Endpoint>,
}
impl Link {
pub fn op(&self) -> ChainOp {
self.ops[0]
}
}
#[derive(Debug, Clone)]
pub struct Endpoint {
pub path: Vec<String>,
pub point: Option<PointRef>,
pub span: Span,
}
#[derive(Debug, Clone)]
pub struct PointRef {
pub name: String,
pub span: Span,
}
#[derive(Debug, Clone)]
pub struct Decl {
pub name: String,
pub groups: Vec<Vec<Value>>,
pub span: Span,
}
#[derive(Debug, Clone)]
pub enum Value {
Number(f64),
Percent(f64),
String(String),
Hex(String),
Ident(String),
Var(String),
Call(Call),
Expr(String),
NamedCall(Call, String),
Tuple(Vec<Value>),
}
#[derive(Debug, Clone)]
pub struct Call {
pub name: String,
pub args: Vec<Value>,
}