Skip to main content

oak_xml/lexer/
token_type.rs

1use oak_core::{Source, Token, TokenType, UniversalElementRole, UniversalTokenRole};
2#[cfg(feature = "serde")]
3use serde::{Deserialize, Serialize};
4
5pub type XmlToken = Token<XmlTokenType>;
6
7impl TokenType for XmlTokenType {
8    type Role = UniversalTokenRole;
9    const END_OF_STREAM: Self = Self::Error;
10
11    fn is_ignored(&self) -> bool {
12        false
13    }
14
15    fn role(&self) -> Self::Role {
16        match self {
17            _ => UniversalTokenRole::None,
18        }
19    }
20}
21
22#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
23#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
24pub enum XmlTokenType {
25    // 基本 kind
26    Root,
27    Whitespace,
28    Newline,
29    Comment,
30    Text,
31    Error,
32    Eof,
33
34    // XML 特定
35    XmlDeclaration,
36    DoctypeDeclaration,
37    ProcessingInstruction,
38    CData,
39
40    // 标签
41    StartTag,
42    EndTag,
43    SelfClosingTag,
44    TagName,
45
46    AttributeName,
47    AttributeValue,
48
49    // 字面量
50    StringLiteral,
51
52    // 标点符号
53    LeftAngle,       // <
54    RightAngle,      // >
55    LeftAngleSlash,  // </
56    SlashRightAngle, // />
57    Equals,          // =
58    Quote,           // "
59    SingleQuote,     // '
60    Exclamation,     // !
61    Question,        // ?
62    Ampersand,       // &
63    Semicolon,       // ;
64
65    // 实体引用
66    EntityReference,
67    CharacterReference,
68
69    // 标识符
70    Identifier,
71
72    // 非终结符
73    SourceFile,
74    Element,
75    Attribute,
76    Prolog,
77}