robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

zeertzjqMerge pull request #40950 from zeertzjq/vim-9.2.08450e1a24836d

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