1 package c
2
3 import (
4 . "github.com/alecthomas/chroma"
5 "github.com/alecthomas/chroma/lexers/internal"
6 )
7
8
9 func caddyfileCommonRules() Rules {
10 return Rules{
11 "site_block_common": {
12
13 {`(import)(\s+)([^\s]+)`, ByGroups(Keyword, Text, NameVariableMagic), nil},
14
15 {`@[^\s]+(?=\s)`, NameDecorator, Push("matcher")},
16
17 {`\[\<matcher\>\]`, NameDecorator, Push("matcher")},
18
19
20 {`try_files`, Keyword, Push("subdirective")},
21
22 {`handle_errors|handle|route|handle_path|not`, Keyword, Push("nested_directive")},
23
24 {`[^\s#]+`, Keyword, Push("directive")},
25 Include("base"),
26 },
27 "matcher": {
28 {`\{`, Punctuation, Push("block")},
29
30 {`not`, Keyword, Push("deep_not_matcher")},
31
32 {`[^\s#]+`, Keyword, Push("arguments")},
33
34 {`\n`, Text, Pop(1)},
35 {`\}`, Punctuation, Pop(1)},
36 Include("base"),
37 },
38 "block": {
39 {`\}`, Punctuation, Pop(2)},
40
41 {`not`, Keyword, Push("not_matcher")},
42
43 {`[^\s#]+`, Keyword, Push("subdirective")},
44 Include("base"),
45 },
46 "nested_block": {
47 {`\}`, Punctuation, Pop(2)},
48
49 {`@[^\s]+(?=\s)`, NameDecorator, Push("matcher")},
50
51 {`\<[^#]+\>`, Keyword, Push("nested_directive")},
52
53 {`[^\s#]+`, Keyword, Push("nested_directive")},
54 Include("base"),
55 },
56 "not_matcher": {
57 {`\}`, Punctuation, Pop(2)},
58 {`\{(?=\s)`, Punctuation, Push("block")},
59 {`[^\s#]+`, Keyword, Push("arguments")},
60 {`\s+`, Text, nil},
61 },
62 "deep_not_matcher": {
63 {`\}`, Punctuation, Pop(2)},
64 {`\{(?=\s)`, Punctuation, Push("block")},
65 {`[^\s#]+`, Keyword, Push("deep_subdirective")},
66 {`\s+`, Text, nil},
67 },
68 "directive": {
69 {`\{(?=\s)`, Punctuation, Push("block")},
70 Include("matcher_token"),
71 Include("comments_pop_1"),
72 {`\n`, Text, Pop(1)},
73 Include("base"),
74 },
75 "nested_directive": {
76 {`\{(?=\s)`, Punctuation, Push("nested_block")},
77 Include("matcher_token"),
78 Include("comments_pop_1"),
79 {`\n`, Text, Pop(1)},
80 Include("base"),
81 },
82 "subdirective": {
83 {`\{(?=\s)`, Punctuation, Push("block")},
84 Include("comments_pop_1"),
85 {`\n`, Text, Pop(1)},
86 Include("base"),
87 },
88 "arguments": {
89 {`\{(?=\s)`, Punctuation, Push("block")},
90 Include("comments_pop_2"),
91 {`\\\n`, Text, nil},
92 {`\n`, Text, Pop(2)},
93 Include("base"),
94 },
95 "deep_subdirective": {
96 {`\{(?=\s)`, Punctuation, Push("block")},
97 Include("comments_pop_3"),
98 {`\n`, Text, Pop(3)},
99 Include("base"),
100 },
101 "matcher_token": {
102 {`@[^\s]+`, NameDecorator, Push("arguments")},
103 {`/[^\s]+`, NameDecorator, Push("arguments")},
104 {`\*`, NameDecorator, Push("arguments")},
105 {`\[\<matcher\>\]`, NameDecorator, Push("arguments")},
106 },
107 "comments": {
108 {`^#.*\n`, CommentSingle, nil},
109 {`\s+#.*\n`, CommentSingle, nil},
110 },
111 "comments_pop_1": {
112 {`^#.*\n`, CommentSingle, Pop(1)},
113 {`\s+#.*\n`, CommentSingle, Pop(1)},
114 },
115 "comments_pop_2": {
116 {`^#.*\n`, CommentSingle, Pop(2)},
117 {`\s+#.*\n`, CommentSingle, Pop(2)},
118 },
119 "comments_pop_3": {
120 {`^#.*\n`, CommentSingle, Pop(3)},
121 {`\s+#.*\n`, CommentSingle, Pop(3)},
122 },
123 "base": {
124 Include("comments"),
125 {`(on|off|first|last|before|after|internal|strip_prefix|strip_suffix|replace)\b`, NameConstant, nil},
126 {`(https?://)?([a-z0-9.-]+)(:)([0-9]+)`, ByGroups(Name, Name, Punctuation, LiteralNumberInteger), nil},
127 {`[a-z-]+/[a-z-+]+`, LiteralString, nil},
128 {`[0-9]+[km]?\b`, LiteralNumberInteger, nil},
129 {`\{[\w+.\$-]+\}`, LiteralStringEscape, nil},
130 {`\[(?=[^#{}$]+\])`, Punctuation, nil},
131 {`\]|\|`, Punctuation, nil},
132 {`[^\s#{}$\]]+`, LiteralString, nil},
133 {`/[^\s#]*`, Name, nil},
134 {`\s+`, Text, nil},
135 },
136 }
137 }
138
139
140 var Caddyfile = internal.Register(MustNewLazyLexer(
141 &Config{
142 Name: "Caddyfile",
143 Aliases: []string{"caddyfile", "caddy"},
144 Filenames: []string{"Caddyfile*"},
145 MimeTypes: []string{},
146 },
147 caddyfileRules,
148 ))
149
150 func caddyfileRules() Rules {
151 return Rules{
152 "root": {
153 Include("comments"),
154
155 {`^\s*(\{)\s*$`, ByGroups(Punctuation), Push("globals")},
156
157 {`(\([^\s#]+\))(\s*)(\{)`, ByGroups(NameVariableAnonymous, Text, Punctuation), Push("snippet")},
158
159 {`[^#{(\s,]+`, GenericHeading, Push("label")},
160
161 {`\{[\w+.\$-]+\}`, LiteralStringEscape, Push("label")},
162 {`\s+`, Text, nil},
163 },
164 "globals": {
165 {`\}`, Punctuation, Pop(1)},
166 {`[^\s#]+`, Keyword, Push("directive")},
167 Include("base"),
168 },
169 "snippet": {
170 {`\}`, Punctuation, Pop(1)},
171
172 {`@[^\s]+(?=\s)`, NameDecorator, Push("matcher")},
173
174 {`[^\s#]+`, Keyword, Push("directive")},
175 Include("base"),
176 },
177 "label": {
178
179
180 {`,\s*\n?`, Text, nil},
181 {` `, Text, nil},
182
183 {`\{[\w+.\$-]+\}`, LiteralStringEscape, nil},
184
185 {`[^#{(\s,]+`, GenericHeading, nil},
186
187 {`#.*\n`, CommentSingle, Push("site_block")},
188
189 {`\{(?=\s)|\n`, Punctuation, Push("site_block")},
190 },
191 "site_block": {
192 {`\}`, Punctuation, Pop(2)},
193 Include("site_block_common"),
194 },
195 }.Merge(caddyfileCommonRules())
196 }
197
198
199 var CaddyfileDirectives = internal.Register(MustNewLazyLexer(
200 &Config{
201 Name: "Caddyfile Directives",
202 Aliases: []string{"caddyfile-directives", "caddyfile-d", "caddy-d"},
203 Filenames: []string{},
204 MimeTypes: []string{},
205 },
206 caddyfileDirectivesRules,
207 ))
208
209 func caddyfileDirectivesRules() Rules {
210 return Rules{
211
212 "root": {
213 Include("site_block_common"),
214 },
215 }.Merge(caddyfileCommonRules())
216 }
217
View as plain text