use oak_core::{ElementType, Parser, UniversalElementRole};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[repr(u8)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum TclElementType {
Root,
Command,
ProcDefinition,
IfCommand,
WhileCommand,
ForCommand,
ForEachCommand,
SetCommand,
Word,
SimpleWord,
VariableWord,
ScriptWord,
BracedWord,
Number,
StringLiteral,
Identifier,
If,
Else,
ElseIf,
For,
While,
ForEach,
Proc,
Return,
Break,
Continue,
Set,
Unset,
Global,
Upvar,
Variable,
Plus,
Minus,
Star,
Slash,
Percent,
Equal,
NotEqual,
Less,
Greater,
LessEqual,
GreaterEqual,
Ampersand,
AmpersandAmpersand,
Pipe,
PipePipe,
Exclamation,
LeftParen,
RightParen,
LeftBracket,
RightBracket,
LeftBrace,
RightBrace,
Semicolon,
Comma,
Dollar,
Whitespace,
Newline,
Comment,
Error,
Eof,
}
impl ElementType for TclElementType {
type Role = UniversalElementRole;
fn role(&self) -> Self::Role {
match self {
TclElementType::Root => UniversalElementRole::Root,
TclElementType::Command => UniversalElementRole::Expression,
TclElementType::Word | TclElementType::SimpleWord | TclElementType::VariableWord | TclElementType::ScriptWord | TclElementType::BracedWord => UniversalElementRole::Expression,
TclElementType::Identifier => UniversalElementRole::Name,
TclElementType::Number | TclElementType::StringLiteral => UniversalElementRole::Value,
_ => UniversalElementRole::None,
}
}
}
impl From<crate::lexer::token_type::TclTokenType> for TclElementType {
fn from(token: crate::lexer::token_type::TclTokenType) -> Self {
unsafe { std::mem::transmute(token) }
}
}