oak_rhombus/parser/
element_type.rs1use oak_core::{ElementType, UniversalElementRole};
2
3#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
5#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
6pub enum RhombusElementType {
7 SourceFile,
9 Whitespace,
11 Newline,
13 Comment,
15 LineComment,
17 NumberLiteral,
19 StringLiteral,
21 BooleanLiteral,
23 Identifier,
25 Block,
27 Statement,
29 Expression,
31 Error,
33 Eof,
35}
36
37impl ElementType for RhombusElementType {
38 type Role = UniversalElementRole;
39
40 fn role(&self) -> Self::Role {
41 match self {
42 Self::SourceFile => UniversalElementRole::Root,
43 Self::Error => UniversalElementRole::Error,
44 Self::Block => UniversalElementRole::Statement,
45 Self::Statement => UniversalElementRole::Statement,
46 Self::Expression => UniversalElementRole::Expression,
47 _ => UniversalElementRole::None,
48 }
49 }
50}
51
52impl From<crate::lexer::token_type::RhombusTokenType> for RhombusElementType {
53 fn from(token: crate::lexer::token_type::RhombusTokenType) -> Self {
54 use crate::lexer::token_type::RhombusTokenType as T;
55 match token {
56 T::Whitespace => RhombusElementType::Whitespace,
57 T::Newline => RhombusElementType::Newline,
58 T::Comment => RhombusElementType::Comment,
59 T::LineComment => RhombusElementType::LineComment,
60 T::NumberLiteral => RhombusElementType::NumberLiteral,
61 T::StringLiteral => RhombusElementType::StringLiteral,
62 T::BooleanLiteral => RhombusElementType::BooleanLiteral,
63 T::Identifier => RhombusElementType::Identifier,
64 T::Fun | T::Val | T::Var | T::Let | T::If | T::Else | T::Match | T::Case | T::Block | T::Module | T::Import | T::Export | T::Require | T::Provide => RhombusElementType::Identifier, T::LeftParen | T::RightParen | T::LeftBracket | T::RightBracket | T::LeftBrace | T::RightBrace | T::Dot | T::Comma | T::Colon | T::Semicolon => RhombusElementType::Identifier, T::Error => RhombusElementType::Error,
67 T::Eof => RhombusElementType::Eof,
68 _ => RhombusElementType::Error,
69 }
70 }
71}