Skip to main content

oak_xml/lexer/
token_type.rs

1use oak_core::{Token, TokenType, UniversalTokenRole};
2
3/// A token in the XML language.
4pub type XmlToken = Token<XmlTokenType>;
5
6impl TokenType for XmlTokenType {
7    type Role = UniversalTokenRole;
8    const END_OF_STREAM: Self = Self::Error;
9
10    fn is_ignored(&self) -> bool {
11        false
12    }
13
14    fn role(&self) -> Self::Role {
15        match self {
16            _ => UniversalTokenRole::None,
17        }
18    }
19}
20
21/// XML token types.
22#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
23#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
24pub enum XmlTokenType {
25    /// Root element.
26    Root,
27    /// Whitespace characters.
28    Whitespace,
29    /// Newline character.
30    Newline,
31    /// Comment.
32    Comment,
33    /// Text content.
34    Text,
35    /// Error token.
36    Error,
37    /// End of file.
38    Eof,
39
40    /// XML declaration.
41    XmlDeclaration,
42    /// Document type declaration.
43    DoctypeDeclaration,
44    /// Processing instruction.
45    ProcessingInstruction,
46    /// CDATA section.
47    CData,
48
49    /// Start tag.
50    StartTag,
51    /// End tag.
52    EndTag,
53    /// Self-closing tag.
54    SelfClosingTag,
55    /// Tag name.
56    TagName,
57
58    /// Attribute name.
59    AttributeName,
60    /// Attribute value.
61    AttributeValue,
62
63    /// String literal.
64    StringLiteral,
65
66    /// `<` operator.
67    LeftAngle,
68    /// `>` operator.
69    RightAngle,
70    /// `</` operator.
71    LeftAngleSlash,
72    /// `/>` operator.
73    SlashRightAngle,
74    /// `=` operator.
75    Equals,
76    /// `"` quote.
77    Quote,
78    /// `'` single quote.
79    SingleQuote,
80    /// `!` exclamation.
81    Exclamation,
82    /// `?` question.
83    Question,
84    /// `&` ampersand.
85    Ampersand,
86    /// `;` semicolon.
87    Semicolon,
88
89    /// Entity reference.
90    EntityReference,
91    /// Character reference.
92    CharacterReference,
93
94    /// Identifier.
95    Identifier,
96
97    /// Source file non-terminal.
98    SourceFile,
99    /// Element non-terminal.
100    Element,
101    /// Attribute non-terminal.
102    Attribute,
103    /// Prolog non-terminal.
104    Prolog,
105}