1package n
2
3import (
4 . "github.com/alecthomas/chroma" // nolint
5 "github.com/alecthomas/chroma/lexers/internal"
6)
7
8// Nginx Configuration File lexer.
9var Nginx = internal.Register(MustNewLexer(
10 &Config{
11 Name: "Nginx configuration file",
12 Aliases: []string{"nginx"},
13 Filenames: []string{"nginx.conf"},
14 MimeTypes: []string{"text/x-nginx-conf"},
15 },
16 Rules{
17 "root": {
18 {`(include)(\s+)([^\s;]+)`, ByGroups(Keyword, Text, Name), nil},
19 {`[^\s;#]+`, Keyword, Push("stmt")},
20 Include("base"),
21 },
22 "block": {
23 {`\}`, Punctuation, Pop(2)},
24 {`[^\s;#]+`, KeywordNamespace, Push("stmt")},
25 Include("base"),
26 },
27 "stmt": {
28 {`\{`, Punctuation, Push("block")},
29 {`;`, Punctuation, Pop(1)},
30 Include("base"),
31 },
32 "base": {
33 {`#.*\n`, CommentSingle, nil},
34 {`on|off`, NameConstant, nil},
35 {`\$[^\s;#()]+`, NameVariable, nil},
36 {`([a-z0-9.-]+)(:)([0-9]+)`, ByGroups(Name, Punctuation, LiteralNumberInteger), nil},
37 {`[a-z-]+/[a-z-+]+`, LiteralString, nil},
38 {`[0-9]+[km]?\b`, LiteralNumberInteger, nil},
39 {`(~)(\s*)([^\s{]+)`, ByGroups(Punctuation, Text, LiteralStringRegex), nil},
40 {`[:=~]`, Punctuation, nil},
41 {`[^\s;#{}$]+`, LiteralString, nil},
42 {`/[^\s;#]*`, Name, nil},
43 {`\s+`, Text, nil},
44 {`[$;]`, Text, nil},
45 },
46 },
47))