66
|
1 package lexers
|
|
2
|
|
3 import (
|
|
4 . "github.com/alecthomas/chroma/v2" // nolint
|
|
5 )
|
|
6
|
|
7 // Docker lexer.
|
|
8 var Docker = Register(MustNewLexer(
|
|
9 &Config{
|
|
10 Name: "Docker",
|
|
11 Aliases: []string{"docker", "dockerfile"},
|
|
12 Filenames: []string{"Dockerfile", "Dockerfile.*", "*.docker"},
|
|
13 MimeTypes: []string{"text/x-dockerfile-config"},
|
|
14 CaseInsensitive: true,
|
|
15 },
|
|
16 dockerRules,
|
|
17 ))
|
|
18
|
|
19 func dockerRules() Rules {
|
|
20 return Rules{
|
|
21 "root": {
|
|
22 {`#.*`, Comment, nil},
|
|
23 {`(ONBUILD)((?:\s*\\?\s*))`, ByGroups(Keyword, Using("Bash")), nil},
|
|
24 {`(HEALTHCHECK)(((?:\s*\\?\s*)--\w+=\w+(?:\s*\\?\s*))*)`, ByGroups(Keyword, Using("Bash")), nil},
|
|
25 {`(VOLUME|ENTRYPOINT|CMD|SHELL)((?:\s*\\?\s*))(\[.*?\])`, ByGroups(Keyword, Using("Bash"), Using("JSON")), nil},
|
|
26 {`(LABEL|ENV|ARG)((?:(?:\s*\\?\s*)\w+=\w+(?:\s*\\?\s*))*)`, ByGroups(Keyword, Using("Bash")), nil},
|
|
27 {`((?:FROM|MAINTAINER|EXPOSE|WORKDIR|USER|STOPSIGNAL)|VOLUME)\b(.*)`, ByGroups(Keyword, LiteralString), nil},
|
|
28 {`((?:RUN|CMD|ENTRYPOINT|ENV|ARG|LABEL|ADD|COPY))`, Keyword, nil},
|
|
29 {`(.*\\\n)*.+`, Using("Bash"), nil},
|
|
30 },
|
|
31 }
|
|
32 }
|