oak_pascal/kind/
mod.rs

1use oak_core::{SyntaxKind, Token};
2use serde::{Deserialize, Serialize};
3
4pub type PascalToken = Token<PascalSyntaxKind>;
5
6#[derive(Copy, Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
7pub enum PascalSyntaxKind {
8    // 空白和换行
9    Whitespace,
10    Newline,
11
12    // 注释
13    Comment,
14
15    // 关键字
16    Program,
17    Begin,
18    End,
19    Var,
20    Const,
21    Type,
22    Function,
23    Procedure,
24    If,
25    Then,
26    Else,
27    While,
28    Do,
29    For,
30    To,
31    Downto,
32    Repeat,
33    Until,
34    Case,
35    Of,
36    With,
37    Record,
38    Array,
39    Set,
40    File,
41    Packed,
42    Nil,
43    True,
44    False,
45    And,
46    Or,
47    Not,
48    Div,
49    Mod,
50    In,
51
52    // 标识符和字面量
53    Identifier,
54    IntegerLiteral,
55    RealLiteral,
56    StringLiteral,
57    CharLiteral,
58
59    // 运算符
60    Plus,         // +
61    Minus,        // -
62    Multiply,     // *
63    Divide,       // /
64    Assign,       // :=
65    Equal,        // =
66    NotEqual,     // <>
67    Less,         // <
68    LessEqual,    // <=
69    Greater,      // >
70    GreaterEqual, // >=
71
72    // 分隔符
73    LeftParen,    // (
74    RightParen,   // )
75    LeftBracket,  // [
76    RightBracket, // ]
77    Semicolon,    // ;
78    Comma,        // ,
79    Dot,          // .
80    Colon,        // :
81    Range,        // ..
82    Caret,        // ^
83
84    // 特殊
85    Error,
86    Eof,
87}
88
89impl SyntaxKind for PascalSyntaxKind {
90    fn is_trivia(&self) -> bool {
91        matches!(self, Self::Whitespace | Self::Newline | Self::Comment)
92    }
93
94    fn is_comment(&self) -> bool {
95        matches!(self, Self::Comment)
96    }
97
98    fn is_whitespace(&self) -> bool {
99        matches!(self, Self::Whitespace | Self::Newline)
100    }
101
102    fn is_token_type(&self) -> bool {
103        true // Pascal doesn't have element types in this simple implementation
104    }
105
106    fn is_element_type(&self) -> bool {
107        false // Pascal doesn't have element types in this simple implementation
108    }
109}