oak_tcl/parser/
element_type.rs1use oak_core::{ElementType, Parser, UniversalElementRole};
2
3#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
5#[repr(u8)]
6#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
7pub enum TclElementType {
8 Root,
10 Command,
12 ProcDefinition,
14 IfCommand,
16 WhileCommand,
18 ForCommand,
20 ForEachCommand,
22 SetCommand,
24 Word,
26 SimpleWord,
28 VariableWord,
30 ScriptWord,
32 BracedWord,
34
35 Number,
37 StringLiteral,
39 Identifier,
41
42 If,
44 Else,
46 ElseIf,
48 For,
50 While,
52 ForEach,
54 Proc,
56 Return,
58 Break,
60 Continue,
62 Set,
64 Unset,
66 Global,
68 Upvar,
70 Variable,
72
73 Plus,
75 Minus,
77 Star,
79 Slash,
81 Percent,
83 Equal,
85 NotEqual,
87 Less,
89 Greater,
91 LessEqual,
93 GreaterEqual,
95 Ampersand,
97 AmpersandAmpersand,
99 Pipe,
101 PipePipe,
103 Exclamation,
105
106 LeftParen,
108 RightParen,
110 LeftBracket,
112 RightBracket,
114 LeftBrace,
116 RightBrace,
118 Semicolon,
120 Comma,
122 Dollar,
124
125 Whitespace,
127 Newline,
129 Comment,
131 Error,
133 Eof,
135}
136
137impl ElementType for TclElementType {
138 type Role = UniversalElementRole;
139
140 fn role(&self) -> Self::Role {
141 match self {
142 TclElementType::Root => UniversalElementRole::Root,
143 TclElementType::Command => UniversalElementRole::Expression,
144 TclElementType::Word | TclElementType::SimpleWord | TclElementType::VariableWord | TclElementType::ScriptWord | TclElementType::BracedWord => UniversalElementRole::Expression,
145 TclElementType::Identifier => UniversalElementRole::Name,
146 TclElementType::Number | TclElementType::StringLiteral => UniversalElementRole::Value,
147 _ => UniversalElementRole::None,
148 }
149 }
150}
151
152impl From<crate::lexer::token_type::TclTokenType> for TclElementType {
153 fn from(token: crate::lexer::token_type::TclTokenType) -> Self {
154 unsafe { std::mem::transmute(token) }
155 }
156}