Skip to main content

oak_tcl/parser/
element_type.rs

1use oak_core::{ElementType, Parser, UniversalElementRole};
2
3/// Tcl element type definition
4#[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 node
9    Root,
10    /// Command
11    Command,
12    /// Proc definition
13    ProcDefinition,
14    /// If command
15    IfCommand,
16    /// While command
17    WhileCommand,
18    /// For command
19    ForCommand,
20    /// ForEach command
21    ForEachCommand,
22    /// Set command
23    SetCommand,
24    /// Word
25    Word,
26    /// Simple word
27    SimpleWord,
28    /// Variable word
29    VariableWord,
30    /// Script word
31    ScriptWord,
32    /// Braced word
33    BracedWord,
34
35    /// Number
36    Number,
37    /// String literal
38    StringLiteral,
39    /// Identifier
40    Identifier,
41
42    /// if keyword
43    If,
44    /// else keyword
45    Else,
46    /// elseif keyword
47    ElseIf,
48    /// for keyword
49    For,
50    /// while keyword
51    While,
52    /// foreach keyword
53    ForEach,
54    /// proc keyword
55    Proc,
56    /// return keyword
57    Return,
58    /// break keyword
59    Break,
60    /// continue keyword
61    Continue,
62    /// set keyword
63    Set,
64    /// unset keyword
65    Unset,
66    /// global keyword
67    Global,
68    /// upvar keyword
69    Upvar,
70    /// variable keyword
71    Variable,
72
73    /// Plus (+)
74    Plus,
75    /// Minus (-)
76    Minus,
77    /// Star (*)
78    Star,
79    /// Slash (/)
80    Slash,
81    /// Percent (%)
82    Percent,
83    /// Equal (=)
84    Equal,
85    /// Not equal (!=)
86    NotEqual,
87    /// Less (<)
88    Less,
89    /// Greater (>)
90    Greater,
91    /// Less equal (<=)
92    LessEqual,
93    /// Greater equal (>=)
94    GreaterEqual,
95    /// Ampersand (&)
96    Ampersand,
97    /// Logical AND (&&)
98    AmpersandAmpersand,
99    /// Pipe (|)
100    Pipe,
101    /// Logical OR (||)
102    PipePipe,
103    /// Exclamation (!)
104    Exclamation,
105
106    /// Left parenthesis (()
107    LeftParen,
108    /// Right parenthesis ())
109    RightParen,
110    /// Left bracket ([)
111    LeftBracket,
112    /// Right bracket (])
113    RightBracket,
114    /// Left brace ({)
115    LeftBrace,
116    /// Right brace (})
117    RightBrace,
118    /// Semicolon (;)
119    Semicolon,
120    /// Comma (,)
121    Comma,
122    /// Dollar ($)
123    Dollar,
124
125    /// Whitespace
126    Whitespace,
127    /// Newline
128    Newline,
129    /// Comment
130    Comment,
131    /// Error
132    Error,
133    /// End of file
134    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}