Mercurial > vim
annotate runtime/syntax/go.vim @ 34906:cb75f6489b63
runtime(go): fix highlighting import string followed by some comment (#14538)
Commit: https://github.com/vim/vim/commit/122d068585686babd63f0b729759ec269171d464
Author: Linda_pp <rhysd@users.noreply.github.com>
Date: Sun Apr 14 00:56:17 2024 +0900
runtime(go): fix highlighting import string followed by some comment (https://github.com/vim/vim/issues/14538)
Signed-off-by: rhysd <lin90162@yahoo.co.jp>
Signed-off-by: Christian Brabandt <cb@256bit.org>
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sat, 13 Apr 2024 18:00:07 +0200 |
parents | deee52c162df |
children |
rev | line source |
---|---|
25161 | 1 " Copyright 2009 The Go Authors. All rights reserved. |
2 " Use of this source code is governed by a BSD-style | |
3 " license that can be found in the LICENSE file. | |
6153 | 4 " |
25161 | 5 " go.vim: Vim syntax file for Go. |
6 " Language: Go | |
7 " Maintainer: Billie Cleek <bhcleek@gmail.com> | |
34906
cb75f6489b63
runtime(go): fix highlighting import string followed by some comment (#14538)
Christian Brabandt <cb@256bit.org>
parents:
34578
diff
changeset
|
8 " Latest Revision: 2024-04-13 |
34578
deee52c162df
runtime(go): `goPackageComment` highlighting too broad
Christian Brabandt <cb@256bit.org>
parents:
34172
diff
changeset
|
9 " 2024-03-17: - fix goPackageComment highlight (by Vim Project) |
25161 | 10 " License: BSD-style. See LICENSE file in source repository. |
11 " Repository: https://github.com/fatih/vim-go | |
6153 | 12 |
13 " Quit when a (custom) syntax file was already loaded | |
25161 | 14 if exists("b:current_syntax") |
6153 | 15 finish |
16 endif | |
17 | |
25161 | 18 let s:keepcpo = &cpo |
19 set cpo&vim | |
20 | |
21 function! s:FoldEnable(...) abort | |
22 if a:0 > 0 | |
23 return index(s:FoldEnable(), a:1) > -1 | |
24 endif | |
25 return get(g:, 'go_fold_enable', ['block', 'import', 'varconst', 'package_comment']) | |
26 endfunction | |
27 | |
28 function! s:HighlightArrayWhitespaceError() abort | |
29 return get(g:, 'go_highlight_array_whitespace_error', 0) | |
30 endfunction | |
31 | |
32 function! s:HighlightChanWhitespaceError() abort | |
33 return get(g:, 'go_highlight_chan_whitespace_error', 0) | |
34 endfunction | |
35 | |
36 function! s:HighlightExtraTypes() abort | |
37 return get(g:, 'go_highlight_extra_types', 0) | |
38 endfunction | |
39 | |
40 function! s:HighlightSpaceTabError() abort | |
41 return get(g:, 'go_highlight_space_tab_error', 0) | |
42 endfunction | |
43 | |
44 function! s:HighlightTrailingWhitespaceError() abort | |
45 return get(g:, 'go_highlight_trailing_whitespace_error', 0) | |
46 endfunction | |
47 | |
48 function! s:HighlightOperators() abort | |
49 return get(g:, 'go_highlight_operators', 0) | |
50 endfunction | |
51 | |
52 function! s:HighlightFunctions() abort | |
53 return get(g:, 'go_highlight_functions', 0) | |
54 endfunction | |
55 | |
56 function! s:HighlightFunctionParameters() abort | |
57 return get(g:, 'go_highlight_function_parameters', 0) | |
58 endfunction | |
59 | |
60 function! s:HighlightFunctionCalls() abort | |
61 return get(g:, 'go_highlight_function_calls', 0) | |
62 endfunction | |
63 | |
64 function! s:HighlightFields() abort | |
65 return get(g:, 'go_highlight_fields', 0) | |
66 endfunction | |
67 | |
68 function! s:HighlightTypes() abort | |
69 return get(g:, 'go_highlight_types', 0) | |
70 endfunction | |
71 | |
72 function! s:HighlightBuildConstraints() abort | |
73 return get(g:, 'go_highlight_build_constraints', 0) | |
74 endfunction | |
75 | |
76 function! s:HighlightStringSpellcheck() abort | |
77 return get(g:, 'go_highlight_string_spellcheck', 1) | |
78 endfunction | |
79 | |
80 function! s:HighlightFormatStrings() abort | |
81 return get(g:, 'go_highlight_format_strings', 1) | |
82 endfunction | |
83 | |
84 function! s:HighlightGenerateTags() abort | |
85 return get(g:, 'go_highlight_generate_tags', 0) | |
86 endfunction | |
87 | |
88 function! s:HighlightVariableAssignments() abort | |
89 return get(g:, 'go_highlight_variable_assignments', 0) | |
90 endfunction | |
91 | |
92 function! s:HighlightVariableDeclarations() abort | |
93 return get(g:, 'go_highlight_variable_declarations', 0) | |
94 endfunction | |
6153 | 95 |
96 syn case match | |
97 | |
25161 | 98 syn keyword goPackage package |
99 syn keyword goImport import contained | |
100 syn keyword goVar var contained | |
101 syn keyword goConst const contained | |
6153 | 102 |
25161 | 103 hi def link goPackage Statement |
104 hi def link goImport Statement | |
105 hi def link goVar Keyword | |
106 hi def link goConst Keyword | |
6153 | 107 hi def link goDeclaration Keyword |
108 | |
109 " Keywords within functions | |
110 syn keyword goStatement defer go goto return break continue fallthrough | |
111 syn keyword goConditional if else switch select | |
112 syn keyword goLabel case default | |
113 syn keyword goRepeat for range | |
114 | |
115 hi def link goStatement Statement | |
116 hi def link goConditional Conditional | |
117 hi def link goLabel Label | |
118 hi def link goRepeat Repeat | |
119 | |
120 " Predefined types | |
31139 | 121 syn keyword goType chan map bool string error any comparable |
6153 | 122 syn keyword goSignedInts int int8 int16 int32 int64 rune |
123 syn keyword goUnsignedInts byte uint uint8 uint16 uint32 uint64 uintptr | |
124 syn keyword goFloats float32 float64 | |
125 syn keyword goComplexes complex64 complex128 | |
126 | |
127 hi def link goType Type | |
128 hi def link goSignedInts Type | |
129 hi def link goUnsignedInts Type | |
130 hi def link goFloats Type | |
131 hi def link goComplexes Type | |
132 | |
25161 | 133 " Predefined functions and values |
32957
a5bd10de6c37
runtime(go): Update Go syntax file with 1.21 builtins (#12876)
Christian Brabandt <cb@256bit.org>
parents:
32004
diff
changeset
|
134 syn keyword goBuiltins append cap clear close complex copy delete imag len |
a5bd10de6c37
runtime(go): Update Go syntax file with 1.21 builtins (#12876)
Christian Brabandt <cb@256bit.org>
parents:
32004
diff
changeset
|
135 syn keyword goBuiltins make max min new panic print println real recover |
25161 | 136 syn keyword goBoolean true false |
137 syn keyword goPredefinedIdentifiers nil iota | |
6153 | 138 |
25161 | 139 hi def link goBuiltins Identifier |
32004 | 140 hi def link goPredefinedIdentifiers Constant |
141 " Boolean links to Constant by default by vim: goBoolean and goPredefinedIdentifiers | |
142 " will be highlighted the same, but having the separate groups allows users to | |
143 " have separate highlighting for them if they desire. | |
25161 | 144 hi def link goBoolean Boolean |
6153 | 145 |
146 " Comments; their contents | |
147 syn keyword goTodo contained TODO FIXME XXX BUG | |
148 syn cluster goCommentGroup contains=goTodo | |
25161 | 149 |
150 syn region goComment start="//" end="$" contains=goGenerate,@goCommentGroup,@Spell | |
151 if s:FoldEnable('comment') | |
152 syn region goComment start="/\*" end="\*/" contains=@goCommentGroup,@Spell fold | |
153 syn match goComment "\v(^\s*//.*\n)+" contains=goGenerate,@goCommentGroup,@Spell fold | |
154 else | |
155 syn region goComment start="/\*" end="\*/" contains=@goCommentGroup,@Spell | |
156 endif | |
6153 | 157 |
158 hi def link goComment Comment | |
159 hi def link goTodo Todo | |
160 | |
25161 | 161 if s:HighlightGenerateTags() |
162 syn match goGenerateVariables contained /\%(\$GOARCH\|\$GOOS\|\$GOFILE\|\$GOLINE\|\$GOPACKAGE\|\$DOLLAR\)\>/ | |
163 syn region goGenerate start="^\s*//go:generate" end="$" contains=goGenerateVariables | |
164 hi def link goGenerate PreProc | |
165 hi def link goGenerateVariables Special | |
166 endif | |
167 | |
6153 | 168 " Go escapes |
169 syn match goEscapeOctal display contained "\\[0-7]\{3}" | |
170 syn match goEscapeC display contained +\\[abfnrtv\\'"]+ | |
171 syn match goEscapeX display contained "\\x\x\{2}" | |
172 syn match goEscapeU display contained "\\u\x\{4}" | |
173 syn match goEscapeBigU display contained "\\U\x\{8}" | |
174 syn match goEscapeError display contained +\\[^0-7xuUabfnrtv\\'"]+ | |
175 | |
176 hi def link goEscapeOctal goSpecialString | |
177 hi def link goEscapeC goSpecialString | |
178 hi def link goEscapeX goSpecialString | |
179 hi def link goEscapeU goSpecialString | |
180 hi def link goEscapeBigU goSpecialString | |
181 hi def link goSpecialString Special | |
182 hi def link goEscapeError Error | |
183 | |
184 " Strings and their contents | |
185 syn cluster goStringGroup contains=goEscapeOctal,goEscapeC,goEscapeX,goEscapeU,goEscapeBigU,goEscapeError | |
25161 | 186 if s:HighlightStringSpellcheck() |
187 syn region goString start=+"+ skip=+\\\\\|\\"+ end=+"+ contains=@goStringGroup,@Spell | |
188 syn region goRawString start=+`+ end=+`+ contains=@Spell | |
189 else | |
190 syn region goString start=+"+ skip=+\\\\\|\\"+ end=+"+ contains=@goStringGroup | |
191 syn region goRawString start=+`+ end=+`+ | |
192 endif | |
193 | |
34906
cb75f6489b63
runtime(go): fix highlighting import string followed by some comment (#14538)
Christian Brabandt <cb@256bit.org>
parents:
34578
diff
changeset
|
194 syn match goImportString /^\%(\s\+\|import \)\(\h\w* \)\?\zs"[^"]\+"/ contained containedin=goImport |
31139 | 195 |
25161 | 196 if s:HighlightFormatStrings() |
197 " [n] notation is valid for specifying explicit argument indexes | |
198 " 1. Match a literal % not preceded by a %. | |
199 " 2. Match any number of -, #, 0, space, or + | |
200 " 3. Match * or [n]* or any number or nothing before a . | |
201 " 4. Match * or [n]* or any number or nothing after a . | |
202 " 5. Match [n] or nothing before a verb | |
203 " 6. Match a formatting verb | |
204 syn match goFormatSpecifier /\ | |
205 \%([^%]\%(%%\)*\)\ | |
206 \@<=%[-#0 +]*\ | |
207 \%(\%(\%(\[\d\+\]\)\=\*\)\|\d\+\)\=\ | |
208 \%(\.\%(\%(\%(\[\d\+\]\)\=\*\)\|\d\+\)\=\)\=\ | |
209 \%(\[\d\+\]\)\=[vTtbcdoqxXUeEfFgGspw]/ contained containedin=goString,goRawString | |
210 hi def link goFormatSpecifier goSpecialString | |
211 endif | |
6153 | 212 |
31139 | 213 hi def link goImportString String |
6153 | 214 hi def link goString String |
215 hi def link goRawString String | |
216 | |
217 " Characters; their contents | |
218 syn cluster goCharacterGroup contains=goEscapeOctal,goEscapeC,goEscapeX,goEscapeU,goEscapeBigU | |
219 syn region goCharacter start=+'+ skip=+\\\\\|\\'+ end=+'+ contains=@goCharacterGroup | |
220 | |
221 hi def link goCharacter Character | |
222 | |
223 " Regions | |
224 syn region goParen start='(' end=')' transparent | |
25161 | 225 if s:FoldEnable('block') |
226 syn region goBlock start="{" end="}" transparent fold | |
227 else | |
228 syn region goBlock start="{" end="}" transparent | |
229 endif | |
230 | |
231 " import | |
232 if s:FoldEnable('import') | |
31139 | 233 syn region goImport start='import (' end=')' transparent fold contains=goImport,goImportString,goComment |
34172
176821d2ea8a
runtime(go): update Go syntax file (#13896)
Christian Brabandt <cb@256bit.org>
parents:
32957
diff
changeset
|
234 syn match goImport /^import ()/ transparent fold contains=goImport |
25161 | 235 else |
31139 | 236 syn region goImport start='import (' end=')' transparent contains=goImport,goImportString,goComment |
34172
176821d2ea8a
runtime(go): update Go syntax file (#13896)
Christian Brabandt <cb@256bit.org>
parents:
32957
diff
changeset
|
237 syn match goImport /^import ()/ transparent contains=goImport |
25161 | 238 endif |
239 | |
240 " var, const | |
241 if s:FoldEnable('varconst') | |
242 syn region goVar start='var (' end='^\s*)$' transparent fold | |
34172
176821d2ea8a
runtime(go): update Go syntax file (#13896)
Christian Brabandt <cb@256bit.org>
parents:
32957
diff
changeset
|
243 \ contains=ALLBUT,goParen,goBlock,goFunction,goTypeName,goReceiverType,goReceiverVar,goParamName,goParamType,goSimpleParams,goPointerOperator |
176821d2ea8a
runtime(go): update Go syntax file (#13896)
Christian Brabandt <cb@256bit.org>
parents:
32957
diff
changeset
|
244 syn match goVar /var ()/ transparent fold |
176821d2ea8a
runtime(go): update Go syntax file (#13896)
Christian Brabandt <cb@256bit.org>
parents:
32957
diff
changeset
|
245 \ contains=goVar |
25161 | 246 syn region goConst start='const (' end='^\s*)$' transparent fold |
34172
176821d2ea8a
runtime(go): update Go syntax file (#13896)
Christian Brabandt <cb@256bit.org>
parents:
32957
diff
changeset
|
247 \ contains=ALLBUT,goParen,goBlock,goFunction,goTypeName,goReceiverType,goReceiverVar,goParamName,goParamType,goSimpleParams,goPointerOperator |
176821d2ea8a
runtime(go): update Go syntax file (#13896)
Christian Brabandt <cb@256bit.org>
parents:
32957
diff
changeset
|
248 syn match goConst /const ()/ transparent fold |
176821d2ea8a
runtime(go): update Go syntax file (#13896)
Christian Brabandt <cb@256bit.org>
parents:
32957
diff
changeset
|
249 \ contains=goConst |
25161 | 250 else |
251 syn region goVar start='var (' end='^\s*)$' transparent | |
34172
176821d2ea8a
runtime(go): update Go syntax file (#13896)
Christian Brabandt <cb@256bit.org>
parents:
32957
diff
changeset
|
252 \ contains=ALLBUT,goParen,goBlock,goFunction,goTypeName,goReceiverType,goReceiverVar,goParamName,goParamType,goSimpleParams,goPointerOperator |
176821d2ea8a
runtime(go): update Go syntax file (#13896)
Christian Brabandt <cb@256bit.org>
parents:
32957
diff
changeset
|
253 syn match goVar /var ()/ transparent |
176821d2ea8a
runtime(go): update Go syntax file (#13896)
Christian Brabandt <cb@256bit.org>
parents:
32957
diff
changeset
|
254 \ contains=goVar |
25161 | 255 syn region goConst start='const (' end='^\s*)$' transparent |
34172
176821d2ea8a
runtime(go): update Go syntax file (#13896)
Christian Brabandt <cb@256bit.org>
parents:
32957
diff
changeset
|
256 \ contains=ALLBUT,goParen,goBlock,goFunction,goTypeName,goReceiverType,goReceiverVar,goParamName,goParamType,goSimpleParams,goPointerOperator |
176821d2ea8a
runtime(go): update Go syntax file (#13896)
Christian Brabandt <cb@256bit.org>
parents:
32957
diff
changeset
|
257 syn match goConst /const ()/ transparent |
176821d2ea8a
runtime(go): update Go syntax file (#13896)
Christian Brabandt <cb@256bit.org>
parents:
32957
diff
changeset
|
258 \ contains=goConst |
25161 | 259 endif |
260 | |
261 " Single-line var, const, and import. | |
262 syn match goSingleDecl /\%(import\|var\|const\) [^(]\@=/ contains=goImport,goVar,goConst | |
6153 | 263 |
264 " Integers | |
31139 | 265 syn match goDecimalInt "\<-\=\%(0\|\%(\d\|\d_\d\)\+\)\>" |
266 syn match goHexadecimalInt "\<-\=0[xX]_\?\%(\x\|\x_\x\)\+\>" | |
267 syn match goOctalInt "\<-\=0[oO]\?_\?\%(\o\|\o_\o\)\+\>" | |
268 syn match goBinaryInt "\<-\=0[bB]_\?\%([01]\|[01]_[01]\)\+\>" | |
6153 | 269 |
270 hi def link goDecimalInt Integer | |
25161 | 271 hi def link goDecimalError Error |
6153 | 272 hi def link goHexadecimalInt Integer |
25161 | 273 hi def link goHexadecimalError Error |
6153 | 274 hi def link goOctalInt Integer |
25161 | 275 hi def link goOctalError Error |
276 hi def link goBinaryInt Integer | |
277 hi def link goBinaryError Error | |
6153 | 278 hi def link Integer Number |
279 | |
280 " Floating point | |
31139 | 281 "float_lit = decimal_float_lit | hex_float_lit . |
282 " | |
283 "decimal_float_lit = decimal_digits "." [ decimal_digits ] [ decimal_exponent ] | | |
284 " decimal_digits decimal_exponent | | |
285 " "." decimal_digits [ decimal_exponent ] . | |
286 "decimal_exponent = ( "e" | "E" ) [ "+" | "-" ] decimal_digits . | |
287 " | |
288 "hex_float_lit = "0" ( "x" | "X" ) hex_mantissa hex_exponent . | |
289 "hex_mantissa = [ "_" ] hex_digits "." [ hex_digits ] | | |
290 " [ "_" ] hex_digits | | |
291 " "." hex_digits . | |
292 "hex_exponent = ( "p" | "P" ) [ "+" | "-" ] decimal_digits . | |
293 " decimal floats with a decimal point | |
294 syn match goFloat "\<-\=\%(0\|\%(\d\|\d_\d\)\+\)\.\%(\%(\%(\d\|\d_\d\)\+\)\=\%([Ee][-+]\=\%(\d\|\d_\d\)\+\)\=\>\)\=" | |
295 syn match goFloat "\s\zs-\=\.\%(\d\|\d_\d\)\+\%(\%([Ee][-+]\=\%(\d\|\d_\d\)\+\)\>\)\=" | |
296 " decimal floats without a decimal point | |
297 syn match goFloat "\<-\=\%(0\|\%(\d\|\d_\d\)\+\)[Ee][-+]\=\%(\d\|\d_\d\)\+\>" | |
298 " hexadecimal floats with a decimal point | |
299 syn match goHexadecimalFloat "\<-\=0[xX]\%(_\x\|\x\)\+\.\%(\%(\x\|\x_\x\)\+\)\=\%([Pp][-+]\=\%(\d\|\d_\d\)\+\)\=\>" | |
300 syn match goHexadecimalFloat "\<-\=0[xX]\.\%(\x\|\x_\x\)\+\%([Pp][-+]\=\%(\d\|\d_\d\)\+\)\=\>" | |
301 " hexadecimal floats without a decimal point | |
302 syn match goHexadecimalFloat "\<-\=0[xX]\%(_\x\|\x\)\+[Pp][-+]\=\%(\d\|\d_\d\)\+\>" | |
6153 | 303 |
304 hi def link goFloat Float | |
31139 | 305 hi def link goHexadecimalFloat Float |
6153 | 306 |
307 " Imaginary literals | |
31139 | 308 syn match goImaginaryDecimal "\<-\=\%(0\|\%(\d\|\d_\d\)\+\)i\>" |
309 syn match goImaginaryHexadecimal "\<-\=0[xX]_\?\%(\x\|\x_\x\)\+i\>" | |
310 syn match goImaginaryOctal "\<-\=0[oO]\?_\?\%(\o\|\o_\o\)\+i\>" | |
311 syn match goImaginaryBinary "\<-\=0[bB]_\?\%([01]\|[01]_[01]\)\+i\>" | |
6153 | 312 |
31139 | 313 " imaginary decimal floats with a decimal point |
314 syn match goImaginaryFloat "\<-\=\%(0\|\%(\d\|\d_\d\)\+\)\.\%(\%(\%(\d\|\d_\d\)\+\)\=\%([Ee][-+]\=\%(\d\|\d_\d\)\+\)\=\)\=i\>" | |
315 syn match goImaginaryFloat "\s\zs-\=\.\%(\d\|\d_\d\)\+\%([Ee][-+]\=\%(\d\|\d_\d\)\+\)\=i\>" | |
316 " imaginary decimal floats without a decimal point | |
317 syn match goImaginaryFloat "\<-\=\%(0\|\%(\d\|\d_\d\)\+\)[Ee][-+]\=\%(\d\|\d_\d\)\+i\>" | |
318 " imaginary hexadecimal floats with a decimal point | |
319 syn match goImaginaryHexadecimalFloat "\<-\=0[xX]\%(_\x\|\x\)\+\.\%(\%(\x\|\x_\x\)\+\)\=\%([Pp][-+]\=\%(\d\|\d_\d\)\+\)\=i\>" | |
320 syn match goImaginaryHexadecimalFloat "\<-\=0[xX]\.\%(\x\|\x_\x\)\+\%([Pp][-+]\=\%(\d\|\d_\d\)\+\)\=i\>" | |
321 " imaginary hexadecimal floats without a decimal point | |
322 syn match goImaginaryHexadecimalFloat "\<-\=0[xX]\%(_\x\|\x\)\+[Pp][-+]\=\%(\d\|\d_\d\)\+i\>" | |
323 | |
324 hi def link goImaginaryDecimal Number | |
325 hi def link goImaginaryHexadecimal Number | |
326 hi def link goImaginaryOctal Number | |
327 hi def link goImaginaryBinary Number | |
328 hi def link goImaginaryFloat Float | |
329 hi def link goImaginaryHexadecimalFloat Float | |
6153 | 330 |
331 " Spaces after "[]" | |
25161 | 332 if s:HighlightArrayWhitespaceError() |
333 syn match goSpaceError display "\%(\[\]\)\@<=\s\+" | |
6153 | 334 endif |
335 | |
336 " Spacing errors around the 'chan' keyword | |
25161 | 337 if s:HighlightChanWhitespaceError() |
6153 | 338 " receive-only annotation on chan type |
25161 | 339 " |
340 " \(\<chan\>\)\@<!<- (only pick arrow when it doesn't come after a chan) | |
341 " this prevents picking up 'chan<- chan<-' but not '<- chan' | |
342 syn match goSpaceError display "\%(\%(\<chan\>\)\@<!<-\)\@<=\s\+\%(\<chan\>\)\@=" | |
343 | |
6153 | 344 " send-only annotation on chan type |
25161 | 345 " |
346 " \(<-\)\@<!\<chan\> (only pick chan when it doesn't come after an arrow) | |
347 " this prevents picking up '<-chan <-chan' but not 'chan <-' | |
348 syn match goSpaceError display "\%(\%(<-\)\@<!\<chan\>\)\@<=\s\+\%(<-\)\@=" | |
349 | |
6153 | 350 " value-ignoring receives in a few contexts |
25161 | 351 syn match goSpaceError display "\%(\%(^\|[={(,;]\)\s*<-\)\@<=\s\+" |
6153 | 352 endif |
353 | |
354 " Extra types commonly seen | |
25161 | 355 if s:HighlightExtraTypes() |
356 syn match goExtraType /\<bytes\.\%(Buffer\)\>/ | |
357 syn match goExtraType /\<context\.\%(Context\)\>/ | |
358 syn match goExtraType /\<io\.\%(Reader\|ReadSeeker\|ReadWriter\|ReadCloser\|ReadWriteCloser\|Writer\|WriteCloser\|Seeker\)\>/ | |
359 syn match goExtraType /\<reflect\.\%(Kind\|Type\|Value\)\>/ | |
6153 | 360 syn match goExtraType /\<unsafe\.Pointer\>/ |
361 endif | |
362 | |
363 " Space-tab error | |
25161 | 364 if s:HighlightSpaceTabError() |
6153 | 365 syn match goSpaceError display " \+\t"me=e-1 |
366 endif | |
367 | |
368 " Trailing white space error | |
25161 | 369 if s:HighlightTrailingWhitespaceError() |
6153 | 370 syn match goSpaceError display excludenl "\s\+$" |
371 endif | |
372 | |
373 hi def link goExtraType Type | |
374 hi def link goSpaceError Error | |
375 | |
25161 | 376 |
377 | |
378 " included from: https://github.com/athom/more-colorful.vim/blob/master/after/syntax/go.vim | |
379 " | |
380 " Comments; their contents | |
381 syn keyword goTodo contained NOTE | |
382 hi def link goTodo Todo | |
383 | |
384 syn match goVarArgs /\.\.\./ | |
385 | |
386 " Operators; | |
387 if s:HighlightOperators() | |
388 " match single-char operators: - + % < > ! & | ^ * = | |
389 " and corresponding two-char operators: -= += %= <= >= != &= |= ^= *= == | |
390 syn match goOperator /[-+%<>!&|^*=]=\?/ | |
391 " match / and /= | |
392 syn match goOperator /\/\%(=\|\ze[^/*]\)/ | |
393 " match two-char operators: << >> &^ | |
394 " and corresponding three-char operators: <<= >>= &^= | |
395 syn match goOperator /\%(<<\|>>\|&^\)=\?/ | |
396 " match remaining two-char operators: := && || <- ++ -- | |
397 syn match goOperator /:=\|||\|<-\|++\|--/ | |
31139 | 398 " match ~ |
399 syn match goOperator /\~/ | |
25161 | 400 " match ... |
401 | |
402 hi def link goPointerOperator goOperator | |
403 hi def link goVarArgs goOperator | |
404 endif | |
405 hi def link goOperator Operator | |
406 | |
31139 | 407 " -> type constraint opening bracket |
408 " |-> start non-counting group | |
409 " || -> any word character | |
410 " || | -> at least one, as many as possible | |
411 " || | | -> start non-counting group | |
412 " || | | | -> match ~ | |
413 " || | | | | -> at most once | |
414 " || | | | | | -> allow a slice type | |
415 " || | | | | | | -> any word character | |
416 " || | | | | | | | -> start a non-counting group | |
417 " || | | | | | | | | -> that matches word characters and | | |
418 " || | | | | | | | | | -> close the non-counting group | |
419 " || | | | | | | | | | | -> close the non-counting group | |
420 " || | | | | | | | | | | |-> any number of matches | |
421 " || | | | | | | | | | | || -> start a non-counting group | |
422 " || | | | | | | | | | | || | -> a comma and whitespace | |
423 " || | | | | | | | | | | || | | -> at most once | |
424 " || | | | | | | | | | | || | | | -> close the non-counting group | |
425 " || | | | | | | | | | | || | | | | -> at least one of those non-counting groups, as many as possible | |
426 " || | | | | | -------- | | | | || | | | | | -> type constraint closing bracket | |
427 " || | | | | || | | | | | || | | | | | | | |
428 syn match goTypeParams /\[\%(\w\+\s\+\%(\~\?\%(\[]\)\?\w\%(\w\||\)\)*\%(,\s*\)\?\)\+\]/ nextgroup=goSimpleParams,goDeclType contained | |
429 | |
25161 | 430 " Functions; |
431 if s:HighlightFunctions() || s:HighlightFunctionParameters() | |
432 syn match goDeclaration /\<func\>/ nextgroup=goReceiver,goFunction,goSimpleParams skipwhite skipnl | |
31139 | 433 syn match goReceiverDecl /(\s*\zs\%(\%(\w\+\s\+\)\?\*\?\w\+\%(\[\%(\%(\[\]\)\?\w\+\%(,\s*\)\?\)\+\]\)\?\)\ze\s*)/ contained contains=goReceiverVar,goReceiverType,goPointerOperator |
25161 | 434 syn match goReceiverVar /\w\+\ze\s\+\%(\w\|\*\)/ nextgroup=goPointerOperator,goReceiverType skipwhite skipnl contained |
435 syn match goPointerOperator /\*/ nextgroup=goReceiverType contained skipwhite skipnl | |
31139 | 436 syn match goFunction /\w\+/ nextgroup=goSimpleParams,goTypeParams contained skipwhite skipnl |
437 syn match goReceiverType /\w\+\%(\[\%(\%(\[\]\)\?\w\+\%(,\s*\)\?\)\+\]\)\?\ze\s*)/ contained | |
25161 | 438 if s:HighlightFunctionParameters() |
439 syn match goSimpleParams /(\%(\w\|\_s\|[*\.\[\],\{\}<>-]\)*)/ contained contains=goParamName,goType nextgroup=goFunctionReturn skipwhite skipnl | |
440 syn match goFunctionReturn /(\%(\w\|\_s\|[*\.\[\],\{\}<>-]\)*)/ contained contains=goParamName,goType skipwhite skipnl | |
441 syn match goParamName /\w\+\%(\s*,\s*\w\+\)*\ze\s\+\%(\w\|\.\|\*\|\[\)/ contained nextgroup=goParamType skipwhite skipnl | |
442 syn match goParamType /\%([^,)]\|\_s\)\+,\?/ contained nextgroup=goParamName skipwhite skipnl | |
443 \ contains=goVarArgs,goType,goSignedInts,goUnsignedInts,goFloats,goComplexes,goDeclType,goBlock | |
444 hi def link goReceiverVar goParamName | |
445 hi def link goParamName Identifier | |
446 endif | |
31139 | 447 syn match goReceiver /(\s*\%(\w\+\s\+\)\?\*\?\s*\w\+\%(\[\%(\%(\[\]\)\?\w\+\%(,\s*\)\?\)\+\]\)\?\s*)\ze\s*\w/ contained nextgroup=goFunction contains=goReceiverDecl skipwhite skipnl |
25161 | 448 else |
449 syn keyword goDeclaration func | |
450 endif | |
451 hi def link goFunction Function | |
452 | |
453 " Function calls; | |
454 if s:HighlightFunctionCalls() | |
31139 | 455 syn match goFunctionCall /\w\+\ze\%(\[\%(\%(\[]\)\?\w\+\(,\s*\)\?\)\+\]\)\?(/ contains=goBuiltins,goDeclaration |
25161 | 456 endif |
457 hi def link goFunctionCall Type | |
458 | |
459 " Fields; | |
460 if s:HighlightFields() | |
461 " 1. Match a sequence of word characters coming after a '.' | |
462 " 2. Require the following but dont match it: ( \@= see :h E59) | |
463 " - The symbols: / - + * % OR | |
464 " - The symbols: [] {} <> ) OR | |
465 " - The symbols: \n \r space OR | |
466 " - The symbols: , : . | |
467 " 3. Have the start of highlight (hs) be the start of matched | |
468 " pattern (s) offsetted one to the right (+1) (see :h E401) | |
469 syn match goField /\.\w\+\ | |
470 \%(\%([\/\-\+*%]\)\|\ | |
471 \%([\[\]{}<\>\)]\)\|\ | |
472 \%([\!=\^|&]\)\|\ | |
473 \%([\n\r\ ]\)\|\ | |
474 \%([,\:.]\)\)\@=/hs=s+1 | |
475 endif | |
476 hi def link goField Identifier | |
477 | |
478 " Structs & Interfaces; | |
479 if s:HighlightTypes() | |
480 syn match goTypeConstructor /\<\w\+{\@=/ | |
481 syn match goTypeDecl /\<type\>/ nextgroup=goTypeName skipwhite skipnl | |
31139 | 482 syn match goTypeName /\w\+/ contained nextgroup=goDeclType,goTypeParams skipwhite skipnl |
25161 | 483 syn match goDeclType /\<\%(interface\|struct\)\>/ skipwhite skipnl |
484 hi def link goReceiverType Type | |
485 else | |
486 syn keyword goDeclType struct interface | |
487 syn keyword goDeclaration type | |
488 endif | |
489 hi def link goTypeConstructor Type | |
490 hi def link goTypeName Type | |
491 hi def link goTypeDecl Keyword | |
492 hi def link goDeclType Keyword | |
493 | |
494 " Variable Assignments | |
495 if s:HighlightVariableAssignments() | |
496 syn match goVarAssign /\v[_.[:alnum:]]+(,\s*[_.[:alnum:]]+)*\ze(\s*([-^+|^\/%&]|\*|\<\<|\>\>|\&\^)?\=[^=])/ | |
497 hi def link goVarAssign Special | |
498 endif | |
499 | |
500 " Variable Declarations | |
501 if s:HighlightVariableDeclarations() | |
502 syn match goVarDefs /\v\w+(,\s*\w+)*\ze(\s*:\=)/ | |
503 hi def link goVarDefs Special | |
504 endif | |
505 | |
506 " Build Constraints | |
507 if s:HighlightBuildConstraints() | |
25836 | 508 syn match goBuildKeyword display contained "+build\|go:build" |
25161 | 509 " Highlight the known values of GOOS, GOARCH, and other +build options. |
510 syn keyword goBuildDirectives contained | |
511 \ android darwin dragonfly freebsd linux nacl netbsd openbsd plan9 | |
512 \ solaris windows 386 amd64 amd64p32 arm armbe arm64 arm64be ppc64 | |
513 \ ppc64le mips mipsle mips64 mips64le mips64p32 mips64p32le ppc | |
514 \ s390 s390x sparc sparc64 cgo ignore race | |
515 | |
516 " Other words in the build directive are build tags not listed above, so | |
517 " avoid highlighting them as comments by using a matchgroup just for the | |
518 " start of the comment. | |
519 " The rs=s+2 option lets the \s*+build portion be part of the inner region | |
520 " instead of the matchgroup so it will be highlighted as a goBuildKeyword. | |
521 syn region goBuildComment matchgroup=goBuildCommentStart | |
31139 | 522 \ start="//\(\s*+build\s\|go:build\)"rs=s+2 end="$" |
25161 | 523 \ contains=goBuildKeyword,goBuildDirectives |
524 hi def link goBuildCommentStart Comment | |
525 hi def link goBuildDirectives Type | |
526 hi def link goBuildKeyword PreProc | |
527 endif | |
528 | |
529 if s:HighlightBuildConstraints() || s:FoldEnable('package_comment') | |
530 " One or more line comments that are followed immediately by a "package" | |
531 " declaration are treated like package documentation, so these must be | |
532 " matched as comments to avoid looking like working build constraints. | |
533 " The he, me, and re options let the "package" itself be highlighted by | |
534 " the usual rules. | |
34578
deee52c162df
runtime(go): `goPackageComment` highlighting too broad
Christian Brabandt <cb@256bit.org>
parents:
34172
diff
changeset
|
535 exe 'syn region goPackageComment start=/\v(\/\/.*\n)+\s*package\s/' |
deee52c162df
runtime(go): `goPackageComment` highlighting too broad
Christian Brabandt <cb@256bit.org>
parents:
34172
diff
changeset
|
536 \ . ' end=/\v\n\s*package\s/he=e-8,me=e-8,re=e-8' |
25161 | 537 \ . ' contains=@goCommentGroup,@Spell' |
538 \ . (s:FoldEnable('package_comment') ? ' fold' : '') | |
34578
deee52c162df
runtime(go): `goPackageComment` highlighting too broad
Christian Brabandt <cb@256bit.org>
parents:
34172
diff
changeset
|
539 exe 'syn region goPackageComment start=/\v^\s*\/\*.*\n(.*\n)*\s*\*\/\npackage\s/' |
deee52c162df
runtime(go): `goPackageComment` highlighting too broad
Christian Brabandt <cb@256bit.org>
parents:
34172
diff
changeset
|
540 \ . ' end=/\v\*\/\n\s*package\s/he=e-8,me=e-8,re=e-8' |
25161 | 541 \ . ' contains=@goCommentGroup,@Spell' |
542 \ . (s:FoldEnable('package_comment') ? ' fold' : '') | |
543 hi def link goPackageComment Comment | |
544 endif | |
545 | |
546 " :GoCoverage commands | |
547 hi def link goCoverageNormalText Comment | |
548 | |
6153 | 549 " Search backwards for a global declaration to start processing the syntax. |
550 "syn sync match goSync grouphere NONE /^\(const\|var\|type\|func\)\>/ | |
551 | |
552 " There's a bug in the implementation of grouphere. For now, use the | |
553 " following as a more expensive/less precise workaround. | |
554 syn sync minlines=500 | |
555 | |
25161 | 556 let b:current_syntax = "go" |
557 | |
558 let &cpo = s:keepcpo | |
559 unlet s:keepcpo | |
6153 | 560 |
561 " vim: sw=2 sts=2 et |