oak_xml/kind/
mod.rs

1use oak_core::SyntaxKind;
2use serde::{Deserialize, Serialize};
3
4#[derive(Copy, Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
5pub enum XmlSyntaxKind {
6    // 基本 kind
7    Whitespace,
8    Newline,
9    Comment,
10    Text,
11    Error,
12    Eof,
13
14    // XML 特定
15    XmlDeclaration,
16    DoctypeDeclaration,
17    ProcessingInstruction,
18    CData,
19
20    // 标签
21    StartTag,
22    EndTag,
23    SelfClosingTag,
24    TagName,
25
26    AttributeName,
27    AttributeValue,
28
29    // 字面量
30    StringLiteral,
31
32    // 标点符号
33    LeftAngle,       // <
34    RightAngle,      // >
35    LeftAngleSlash,  // </
36    SlashRightAngle, // />
37    Equals,          // =
38    Quote,           // "
39    SingleQuote,     // '
40    Exclamation,     // !
41    Question,        // ?
42    Ampersand,       // &
43    Semicolon,       // ;
44
45    // 实体引用
46    EntityReference,
47    CharacterReference,
48
49    // 标识符
50    Identifier,
51}
52
53impl SyntaxKind for XmlSyntaxKind {
54    fn is_trivia(&self) -> bool {
55        matches!(self, Self::Whitespace | Self::Newline | Self::Comment)
56    }
57
58    fn is_comment(&self) -> bool {
59        matches!(self, Self::Comment)
60    }
61
62    fn is_whitespace(&self) -> bool {
63        matches!(self, Self::Whitespace | Self::Newline)
64    }
65
66    fn is_token_type(&self) -> bool {
67        !matches!(self, Self::XmlDeclaration | Self::DoctypeDeclaration | Self::StartTag | Self::EndTag | Self::SelfClosingTag)
68    }
69
70    fn is_element_type(&self) -> bool {
71        matches!(self, Self::XmlDeclaration | Self::DoctypeDeclaration | Self::StartTag | Self::EndTag | Self::SelfClosingTag)
72    }
73}