use muskitty_css_tokenizer::Token;
#[derive(Debug, Clone, Default)]
pub struct Stylesheet {
pub rules: Vec<Rule>,
}
#[derive(Debug, Clone)]
pub enum Rule {
AtRule(AtRule),
QualifiedRule(QualifiedRule),
Declarations(Vec<Declaration>),
}
#[derive(Debug, Clone)]
pub struct AtRule {
pub name: String,
pub prelude: Vec<ComponentValue>,
pub declarations: Option<Vec<Declaration>>,
pub child_rules: Option<Vec<Rule>>,
}
#[derive(Debug, Clone)]
pub struct QualifiedRule {
pub prelude: Vec<ComponentValue>,
pub declarations: Vec<Declaration>,
pub child_rules: Vec<Rule>,
}
#[derive(Debug, Clone)]
pub struct Declaration {
pub name: String,
pub value: Vec<ComponentValue>,
pub important: bool,
pub original_text: Option<String>,
}
#[derive(Debug, Clone)]
pub enum ComponentValue {
PreservedToken(Token),
Function(Function),
SimpleBlock(SimpleBlock),
}
#[derive(Debug, Clone)]
pub struct Function {
pub name: String,
pub value: Vec<ComponentValue>,
}
#[derive(Debug, Clone)]
pub struct SimpleBlock {
pub kind: BlockKind,
pub value: Vec<ComponentValue>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum BlockKind {
Curly,
Square,
Paren,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ParseError {
pub message: String,
}
impl ParseError {
pub fn new(message: impl Into<String>) -> Self {
ParseError {
message: message.into(),
}
}
}
impl std::fmt::Display for ParseError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "CSS parse error: {}", self.message)
}
}
impl std::error::Error for ParseError {}