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