oak_bash/parser/
element_type.rs1use crate::lexer::BashTokenType;
2use oak_core::{ElementType, UniversalElementRole};
3
4#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
6#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
7pub enum BashElementType {
8 Token(BashTokenType),
10 Root,
12 CommandStatement,
14 VariableAssignment,
16 Pipeline,
18 Redirection,
20 IfStatement,
22 ForStatement,
24 WhileStatement,
26 FunctionDefinition,
28 Error,
30}
31
32impl From<BashTokenType> for BashElementType {
33 fn from(token: BashTokenType) -> Self {
34 Self::Token(token)
35 }
36}
37
38impl ElementType for BashElementType {
39 type Role = UniversalElementRole;
40
41 fn is_root(&self) -> bool {
42 matches!(self, Self::Root)
43 }
44
45 fn is_error(&self) -> bool {
46 matches!(self, Self::Error)
47 }
48
49 fn role(&self) -> Self::Role {
50 match self {
51 Self::Root => UniversalElementRole::Root,
52 Self::FunctionDefinition => UniversalElementRole::Definition,
53 Self::VariableAssignment => UniversalElementRole::Statement,
54 Self::CommandStatement | Self::IfStatement | Self::ForStatement | Self::WhileStatement | Self::Pipeline | Self::Redirection => UniversalElementRole::Statement,
55 Self::Error => UniversalElementRole::Error,
56 _ => UniversalElementRole::None,
57 }
58 }
59}