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