oak_nginx/kind/
mod.rs

1use oak_core::SyntaxKind;
2use serde::{Deserialize, Serialize};
3
4#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
5pub enum NginxSyntaxKind {
6    // 节点种类
7    Root,
8    Directive,
9    Block,
10    Parameter,
11    Value,
12    Comment,
13
14    // 词法种类 - 关键字
15    ServerKeyword,     // server
16    LocationKeyword,   // location
17    UpstreamKeyword,   // upstream
18    HttpKeyword,       // http
19    EventsKeyword,     // events
20    ListenKeyword,     // listen
21    ServerNameKeyword, // server_name
22    RootKeyword,       // root
23    IndexKeyword,      // index
24    ProxyPassKeyword,  // proxy_pass
25
26    // 词法种类 - 符号
27    LeftBrace,  // {
28    RightBrace, // }
29    Semicolon,  // ;
30
31    // 词法种类 - 字面量
32    Identifier,
33    String,
34    Number,
35    Path,
36    Url,
37
38    // 词法种类 - 其他
39    Whitespace,
40    Newline,
41    CommentToken,
42    Eof,
43    Error,
44}
45
46impl SyntaxKind for NginxSyntaxKind {
47    fn is_trivia(&self) -> bool {
48        matches!(self, Self::Whitespace | Self::Newline | Self::CommentToken)
49    }
50
51    fn is_comment(&self) -> bool {
52        matches!(self, Self::CommentToken)
53    }
54
55    fn is_whitespace(&self) -> bool {
56        matches!(self, Self::Whitespace | Self::Newline)
57    }
58
59    fn is_token_type(&self) -> bool {
60        !matches!(self, Self::Root | Self::Directive | Self::Block | Self::Parameter | Self::Value | Self::Comment)
61    }
62
63    fn is_element_type(&self) -> bool {
64        matches!(self, Self::Root | Self::Directive | Self::Block | Self::Parameter | Self::Value | Self::Comment)
65    }
66}