use oak_core::{ElementType, UniversalElementRole};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum RhombusElementType {
SourceFile,
Whitespace,
Newline,
Comment,
LineComment,
NumberLiteral,
StringLiteral,
BooleanLiteral,
Identifier,
Block,
Statement,
Expression,
Error,
Eof,
}
impl ElementType for RhombusElementType {
type Role = UniversalElementRole;
fn role(&self) -> Self::Role {
match self {
Self::SourceFile => UniversalElementRole::Root,
Self::Error => UniversalElementRole::Error,
Self::Block => UniversalElementRole::Statement,
Self::Statement => UniversalElementRole::Statement,
Self::Expression => UniversalElementRole::Expression,
_ => UniversalElementRole::None,
}
}
}
impl From<crate::lexer::token_type::RhombusTokenType> for RhombusElementType {
fn from(token: crate::lexer::token_type::RhombusTokenType) -> Self {
use crate::lexer::token_type::RhombusTokenType as T;
match token {
T::Whitespace => RhombusElementType::Whitespace,
T::Newline => RhombusElementType::Newline,
T::Comment => RhombusElementType::Comment,
T::LineComment => RhombusElementType::LineComment,
T::NumberLiteral => RhombusElementType::NumberLiteral,
T::StringLiteral => RhombusElementType::StringLiteral,
T::BooleanLiteral => RhombusElementType::BooleanLiteral,
T::Identifier => RhombusElementType::Identifier,
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,
T::Eof => RhombusElementType::Eof,
_ => RhombusElementType::Error,
}
}
}