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>
|
25836
|
8 " Latest Revision: 2021-09-18
|
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
|
|
120 syn keyword goType chan map bool string error
|
|
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
|
|
139 hi def link goBoolean Boolean
|
|
140 hi def link goPredefinedIdentifiers goBoolean
|
6153
|
141
|
|
142 " Comments; their contents
|
|
143 syn keyword goTodo contained TODO FIXME XXX BUG
|
|
144 syn cluster goCommentGroup contains=goTodo
|
25161
|
145
|
|
146 syn region goComment start="//" end="$" contains=goGenerate,@goCommentGroup,@Spell
|
|
147 if s:FoldEnable('comment')
|
|
148 syn region goComment start="/\*" end="\*/" contains=@goCommentGroup,@Spell fold
|
|
149 syn match goComment "\v(^\s*//.*\n)+" contains=goGenerate,@goCommentGroup,@Spell fold
|
|
150 else
|
|
151 syn region goComment start="/\*" end="\*/" contains=@goCommentGroup,@Spell
|
|
152 endif
|
6153
|
153
|
|
154 hi def link goComment Comment
|
|
155 hi def link goTodo Todo
|
|
156
|
25161
|
157 if s:HighlightGenerateTags()
|
|
158 syn match goGenerateVariables contained /\%(\$GOARCH\|\$GOOS\|\$GOFILE\|\$GOLINE\|\$GOPACKAGE\|\$DOLLAR\)\>/
|
|
159 syn region goGenerate start="^\s*//go:generate" end="$" contains=goGenerateVariables
|
|
160 hi def link goGenerate PreProc
|
|
161 hi def link goGenerateVariables Special
|
|
162 endif
|
|
163
|
6153
|
164 " Go escapes
|
|
165 syn match goEscapeOctal display contained "\\[0-7]\{3}"
|
|
166 syn match goEscapeC display contained +\\[abfnrtv\\'"]+
|
|
167 syn match goEscapeX display contained "\\x\x\{2}"
|
|
168 syn match goEscapeU display contained "\\u\x\{4}"
|
|
169 syn match goEscapeBigU display contained "\\U\x\{8}"
|
|
170 syn match goEscapeError display contained +\\[^0-7xuUabfnrtv\\'"]+
|
|
171
|
|
172 hi def link goEscapeOctal goSpecialString
|
|
173 hi def link goEscapeC goSpecialString
|
|
174 hi def link goEscapeX goSpecialString
|
|
175 hi def link goEscapeU goSpecialString
|
|
176 hi def link goEscapeBigU goSpecialString
|
|
177 hi def link goSpecialString Special
|
|
178 hi def link goEscapeError Error
|
|
179
|
|
180 " Strings and their contents
|
|
181 syn cluster goStringGroup contains=goEscapeOctal,goEscapeC,goEscapeX,goEscapeU,goEscapeBigU,goEscapeError
|
25161
|
182 if s:HighlightStringSpellcheck()
|
|
183 syn region goString start=+"+ skip=+\\\\\|\\"+ end=+"+ contains=@goStringGroup,@Spell
|
|
184 syn region goRawString start=+`+ end=+`+ contains=@Spell
|
|
185 else
|
|
186 syn region goString start=+"+ skip=+\\\\\|\\"+ end=+"+ contains=@goStringGroup
|
|
187 syn region goRawString start=+`+ end=+`+
|
|
188 endif
|
|
189
|
|
190 if s:HighlightFormatStrings()
|
|
191 " [n] notation is valid for specifying explicit argument indexes
|
|
192 " 1. Match a literal % not preceded by a %.
|
|
193 " 2. Match any number of -, #, 0, space, or +
|
|
194 " 3. Match * or [n]* or any number or nothing before a .
|
|
195 " 4. Match * or [n]* or any number or nothing after a .
|
|
196 " 5. Match [n] or nothing before a verb
|
|
197 " 6. Match a formatting verb
|
|
198 syn match goFormatSpecifier /\
|
|
199 \%([^%]\%(%%\)*\)\
|
|
200 \@<=%[-#0 +]*\
|
|
201 \%(\%(\%(\[\d\+\]\)\=\*\)\|\d\+\)\=\
|
|
202 \%(\.\%(\%(\%(\[\d\+\]\)\=\*\)\|\d\+\)\=\)\=\
|
|
203 \%(\[\d\+\]\)\=[vTtbcdoqxXUeEfFgGspw]/ contained containedin=goString,goRawString
|
|
204 hi def link goFormatSpecifier goSpecialString
|
|
205 endif
|
6153
|
206
|
|
207 hi def link goString String
|
|
208 hi def link goRawString String
|
|
209
|
|
210 " Characters; their contents
|
|
211 syn cluster goCharacterGroup contains=goEscapeOctal,goEscapeC,goEscapeX,goEscapeU,goEscapeBigU
|
|
212 syn region goCharacter start=+'+ skip=+\\\\\|\\'+ end=+'+ contains=@goCharacterGroup
|
|
213
|
|
214 hi def link goCharacter Character
|
|
215
|
|
216 " Regions
|
|
217 syn region goParen start='(' end=')' transparent
|
25161
|
218 if s:FoldEnable('block')
|
|
219 syn region goBlock start="{" end="}" transparent fold
|
|
220 else
|
|
221 syn region goBlock start="{" end="}" transparent
|
|
222 endif
|
|
223
|
|
224 " import
|
|
225 if s:FoldEnable('import')
|
|
226 syn region goImport start='import (' end=')' transparent fold contains=goImport,goString,goComment
|
|
227 else
|
|
228 syn region goImport start='import (' end=')' transparent contains=goImport,goString,goComment
|
|
229 endif
|
|
230
|
|
231 " var, const
|
|
232 if s:FoldEnable('varconst')
|
|
233 syn region goVar start='var (' end='^\s*)$' transparent fold
|
|
234 \ contains=ALLBUT,goParen,goBlock,goFunction,goTypeName,goReceiverType,goReceiverVar,goParamName,goParamType,goSimpleParams,goPointerOperator
|
|
235 syn region goConst start='const (' end='^\s*)$' transparent fold
|
|
236 \ contains=ALLBUT,goParen,goBlock,goFunction,goTypeName,goReceiverType,goReceiverVar,goParamName,goParamType,goSimpleParams,goPointerOperator
|
|
237 else
|
|
238 syn region goVar start='var (' end='^\s*)$' transparent
|
|
239 \ contains=ALLBUT,goParen,goBlock,goFunction,goTypeName,goReceiverType,goReceiverVar,goParamName,goParamType,goSimpleParams,goPointerOperator
|
|
240 syn region goConst start='const (' end='^\s*)$' transparent
|
|
241 \ contains=ALLBUT,goParen,goBlock,goFunction,goTypeName,goReceiverType,goReceiverVar,goParamName,goParamType,goSimpleParams,goPointerOperator
|
|
242 endif
|
|
243
|
|
244 " Single-line var, const, and import.
|
|
245 syn match goSingleDecl /\%(import\|var\|const\) [^(]\@=/ contains=goImport,goVar,goConst
|
6153
|
246
|
|
247 " Integers
|
25161
|
248 syn match goDecimalInt "\<-\=\(0\|[1-9]_\?\(\d\|\d\+_\?\d\+\)*\)\%([Ee][-+]\=\d\+\)\=\>"
|
|
249 syn match goDecimalError "\<-\=\(_\(\d\+_*\)\+\|\([1-9]\d*_*\)\+__\(\d\+_*\)\+\|\([1-9]\d*_*\)\+_\+\)\%([Ee][-+]\=\d\+\)\=\>"
|
|
250 syn match goHexadecimalInt "\<-\=0[xX]_\?\(\x\+_\?\)\+\>"
|
|
251 syn match goHexadecimalError "\<-\=0[xX]_\?\(\x\+_\?\)*\(\([^ \t0-9A-Fa-f_)]\|__\)\S*\|_\)\>"
|
|
252 syn match goOctalInt "\<-\=0[oO]\?_\?\(\o\+_\?\)\+\>"
|
25836
|
253 syn match goOctalError "\<-\=0[0-7oO_]*\(\([^ \t0-7oOxX_/)\]\}\:;]\|[oO]\{2,\}\|__\)\S*\|_\|[oOxX]\)\>"
|
25161
|
254 syn match goBinaryInt "\<-\=0[bB]_\?\([01]\+_\?\)\+\>"
|
|
255 syn match goBinaryError "\<-\=0[bB]_\?[01_]*\([^ \t01_)]\S*\|__\S*\|_\)\>"
|
6153
|
256
|
|
257 hi def link goDecimalInt Integer
|
25161
|
258 hi def link goDecimalError Error
|
6153
|
259 hi def link goHexadecimalInt Integer
|
25161
|
260 hi def link goHexadecimalError Error
|
6153
|
261 hi def link goOctalInt Integer
|
25161
|
262 hi def link goOctalError Error
|
|
263 hi def link goBinaryInt Integer
|
|
264 hi def link goBinaryError Error
|
6153
|
265 hi def link Integer Number
|
|
266
|
|
267 " Floating point
|
25161
|
268 syn match goFloat "\<-\=\d\+\.\d*\%([Ee][-+]\=\d\+\)\=\>"
|
|
269 syn match goFloat "\<-\=\.\d\+\%([Ee][-+]\=\d\+\)\=\>"
|
6153
|
270
|
|
271 hi def link goFloat Float
|
|
272
|
|
273 " Imaginary literals
|
25161
|
274 syn match goImaginary "\<-\=\d\+i\>"
|
|
275 syn match goImaginary "\<-\=\d\+[Ee][-+]\=\d\+i\>"
|
|
276 syn match goImaginaryFloat "\<-\=\d\+\.\d*\%([Ee][-+]\=\d\+\)\=i\>"
|
|
277 syn match goImaginaryFloat "\<-\=\.\d\+\%([Ee][-+]\=\d\+\)\=i\>"
|
6153
|
278
|
|
279 hi def link goImaginary Number
|
25161
|
280 hi def link goImaginaryFloat Float
|
6153
|
281
|
|
282 " Spaces after "[]"
|
25161
|
283 if s:HighlightArrayWhitespaceError()
|
|
284 syn match goSpaceError display "\%(\[\]\)\@<=\s\+"
|
6153
|
285 endif
|
|
286
|
|
287 " Spacing errors around the 'chan' keyword
|
25161
|
288 if s:HighlightChanWhitespaceError()
|
6153
|
289 " receive-only annotation on chan type
|
25161
|
290 "
|
|
291 " \(\<chan\>\)\@<!<- (only pick arrow when it doesn't come after a chan)
|
|
292 " this prevents picking up 'chan<- chan<-' but not '<- chan'
|
|
293 syn match goSpaceError display "\%(\%(\<chan\>\)\@<!<-\)\@<=\s\+\%(\<chan\>\)\@="
|
|
294
|
6153
|
295 " send-only annotation on chan type
|
25161
|
296 "
|
|
297 " \(<-\)\@<!\<chan\> (only pick chan when it doesn't come after an arrow)
|
|
298 " this prevents picking up '<-chan <-chan' but not 'chan <-'
|
|
299 syn match goSpaceError display "\%(\%(<-\)\@<!\<chan\>\)\@<=\s\+\%(<-\)\@="
|
|
300
|
6153
|
301 " value-ignoring receives in a few contexts
|
25161
|
302 syn match goSpaceError display "\%(\%(^\|[={(,;]\)\s*<-\)\@<=\s\+"
|
6153
|
303 endif
|
|
304
|
|
305 " Extra types commonly seen
|
25161
|
306 if s:HighlightExtraTypes()
|
|
307 syn match goExtraType /\<bytes\.\%(Buffer\)\>/
|
|
308 syn match goExtraType /\<context\.\%(Context\)\>/
|
|
309 syn match goExtraType /\<io\.\%(Reader\|ReadSeeker\|ReadWriter\|ReadCloser\|ReadWriteCloser\|Writer\|WriteCloser\|Seeker\)\>/
|
|
310 syn match goExtraType /\<reflect\.\%(Kind\|Type\|Value\)\>/
|
6153
|
311 syn match goExtraType /\<unsafe\.Pointer\>/
|
|
312 endif
|
|
313
|
|
314 " Space-tab error
|
25161
|
315 if s:HighlightSpaceTabError()
|
6153
|
316 syn match goSpaceError display " \+\t"me=e-1
|
|
317 endif
|
|
318
|
|
319 " Trailing white space error
|
25161
|
320 if s:HighlightTrailingWhitespaceError()
|
6153
|
321 syn match goSpaceError display excludenl "\s\+$"
|
|
322 endif
|
|
323
|
|
324 hi def link goExtraType Type
|
|
325 hi def link goSpaceError Error
|
|
326
|
25161
|
327
|
|
328
|
|
329 " included from: https://github.com/athom/more-colorful.vim/blob/master/after/syntax/go.vim
|
|
330 "
|
|
331 " Comments; their contents
|
|
332 syn keyword goTodo contained NOTE
|
|
333 hi def link goTodo Todo
|
|
334
|
|
335 syn match goVarArgs /\.\.\./
|
|
336
|
|
337 " Operators;
|
|
338 if s:HighlightOperators()
|
|
339 " match single-char operators: - + % < > ! & | ^ * =
|
|
340 " and corresponding two-char operators: -= += %= <= >= != &= |= ^= *= ==
|
|
341 syn match goOperator /[-+%<>!&|^*=]=\?/
|
|
342 " match / and /=
|
|
343 syn match goOperator /\/\%(=\|\ze[^/*]\)/
|
|
344 " match two-char operators: << >> &^
|
|
345 " and corresponding three-char operators: <<= >>= &^=
|
|
346 syn match goOperator /\%(<<\|>>\|&^\)=\?/
|
|
347 " match remaining two-char operators: := && || <- ++ --
|
|
348 syn match goOperator /:=\|||\|<-\|++\|--/
|
|
349 " match ...
|
|
350
|
|
351 hi def link goPointerOperator goOperator
|
|
352 hi def link goVarArgs goOperator
|
|
353 endif
|
|
354 hi def link goOperator Operator
|
|
355
|
|
356 " Functions;
|
|
357 if s:HighlightFunctions() || s:HighlightFunctionParameters()
|
|
358 syn match goDeclaration /\<func\>/ nextgroup=goReceiver,goFunction,goSimpleParams skipwhite skipnl
|
|
359 syn match goReceiverVar /\w\+\ze\s\+\%(\w\|\*\)/ nextgroup=goPointerOperator,goReceiverType skipwhite skipnl contained
|
|
360 syn match goPointerOperator /\*/ nextgroup=goReceiverType contained skipwhite skipnl
|
|
361 syn match goFunction /\w\+/ nextgroup=goSimpleParams contained skipwhite skipnl
|
|
362 syn match goReceiverType /\w\+/ contained
|
|
363 if s:HighlightFunctionParameters()
|
|
364 syn match goSimpleParams /(\%(\w\|\_s\|[*\.\[\],\{\}<>-]\)*)/ contained contains=goParamName,goType nextgroup=goFunctionReturn skipwhite skipnl
|
|
365 syn match goFunctionReturn /(\%(\w\|\_s\|[*\.\[\],\{\}<>-]\)*)/ contained contains=goParamName,goType skipwhite skipnl
|
|
366 syn match goParamName /\w\+\%(\s*,\s*\w\+\)*\ze\s\+\%(\w\|\.\|\*\|\[\)/ contained nextgroup=goParamType skipwhite skipnl
|
|
367 syn match goParamType /\%([^,)]\|\_s\)\+,\?/ contained nextgroup=goParamName skipwhite skipnl
|
|
368 \ contains=goVarArgs,goType,goSignedInts,goUnsignedInts,goFloats,goComplexes,goDeclType,goBlock
|
|
369 hi def link goReceiverVar goParamName
|
|
370 hi def link goParamName Identifier
|
|
371 endif
|
|
372 syn match goReceiver /(\s*\w\+\%(\s\+\*\?\s*\w\+\)\?\s*)\ze\s*\w/ contained nextgroup=goFunction contains=goReceiverVar skipwhite skipnl
|
|
373 else
|
|
374 syn keyword goDeclaration func
|
|
375 endif
|
|
376 hi def link goFunction Function
|
|
377
|
|
378 " Function calls;
|
|
379 if s:HighlightFunctionCalls()
|
|
380 syn match goFunctionCall /\w\+\ze(/ contains=goBuiltins,goDeclaration
|
|
381 endif
|
|
382 hi def link goFunctionCall Type
|
|
383
|
|
384 " Fields;
|
|
385 if s:HighlightFields()
|
|
386 " 1. Match a sequence of word characters coming after a '.'
|
|
387 " 2. Require the following but dont match it: ( \@= see :h E59)
|
|
388 " - The symbols: / - + * % OR
|
|
389 " - The symbols: [] {} <> ) OR
|
|
390 " - The symbols: \n \r space OR
|
|
391 " - The symbols: , : .
|
|
392 " 3. Have the start of highlight (hs) be the start of matched
|
|
393 " pattern (s) offsetted one to the right (+1) (see :h E401)
|
|
394 syn match goField /\.\w\+\
|
|
395 \%(\%([\/\-\+*%]\)\|\
|
|
396 \%([\[\]{}<\>\)]\)\|\
|
|
397 \%([\!=\^|&]\)\|\
|
|
398 \%([\n\r\ ]\)\|\
|
|
399 \%([,\:.]\)\)\@=/hs=s+1
|
|
400 endif
|
|
401 hi def link goField Identifier
|
|
402
|
|
403 " Structs & Interfaces;
|
|
404 if s:HighlightTypes()
|
|
405 syn match goTypeConstructor /\<\w\+{\@=/
|
|
406 syn match goTypeDecl /\<type\>/ nextgroup=goTypeName skipwhite skipnl
|
|
407 syn match goTypeName /\w\+/ contained nextgroup=goDeclType skipwhite skipnl
|
|
408 syn match goDeclType /\<\%(interface\|struct\)\>/ skipwhite skipnl
|
|
409 hi def link goReceiverType Type
|
|
410 else
|
|
411 syn keyword goDeclType struct interface
|
|
412 syn keyword goDeclaration type
|
|
413 endif
|
|
414 hi def link goTypeConstructor Type
|
|
415 hi def link goTypeName Type
|
|
416 hi def link goTypeDecl Keyword
|
|
417 hi def link goDeclType Keyword
|
|
418
|
|
419 " Variable Assignments
|
|
420 if s:HighlightVariableAssignments()
|
|
421 syn match goVarAssign /\v[_.[:alnum:]]+(,\s*[_.[:alnum:]]+)*\ze(\s*([-^+|^\/%&]|\*|\<\<|\>\>|\&\^)?\=[^=])/
|
|
422 hi def link goVarAssign Special
|
|
423 endif
|
|
424
|
|
425 " Variable Declarations
|
|
426 if s:HighlightVariableDeclarations()
|
|
427 syn match goVarDefs /\v\w+(,\s*\w+)*\ze(\s*:\=)/
|
|
428 hi def link goVarDefs Special
|
|
429 endif
|
|
430
|
|
431 " Build Constraints
|
|
432 if s:HighlightBuildConstraints()
|
25836
|
433 syn match goBuildKeyword display contained "+build\|go:build"
|
25161
|
434 " Highlight the known values of GOOS, GOARCH, and other +build options.
|
|
435 syn keyword goBuildDirectives contained
|
|
436 \ android darwin dragonfly freebsd linux nacl netbsd openbsd plan9
|
|
437 \ solaris windows 386 amd64 amd64p32 arm armbe arm64 arm64be ppc64
|
|
438 \ ppc64le mips mipsle mips64 mips64le mips64p32 mips64p32le ppc
|
|
439 \ s390 s390x sparc sparc64 cgo ignore race
|
|
440
|
|
441 " Other words in the build directive are build tags not listed above, so
|
|
442 " avoid highlighting them as comments by using a matchgroup just for the
|
|
443 " start of the comment.
|
|
444 " The rs=s+2 option lets the \s*+build portion be part of the inner region
|
|
445 " instead of the matchgroup so it will be highlighted as a goBuildKeyword.
|
|
446 syn region goBuildComment matchgroup=goBuildCommentStart
|
|
447 \ start="//\s*+build\s"rs=s+2 end="$"
|
|
448 \ contains=goBuildKeyword,goBuildDirectives
|
|
449 hi def link goBuildCommentStart Comment
|
|
450 hi def link goBuildDirectives Type
|
|
451 hi def link goBuildKeyword PreProc
|
|
452 endif
|
|
453
|
|
454 if s:HighlightBuildConstraints() || s:FoldEnable('package_comment')
|
|
455 " One or more line comments that are followed immediately by a "package"
|
|
456 " declaration are treated like package documentation, so these must be
|
|
457 " matched as comments to avoid looking like working build constraints.
|
|
458 " The he, me, and re options let the "package" itself be highlighted by
|
|
459 " the usual rules.
|
|
460 exe 'syn region goPackageComment start=/\v(\/\/.*\n)+\s*package/'
|
|
461 \ . ' end=/\v\n\s*package/he=e-7,me=e-7,re=e-7'
|
|
462 \ . ' contains=@goCommentGroup,@Spell'
|
|
463 \ . (s:FoldEnable('package_comment') ? ' fold' : '')
|
|
464 exe 'syn region goPackageComment start=/\v^\s*\/\*.*\n(.*\n)*\s*\*\/\npackage/'
|
|
465 \ . ' end=/\v\*\/\n\s*package/he=e-7,me=e-7,re=e-7'
|
|
466 \ . ' contains=@goCommentGroup,@Spell'
|
|
467 \ . (s:FoldEnable('package_comment') ? ' fold' : '')
|
|
468 hi def link goPackageComment Comment
|
|
469 endif
|
|
470
|
|
471 " :GoCoverage commands
|
|
472 hi def link goCoverageNormalText Comment
|
|
473
|
6153
|
474 " Search backwards for a global declaration to start processing the syntax.
|
|
475 "syn sync match goSync grouphere NONE /^\(const\|var\|type\|func\)\>/
|
|
476
|
|
477 " There's a bug in the implementation of grouphere. For now, use the
|
|
478 " following as a more expensive/less precise workaround.
|
|
479 syn sync minlines=500
|
|
480
|
25161
|
481 let b:current_syntax = "go"
|
|
482
|
|
483 let &cpo = s:keepcpo
|
|
484 unlet s:keepcpo
|
6153
|
485
|
|
486 " vim: sw=2 sts=2 et
|