use crate::lexer::BashTokenType;
use oak_core::{ElementType, UniversalElementRole};
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum BashElementType {
Token(BashTokenType),
Root,
CommandStatement,
VariableAssignment,
Pipeline,
Redirection,
IfStatement,
ForStatement,
WhileStatement,
FunctionDefinition,
Error,
}
impl From<BashTokenType> for BashElementType {
fn from(token: BashTokenType) -> Self {
Self::Token(token)
}
}
impl ElementType for BashElementType {
type Role = UniversalElementRole;
fn is_root(&self) -> bool {
matches!(self, Self::Root)
}
fn is_error(&self) -> bool {
matches!(self, Self::Error)
}
fn role(&self) -> Self::Role {
match self {
Self::Root => UniversalElementRole::Root,
Self::FunctionDefinition => UniversalElementRole::Definition,
Self::VariableAssignment => UniversalElementRole::Statement,
Self::CommandStatement | Self::IfStatement | Self::ForStatement | Self::WhileStatement | Self::Pipeline | Self::Redirection => UniversalElementRole::Statement,
Self::Error => UniversalElementRole::Error,
_ => UniversalElementRole::None,
}
}
}