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