Skip to main content

oak_scss/parser/
element_type.rs

1use oak_core::{ElementType, UniversalElementRole};
2
3#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
4#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
5#[repr(u8)]
6pub enum ScssElementType {
7    // Keywords
8    /// '@import' keyword.
9    Import,
10    /// '@include' keyword.
11    Include,
12    /// '@mixin' keyword.
13    Mixin,
14    /// '@function' keyword.
15    Function,
16    /// '@return' keyword.
17    Return,
18    /// '@if' keyword.
19    If,
20    /// '@else' keyword.
21    Else,
22    /// '@for' keyword.
23    For,
24    /// '@while' keyword.
25    While,
26    /// '@each' keyword.
27    Each,
28    /// 'in' keyword.
29    In,
30    /// 'true' keyword.
31    True,
32    /// 'false' keyword.
33    False,
34    /// 'null' keyword.
35    Null,
36
37    // Operators
38    /// '==' operator.
39    EqEq,
40    /// '!=' operator.
41    Ne,
42    /// '<=' operator.
43    Le,
44    /// '>=' operator.
45    Ge,
46    /// '&&' operator.
47    AndAnd,
48    /// '||' operator.
49    OrOr,
50    /// '=' operator.
51    Eq,
52    /// '<' operator.
53    Lt,
54    /// '>' operator.
55    Gt,
56    /// 'and' operator.
57    And,
58    /// 'or' operator.
59    Or,
60    /// 'xor' operator.
61    Xor,
62    /// '+' operator.
63    Plus,
64    /// '-' operator.
65    Minus,
66    /// '*' operator.
67    Star,
68    /// '/' operator.
69    Slash,
70    /// '%' operator.
71    Percent,
72    /// '!' operator.
73    Bang,
74
75    // Punctuation
76    /// '(' punctuation.
77    LeftParen,
78    /// ')' punctuation.
79    RightParen,
80    /// '{' punctuation.
81    LeftBrace,
82    /// '}' punctuation.
83    RightBrace,
84    /// '[' punctuation.
85    LeftBracket,
86    /// ']' punctuation.
87    RightBracket,
88    /// ';' punctuation.
89    Semicolon,
90    /// ':' punctuation.
91    Colon,
92    /// ',' punctuation.
93    Comma,
94    /// '.' punctuation.
95    Dot,
96    /// '#' punctuation.
97    Hash,
98    /// '@' punctuation.
99    At,
100    /// '$' punctuation.
101    Dollar,
102
103    // Literals and Identifiers
104    /// Identifier.
105    Identifier,
106    /// Integer literal.
107    IntegerLiteral,
108    /// String literal.
109    StringLiteral,
110
111    // Others
112    /// Whitespace.
113    Whitespace,
114    /// Newline.
115    Newline,
116    /// Comment.
117    Comment,
118    /// End of file.
119    Eof,
120    /// Error token.
121    Error,
122
123    // Composite Elements
124    /// Source file.
125    SourceFile,
126    /// Rule set.
127    RuleSet,
128    /// Selector.
129    Selector,
130    /// Declaration.
131    Declaration,
132    /// Property.
133    Property,
134    /// Value node.
135    ValueNode,
136    /// Block.
137    Block,
138    /// Mixin declaration.
139    MixinDeclaration,
140    /// Function declaration.
141    FunctionDeclaration,
142    /// Include statement.
143    IncludeStatement,
144    /// Import statement.
145    ImportStatement,
146    /// Variable declaration.
147    VariableDeclaration,
148    /// If statement.
149    IfStatement,
150    /// For statement.
151    ForStatement,
152    /// Each statement.
153    EachStatement,
154    /// While statement.
155    WhileStatement,
156    /// Return statement.
157    ReturnStatement,
158}
159
160impl ElementType for ScssElementType {
161    type Role = UniversalElementRole;
162
163    fn role(&self) -> Self::Role {
164        match self {
165            Self::SourceFile => UniversalElementRole::Root,
166            Self::RuleSet | Self::MixinDeclaration | Self::FunctionDeclaration => UniversalElementRole::Definition,
167            Self::Block => UniversalElementRole::Container,
168            Self::Declaration | Self::Property => UniversalElementRole::Attribute,
169            Self::Selector => UniversalElementRole::Name,
170            Self::ValueNode => UniversalElementRole::Value,
171            Self::ImportStatement | Self::IncludeStatement | Self::VariableDeclaration | Self::IfStatement | Self::ForStatement | Self::EachStatement | Self::WhileStatement => UniversalElementRole::Statement,
172            Self::Error => UniversalElementRole::Error,
173            _ => UniversalElementRole::None,
174        }
175    }
176}
177
178impl From<crate::lexer::token_type::ScssTokenType> for ScssElementType {
179    fn from(token: crate::lexer::token_type::ScssTokenType) -> Self {
180        unsafe { std::mem::transmute(token) }
181    }
182}