Skip to main content

oak_css/parser/
element_type.rs

1use crate::lexer::CssTokenType;
2use oak_core::{ElementType, UniversalElementRole};
3use serde::{Deserialize, Serialize};
4
5/// CSS element type
6#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
7pub enum CssElementType {
8    /// Source file (root)
9    SourceFile,
10    /// Rule set
11    RuleSet,
12    /// Selector list
13    SelectorList,
14    /// Selector
15    Selector,
16    /// Declaration block
17    DeclarationBlock,
18    /// Declaration
19    Declaration,
20    /// Property
21    Property,
22    /// Value
23    Value,
24    /// At-rule
25    AtRule,
26    /// Media query
27    MediaQuery,
28    /// Function
29    Function,
30    /// Url
31    Url,
32    /// Calc expression
33    CalcExpression,
34}
35
36impl ElementType for CssElementType {
37    type Role = UniversalElementRole;
38
39    fn role(&self) -> Self::Role {
40        match self {
41            Self::SourceFile => UniversalElementRole::Root,
42            Self::RuleSet => UniversalElementRole::Container,
43            Self::SelectorList => UniversalElementRole::Detail,
44            Self::DeclarationBlock => UniversalElementRole::Container,
45            Self::Declaration => UniversalElementRole::Statement,
46            _ => UniversalElementRole::None,
47        }
48    }
49}
50
51impl From<CssTokenType> for CssElementType {
52    fn from(token: CssTokenType) -> Self {
53        match token {
54            _ => Self::SourceFile, // Default
55        }
56    }
57}