oak_dockerfile/kind/
mod.rs

1pub type DockerfileToken = Token<DockerfileSyntaxKind>;
2
3/// Dockerfile 语法种类
4#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, serde::Serialize)]
5pub enum DockerfileSyntaxKind {
6    // 基本 kind
7    Identifier,
8    String,
9    Number,
10    Whitespace,
11    Newline,
12
13    // Dockerfile 指令
14    From,
15    Run,
16    Cmd,
17    Label,
18    Maintainer,
19    Expose,
20    Env,
21    Add,
22    Copy,
23    Entrypoint,
24    Volume,
25    User,
26    Workdir,
27    Arg,
28    Onbuild,
29    Stopsignal,
30    Healthcheck,
31    Shell,
32
33    // 特殊关键
34    As,
35    None,
36    Interval,
37    Timeout,
38    StartPeriod,
39    Retries,
40
41    // 操作符和分隔符
42    Equal,        // = (保持向后兼容)
43    Equals,       // = (新名称)
44    Colon,        // :
45    Comma,        // ,
46    Semicolon,    // ;
47    Dollar,       // $
48    LeftBracket,  // [
49    RightBracket, // ]
50    LeftBrace,    // {
51    RightBrace,   // }
52    LeftParen,    // (
53    RightParen,   // )
54
55    // 注释
56    Comment,
57
58    // 路径和文件名
59    Path,
60
61    // 特殊
62    Error,
63    Eof,
64}
65
66impl DockerfileSyntaxKind {
67    pub fn is_instruction(&self) -> bool {
68        matches!(
69            self,
70            Self::From
71                | Self::Run
72                | Self::Cmd
73                | Self::Label
74                | Self::Maintainer
75                | Self::Expose
76                | Self::Env
77                | Self::Add
78                | Self::Copy
79                | Self::Entrypoint
80                | Self::Volume
81                | Self::User
82                | Self::Workdir
83                | Self::Arg
84                | Self::Onbuild
85                | Self::Stopsignal
86                | Self::Healthcheck
87                | Self::Shell
88        )
89    }
90
91    pub fn is_trivia(&self) -> bool {
92        matches!(self, Self::Whitespace | Self::Newline | Self::Comment)
93    }
94}
95
96use oak_core::{SyntaxKind, Token};
97
98impl SyntaxKind for DockerfileSyntaxKind {
99    fn is_trivia(&self) -> bool {
100        matches!(self, Self::Whitespace | Self::Newline | Self::Comment)
101    }
102
103    fn is_comment(&self) -> bool {
104        matches!(self, Self::Comment)
105    }
106
107    fn is_whitespace(&self) -> bool {
108        matches!(self, Self::Whitespace | Self::Newline)
109    }
110
111    fn is_token_type(&self) -> bool {
112        !matches!(self, Self::Error | Self::Eof)
113    }
114
115    fn is_element_type(&self) -> bool {
116        matches!(self, Self::Error | Self::Eof)
117    }
118}