Skip to main content

oak_sass/parser/
element_type.rs

1use oak_core::{ElementType, UniversalElementRole};
2
3/// Element types for the Sass language.
4#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
5#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
6pub enum SassElementType {
7    /// A source file.
8    SourceFile,
9    /// The root node.
10    Root,
11    /// A selector.
12    Selector,
13    /// A variable declaration.
14    Variable,
15    /// A mixin declaration.
16    Mixin,
17    /// A function declaration.
18    Function,
19    /// A value.
20    Value,
21    /// An object.
22    Object,
23    /// An array.
24    Array,
25    /// A string literal.
26    String,
27    /// A numeric literal.
28    Number,
29    /// A boolean literal.
30    Boolean,
31    /// A null literal.
32    Null,
33    /// An entry in an object.
34    ObjectEntry,
35    /// An element in an array.
36    ArrayElement,
37    /// An error node.
38    ErrorNode,
39    /// A left brace `{`.
40    LeftBrace,
41    /// A right brace `}`.
42    RightBrace,
43    /// A left bracket `[`.
44    LeftBracket,
45    /// A right bracket `]`.
46    RightBracket,
47    /// A comma `,`.
48    Comma,
49    /// A colon `:`.
50    Colon,
51    /// Whitespace.
52    Whitespace,
53    /// A comment.
54    Comment,
55    /// End of file marker.
56    Eof,
57    /// Syntax error.
58    Error,
59}
60
61impl ElementType for SassElementType {
62    type Role = UniversalElementRole;
63
64    fn role(&self) -> Self::Role {
65        match self {
66            Self::SourceFile | Self::Root => UniversalElementRole::Root,
67            Self::Error => UniversalElementRole::Error,
68            _ => UniversalElementRole::None,
69        }
70    }
71}
72
73impl From<crate::lexer::token_type::SassTokenType> for SassElementType {
74    fn from(token: crate::lexer::token_type::SassTokenType) -> Self {
75        use crate::lexer::token_type::SassTokenType as T;
76        match token {
77            T::Whitespace => Self::Whitespace,
78            T::LineComment | T::BlockComment => Self::Comment,
79            T::Eof => Self::Eof,
80            T::Error => Self::Error,
81            T::LeftBrace => Self::LeftBrace,
82            T::RightBrace => Self::RightBrace,
83            T::LeftBracket => Self::LeftBracket,
84            T::RightBracket => Self::RightBracket,
85            T::Comma => Self::Comma,
86            T::Colon => Self::Colon,
87            _ => Self::Error, // Fallback for now
88        }
89    }
90}