use crate::lexer::CppTokenType;
use oak_core::{ElementType, UniversalElementRole};
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[repr(u16)]
pub enum CppElementType {
Token(CppTokenType),
SourceFile,
FunctionDefinition,
ClassDefinition,
NamespaceDefinition,
DeclarationStatement,
ExpressionStatement,
CompoundStatement,
IfStatement,
WhileStatement,
ForStatement,
ReturnStatement,
FunctionCall,
Error,
}
impl From<CppTokenType> for CppElementType {
fn from(token: CppTokenType) -> Self {
Self::Token(token)
}
}
impl ElementType for CppElementType {
type Role = UniversalElementRole;
fn is_root(&self) -> bool {
matches!(self, Self::SourceFile)
}
fn is_error(&self) -> bool {
matches!(self, Self::Error)
}
fn role(&self) -> Self::Role {
match self {
Self::SourceFile => UniversalElementRole::Root,
Self::FunctionDefinition | Self::ClassDefinition | Self::NamespaceDefinition => UniversalElementRole::Definition,
Self::DeclarationStatement | Self::ExpressionStatement | Self::CompoundStatement | Self::IfStatement | Self::WhileStatement | Self::ForStatement | Self::ReturnStatement => UniversalElementRole::Statement,
Self::Error => UniversalElementRole::Error,
_ => UniversalElementRole::Container,
}
}
}