go.vim 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. syn cluster goTypes contains=goType,goSignedInts,goUnsignedInts,goFloats,goComplexes
  2. syn cluster goNumber contains=goDecimalInt,goHexadecimalInt,goOctalInt,goFloat,goImaginary,goImaginaryFloat
  3. if !exists("g:go_highlight_fields")
  4. let g:go_highlight_fields = 0
  5. endif
  6. if g:go_highlight_fields != 0
  7. syn match goField /\(\.\)\@1<=\w\+\([.\ \n\r\:\)\[,+-\*\\\]]\)\@=/
  8. endif
  9. if !exists("g:go_highlight_functions")
  10. let g:go_highlight_functions = 0
  11. endif
  12. if g:go_highlight_functions != 0
  13. syn clear goFunctionCall
  14. syn clear goFunction
  15. syn match goDeclaration /\<func\>/ nextgroup=goReceiverRegion,goFunction skipwhite skipnl
  16. syn region goReceiverRegion matchgroup=ContainerChars start=/(/ end=/)/ contains=goReceiver nextgroup=goFunction contained
  17. syn match goReceiver /\(\w\|[ *]\)\+/ contained contains=goReceiverVar skipwhite skipnl contained
  18. syn cluster validFuncRegionContains contains=@goTypes,goField,goDeclaration,GoBuiltins,goDeclStruct,goDeclInterface,OperatorChars,ContainerChars,goString,goRawString,@goNumber,goTypeConstructor
  19. " fix comment
  20. syn match goFunctionTagLine /\w\+(.\{-})\(\s*(.\{-})\|\s\S\+\)\?\(\s*\|$\)/ nextgroup=goFunction contains=goFunction,goFunctionParamRegion,goFunctionReturnRegion,goFunctionReturn,OperatorChars,ContainerChars,goComment
  21. syn region goFunctionParamRegion matchgroup=ContainerChars start=/(/ end=/)/ contains=@validFuncRegionContains nextgroup=goFunctionReturnRegion,goFunctionReturn skipwhite contained
  22. syn region goFunctionReturnRegion matchgroup=ContainerChars start=/(/ end=/)/ contains=@validFuncRegionContains skipwhite contained
  23. syn match goFunctionReturn /\w\+/ contains=@validFuncRegionContains skipwhite contained
  24. syn match goFunction /\w\+\ze(/ nextgroup=goFunctionParamRegion skipwhite contained
  25. endif
  26. if !exists("g:go_highlight_types")
  27. let g:go_highlight_types = 0
  28. endif
  29. if g:go_highlight_types != 0
  30. syn match goTypeConstructor /\<\w\+{/he=e-1 contains=goTypeOpen
  31. syn match goTypeOpen /{/ contained
  32. "syn match goTypeClose /}/ contained
  33. " TODO (maybe): handle only Type-highlighting things like xml.Name ignoring
  34. " the first \w+\. and highlighting the remaining \w+
  35. "
  36. " This is most likely bad... probably very bad.. and brittle?
  37. syn clear goTypeDecl
  38. syn clear goTypeName
  39. syn clear goDeclType
  40. syn cluster validTypeContains contains=goComment,goNewDeclType,goDeclTypeField,goDeclTypeFieldType,goDeclTypeFieldSlice,goDeclTypeFieldPointerOp,goString,goRawString,OperatorChars,ContainerChars
  41. syn cluster validStructContains contains=goComment,goNewDeclType,goDeclTypeField,goDeclTypeFieldType,goString,goRawString,OperatorChars,ContainerChars
  42. syn cluster validInterfaceContains contains=goComment,goFunctionTagLine,OperatorChars,ContainerChars
  43. syn match goTypeDecl /\<type\>/ nextgroup=goNewDeclType,goTypeRegion skipwhite skipnl
  44. syn region goTypeRegion matchgroup=ContainerChars start=/(/ end=/)/ contains=@validTypeContains fold contained
  45. syn region goDeclStructRegion matchgroup=ContainerChars start=/{/ end=/}/ contains=@validStructContains fold contained
  46. syn region goDeclInterfaceRegion matchgroup=ContainerChars start=/{/ end=/}/ contains=@validInterfaceContains fold contained
  47. syn match goDeclTypeFieldPointerOp /\*/ nextgroup=goDeclTypeFieldPointerOp,goDeclTypeFieldSlice,goDeclTypeFieldType,goDeclStruct,goDeclInterface skipwhite contained
  48. syn region goDeclTypeFieldSlice matchgroup=ContainerChars start=/\[/ end=/\]/ contains=goDecimalInt,goHexadecimalInt,goOctalInt nextgroup=goDeclTypeFieldPointerOp,goDeclTypeFieldSlice,goDeclTypeFieldType,goDeclStruct,goDeclInterface skipwhite contained
  49. syn match goDeclTypeFieldType /\(\w\|\.\)\+/ skipwhite contained
  50. syn match goDeclTypeField /\w\+/ nextgroup=goDeclTypeFieldPointerOp,goDeclTypeFieldSlice,goDeclTypeFieldType skipwhite contained
  51. syn match goNewDeclType /\w\+\ze\s\+\<\(struct\|interface\)\>/ nextgroup=goDeclStruct,goDeclInterface skipwhite contained
  52. syn match goDeclStruct /\<struct\>/ nextgroup=goDeclStructRegion skipwhite skipnl
  53. syn match goDeclInterface /\<interface\>/ nextgroup=goDeclInterfaceRegion skipwhite skipnl
  54. endif
  55. hi link goPointerOperator Operator
  56. hi link goDeclTypeFieldPointerOp Operator
  57. hi link goTypeConstructor Type
  58. hi link goTypeOpen ContainerChars
  59. hi link goDeclTypeFieldType Type
  60. hi link goNewDeclType Type
  61. hi link goDeclInterface Keyword
  62. hi link goDeclStruct Keyword
  63. hi link goFunction Function
  64. hi link goMethodCall Function
  65. hi link goFunctionCall Function