Skip to main content

oak_lua/parser/
element_type.rs

1use oak_core::{ElementType, Parser, UniversalElementRole};
2#[cfg(feature = "serde")]
3use serde::{Deserialize, Serialize};
4
5#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
6#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
7#[repr(u16)]
8pub enum LuaElementType {
9    Root,
10    // 关键字
11    And,
12    Break,
13    Do,
14    Else,
15    Elseif,
16    End,
17    False,
18    For,
19    Function,
20    Goto,
21    If,
22    In,
23    Local,
24    Nil,
25    Not,
26    Or,
27    Repeat,
28    Return,
29    Then,
30    True,
31    Until,
32    While,
33
34    // 标识符和字面量
35    Identifier,
36    Number,
37    String,
38
39    // 操作符
40    Plus,       // +
41    Minus,      // -
42    Star,       // *
43    Slash,      // /
44    Percent,    // %
45    Caret,      // ^
46    Hash,       // #
47    Ampersand,  // &
48    Tilde,      // ~
49    Pipe,       // |
50    LtLt,       // <<
51    GtGt,       // >>
52    SlashSlash, // //
53    EqEq,       // ==
54    TildeEq,    // ~=
55    LtEq,       // <=
56    GtEq,       // >=
57    Lt,         // <
58    Gt,         // >
59    Eq,         // =
60
61    // 分隔符
62    LeftParen,    // (
63    RightParen,   // )
64    LeftBrace,    // {
65    RightBrace,   // }
66    LeftBracket,  // [
67    RightBracket, // ]
68    ColonColon,   // ::
69    Semicolon,    // ;
70    Colon,        // :
71    Comma,        // ,
72    Dot,          // .
73    DotDot,       // ..
74    DotDotDot,    // ...
75
76    // 空白和注释
77    Whitespace,
78    Newline,
79    Comment,
80
81    // 特殊标记
82    EndOfStream,
83    Error,
84
85    // 语法节点类型 (非终结符)
86    SourceFile,
87    FunctionDeclaration,
88    ParameterList,
89    Parameter,
90    BlockStatement,
91    LocalStatement,
92    AssignmentStatement,
93    ExpressionStatement,
94    IfStatement,
95    WhileStatement,
96    ForStatement,
97    RepeatStatement,
98    DoStatement,
99    BreakStatement,
100    ReturnStatement,
101    GotoStatement,
102    LabelStatement,
103    IdentifierExpression,
104    LiteralExpression,
105    BooleanLiteral,
106    NilLiteral,
107    ParenthesizedExpression,
108    BinaryExpression,
109    UnaryExpression,
110    CallExpression,
111    MemberExpression,
112    IndexExpression,
113    TableConstructorExpression,
114    FunctionExpression,
115    VarargExpression,
116    TableField,
117    FieldList,
118    ArgumentList,
119    VariableList,
120    ExpressionList,
121    NameList,
122    FunctionName,
123    FunctionBody,
124    ChunkStatement,
125    StatementList,
126}
127
128impl ElementType for LuaElementType {
129    type Role = UniversalElementRole;
130
131    fn role(&self) -> Self::Role {
132        match self {
133            _ => UniversalElementRole::None,
134        }
135    }
136}
137
138impl From<crate::lexer::token_type::LuaTokenType> for LuaElementType {
139    fn from(token: crate::lexer::token_type::LuaTokenType) -> Self {
140        unsafe { std::mem::transmute(token) }
141    }
142}