1use oak_core::{SyntaxKind, Token};
2use serde::{Deserialize, Serialize};
3
4pub type DjangoToken = Token<DjangoSyntaxKind>;
5
6#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
8pub enum DjangoSyntaxKind {
9 Identifier,
11 Number,
12 String,
13 Whitespace,
14 Newline,
15
16 VariableStart, VariableEnd, TagStart, TagEnd, CommentStart, CommentEnd, If,
26 Elif,
27 Else,
28 Endif,
29 For,
30 Empty,
31 Endfor,
32 Block,
33 Endblock,
34 Extends,
35 Include,
36 Load,
37 With,
38 Endwith,
39 Autoescape,
40 Endautoescape,
41 Csrf,
42 Url,
43 Static,
44 Now,
45 Cycle,
46 Filter,
47 Endfilter,
48 Spaceless,
49 Endspaceless,
50 Verbatim,
51 Endverbatim,
52
53 Pipe, Colon, Dot, Comma, Equal, Plus, Minus, Star, Slash, Percent, EqualEqual, NotEqual, Less, LessEqual, Greater, GreaterEqual, And,
75 Or,
76 Not,
77 In,
78
79 LeftParen, RightParen, LeftBracket, RightBracket, Semicolon, HtmlText,
88 HtmlTag,
89
90 Comment,
92
93 Root,
95 Error,
96 Eof,
97}
98
99impl DjangoSyntaxKind {
100 pub fn is_keyword(&self) -> bool {
101 matches!(
102 self,
103 Self::If
104 | Self::Elif
105 | Self::Else
106 | Self::Endif
107 | Self::For
108 | Self::Empty
109 | Self::Endfor
110 | Self::Block
111 | Self::Endblock
112 | Self::Extends
113 | Self::Include
114 | Self::Load
115 | Self::With
116 | Self::Endwith
117 | Self::Autoescape
118 | Self::Endautoescape
119 | Self::Csrf
120 | Self::Url
121 | Self::Static
122 | Self::Now
123 | Self::Cycle
124 | Self::Filter
125 | Self::Endfilter
126 | Self::Spaceless
127 | Self::Endspaceless
128 | Self::Verbatim
129 | Self::Endverbatim
130 | Self::And
131 | Self::Or
132 | Self::Not
133 | Self::In
134 )
135 }
136
137 pub fn is_trivia(&self) -> bool {
138 matches!(self, Self::Whitespace | Self::Newline | Self::Comment)
139 }
140}
141
142impl SyntaxKind for DjangoSyntaxKind {
143 fn is_trivia(&self) -> bool {
144 matches!(self, Self::Whitespace | Self::Newline | Self::Comment)
145 }
146
147 fn is_comment(&self) -> bool {
148 matches!(self, Self::Comment)
149 }
150
151 fn is_whitespace(&self) -> bool {
152 matches!(self, Self::Whitespace | Self::Newline)
153 }
154
155 fn is_token_type(&self) -> bool {
156 !matches!(self, Self::Error | Self::Eof)
157 }
158
159 fn is_element_type(&self) -> bool {
160 false
161 }
162}