oak_handlebars/lexer/token_type.rs
1use oak_core::{Token, TokenType, UniversalTokenRole};
2#[cfg(feature = "serde")]
3use serde::{Deserialize, Serialize};
4
5/// Handlebars token.
6pub type _HandlebarsToken = Token<HandlebarsTokenType>;
7
8/// Handlebars token type definition.
9#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
10#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11pub enum HandlebarsTokenType {
12 // --- Tokens ---
13 /// Whitespace.
14 Whitespace,
15 /// Newline.
16 Newline,
17
18 /// Comment.
19 Comment,
20
21 // Handlebars specific tokens
22 /// `{{`.
23 Open,
24 /// `}}`.
25 Close,
26 /// `{{{`.
27 OpenUnescaped,
28 /// `}}}`.
29 CloseUnescaped,
30 /// `{{{{`.
31 OpenRawBlock,
32 /// `}}}}`.
33 CloseRawBlock,
34 /// `{{{{/`.
35 OpenEndRawBlock,
36 /// `{{#`.
37 OpenBlock,
38 /// `{{^`.
39 OpenInverseBlock,
40 /// `{{/`.
41 CloseBlock,
42 /// `{{>`.
43 OpenPartial,
44 /// `{{!`.
45 OpenComment,
46 /// `{{!--`.
47 OpenCommentBlock,
48 /// `--}}`.
49 CloseCommentBlock,
50
51 // Keywords
52 /// `else` keyword.
53 Else,
54
55 // Identifiers and literals
56 /// Identifier.
57 Identifier,
58 /// String literal.
59 StringLiteral,
60 /// Number literal.
61 NumberLiteral,
62 /// Boolean literal.
63 BooleanLiteral,
64 /// `.` symbol.
65 Dot,
66 /// `/` symbol.
67 Slash,
68 /// `#` symbol.
69 Hash,
70 /// `@` symbol.
71 At,
72 /// `|` symbol.
73 Pipe,
74 /// `=` symbol.
75 Equal,
76 /// `(` symbol.
77 LeftParen,
78 /// `)` symbol.
79 RightParen,
80 /// `[` symbol.
81 LeftBracket,
82 /// `]` symbol.
83 RightBracket,
84 /// `^` symbol.
85 Caret,
86
87 // Content
88 /// HTML/text content.
89 Content,
90
91 // --- Elements ---
92 /// Root node.
93 Root,
94 /// Mustache expression.
95 Mustache,
96 /// Block expression.
97 Block,
98 /// Inverse block expression.
99 InverseBlock,
100 /// Partial template reference.
101 Partial,
102 /// Comment node.
103 CommentNode,
104 /// Content node.
105 ContentNode,
106 /// Expression node.
107 Expression,
108 /// Path node.
109 Path,
110 /// Parameter node.
111 Parameter,
112 /// Else block.
113 ElseBlock,
114
115 // --- Special ---
116 /// Error.
117 Error,
118 /// End of stream.
119 Eof,
120}
121
122impl TokenType for HandlebarsTokenType {
123 type Role = UniversalTokenRole;
124 const END_OF_STREAM: Self = Self::Error;
125
126 fn is_ignored(&self) -> bool {
127 false
128 }
129
130 fn role(&self) -> Self::Role {
131 match self {
132 _ => UniversalTokenRole::None,
133 }
134 }
135}