1use oak_core::{ElementType, TokenType, UniversalElementRole, UniversalTokenRole};
2use serde::{Deserialize, Serialize};
3
4#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
5pub enum NginxSyntaxKind {
6 Root,
8 Directive,
9 Block,
10 Parameter,
11 Value,
12 Comment,
13
14 ServerKeyword, LocationKeyword, UpstreamKeyword, HttpKeyword, EventsKeyword, ListenKeyword, ServerNameKeyword, RootKeyword, IndexKeyword, ProxyPassKeyword, LeftBrace, RightBrace, Semicolon, Identifier,
33 String,
34 Number,
35 Path,
36 Url,
37
38 Whitespace,
40 Newline,
41 CommentToken,
42 Eof,
43 Error,
44}
45
46impl TokenType for NginxSyntaxKind {
47 const END_OF_STREAM: Self = Self::Eof;
48 type Role = UniversalTokenRole;
49
50 fn role(&self) -> Self::Role {
51 match self {
52 Self::Whitespace | Self::Newline => UniversalTokenRole::Whitespace,
53 Self::CommentToken | Self::Comment => UniversalTokenRole::Comment,
54 Self::Eof => UniversalTokenRole::Eof,
55 _ => UniversalTokenRole::None,
56 }
57 }
58
59 fn is_comment(&self) -> bool {
60 matches!(self, Self::CommentToken | Self::Comment)
61 }
62
63 fn is_whitespace(&self) -> bool {
64 matches!(self, Self::Whitespace | Self::Newline)
65 }
66}
67
68impl ElementType for NginxSyntaxKind {
69 type Role = UniversalElementRole;
70
71 fn role(&self) -> Self::Role {
72 match self {
73 Self::Error => UniversalElementRole::Error,
74 Self::Root => UniversalElementRole::Root,
75 Self::Directive | Self::Block => UniversalElementRole::Detail,
76 _ => UniversalElementRole::None,
77 }
78 }
79}
80
81impl NginxSyntaxKind {
82 pub fn is_element(&self) -> bool {
83 matches!(self, Self::Root | Self::Directive | Self::Block | Self::Parameter | Self::Value | Self::Comment)
84 }
85
86 pub fn is_token(&self) -> bool {
87 !self.is_element()
88 }
89}