use oak_core::{ElementType, UniversalElementRole};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[repr(u16)]
pub enum PythonElementType {
Whitespace,
Comment,
Identifier,
Number,
String,
Bytes,
FString,
AndKeyword,
AsKeyword,
AssertKeyword,
AsyncKeyword,
AwaitKeyword,
BreakKeyword,
ClassKeyword,
ContinueKeyword,
DefKeyword,
DelKeyword,
ElifKeyword,
ElseKeyword,
ExceptKeyword,
FalseKeyword,
FinallyKeyword,
ForKeyword,
FromKeyword,
GlobalKeyword,
IfKeyword,
ImportKeyword,
InKeyword,
IsKeyword,
LambdaKeyword,
NoneKeyword,
NonlocalKeyword,
NotKeyword,
OrKeyword,
PassKeyword,
RaiseKeyword,
ReturnKeyword,
TrueKeyword,
TryKeyword,
WhileKeyword,
WithKeyword,
YieldKeyword,
Plus,
Minus,
Star,
DoubleStar,
Slash,
DoubleSlash,
Percent,
At,
LeftShift,
RightShift,
Ampersand,
Pipe,
Caret,
Tilde,
Less,
Greater,
LessEqual,
GreaterEqual,
Equal,
NotEqual,
Assign,
PlusAssign,
MinusAssign,
StarAssign,
DoubleStarAssign,
SlashAssign,
DoubleSlashAssign,
PercentAssign,
AtAssign,
AmpersandAssign,
PipeAssign,
CaretAssign,
LeftShiftAssign,
RightShiftAssign,
LeftParen,
RightParen,
LeftBracket,
RightBracket,
LeftBrace,
RightBrace,
Comma,
Colon,
Semicolon,
Dot,
Arrow,
Ellipsis,
Newline,
Indent,
Dedent,
Eof,
Error,
Root,
Module,
InteractiveModule,
ExpressionModule,
Name,
Constant,
JoinedStr,
Expr,
Tuple,
GeneratorExp,
List,
ListComp,
Dict,
DictComp,
SetComp,
Set,
UnaryOp,
Keyword,
Starred,
Call,
Slice,
Subscript,
Attribute,
BinOp,
BoolOp,
Compare,
IfExp,
Lambda,
Yield,
YieldFrom,
NamedExpr,
FormattedValue,
Await,
Suite,
Decorator,
AssignStmt,
WithItem,
Return,
ReturnStmt,
Pass,
PassStmt,
Break,
BreakStmt,
Continue,
ContinueStmt,
Global,
GlobalStmt,
Nonlocal,
NonlocalStmt,
Assert,
AssertStmt,
If,
IfStmt,
While,
WhileStmt,
For,
ForStmt,
AsyncFor,
Try,
TryStmt,
ExceptHandler,
With,
WithStmt,
AsyncWith,
FunctionDef,
AsyncFunctionDef,
ClassDef,
Import,
ImportFrom,
ImportStmt,
ImportFromStmt,
ExprStmt,
Delete,
DeleteStmt,
Raise,
RaiseStmt,
Arguments,
Arg,
Alias,
Comprehension,
}
impl From<u16> for PythonElementType {
fn from(d: u16) -> PythonElementType {
unsafe { core::mem::transmute::<u16, PythonElementType>(d) }
}
}
impl PythonElementType {
pub fn is_keyword(&self) -> bool {
matches!(
self,
Self::AndKeyword
| Self::AsKeyword
| Self::AssertKeyword
| Self::AsyncKeyword
| Self::AwaitKeyword
| Self::BreakKeyword
| Self::ClassKeyword
| Self::ContinueKeyword
| Self::DefKeyword
| Self::DelKeyword
| Self::ElifKeyword
| Self::ElseKeyword
| Self::ExceptKeyword
| Self::FalseKeyword
| Self::FinallyKeyword
| Self::ForKeyword
| Self::FromKeyword
| Self::GlobalKeyword
| Self::IfKeyword
| Self::ImportKeyword
| Self::InKeyword
| Self::IsKeyword
| Self::LambdaKeyword
| Self::NoneKeyword
| Self::NonlocalKeyword
| Self::NotKeyword
| Self::OrKeyword
| Self::PassKeyword
| Self::RaiseKeyword
| Self::ReturnKeyword
| Self::TrueKeyword
| Self::TryKeyword
| Self::WhileKeyword
| Self::WithKeyword
| Self::YieldKeyword
)
}
}
impl PythonElementType {
pub fn is_trivia(&self) -> bool {
matches!(self, Self::Whitespace | Self::Comment)
}
}
impl ElementType for PythonElementType {
type Role = UniversalElementRole;
fn role(&self) -> Self::Role {
match self {
_ => UniversalElementRole::None,
}
}
}
impl From<crate::lexer::token_type::PythonTokenType> for PythonElementType {
fn from(token: crate::lexer::token_type::PythonTokenType) -> Self {
unsafe { std::mem::transmute(token) }
}
}