go.vim 24 KB

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