go.vim 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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=goContainer 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,goContainer,goString,goRawString,@goNumber,goTypeConstructor
  19. " fix comment
  20. syn match goFunctionTagLine /\w\+(.\{-})\(\s*(.\{-})\|\s\S\+\)\?\(\s*\|$\)/ nextgroup=goFunction contains=goFunction,goFunctionParamRegion,goFunctionReturnRegion,goFunctionReturn,OperatorChars,goContainer,goComment
  21. syn region goFunctionParamRegion matchgroup=goContainer start=/(/ end=/)/ contains=@validFuncRegionContains nextgroup=goFunctionReturnRegion,goFunctionReturn skipwhite contained
  22. syn region goFunctionReturnRegion matchgroup=goContainer 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\+\({\)\@1=/
  31. " handle map[type]type
  32. " handle field, field type
  33. " This is most likely bad... probably very bad.. and brittle?
  34. syn clear goTypeDecl
  35. syn clear goTypeName
  36. syn clear goDeclType
  37. syn cluster validTypeContains contains=goComment,goNewDeclType,goDeclTypeField,goDeclTypeFieldTypeW,goDeclTypeFieldSlice,goDeclTypeFieldPointerOp,goString,goRawString,OperatorChars,goContainer
  38. syn cluster validStructContains contains=goComment,goNewDeclType,goDeclTypeField,goDeclTypeFieldTypeW,goString,goRawString,OperatorChars,goContainer
  39. syn cluster validInterfaceContains contains=goComment,goFunctionTagLine,OperatorChars,goContainer
  40. syn match goTypeDecl /\<type\>/ nextgroup=goNewDeclType,goTypeRegion skipwhite skipnl
  41. syn region goTypeRegion matchgroup=goContainer start=/(/ end=/)/ contains=@validTypeContains fold contained
  42. syn region goDeclStructRegion matchgroup=goContainer start=/{/ end=/}/ contains=@validStructContains fold contained
  43. syn region goDeclInterfaceRegion matchgroup=goContainer start=/{/ end=/}/ contains=@validInterfaceContains fold contained
  44. syn match goDeclTypeFieldPointerOp /\*/ nextgroup=goDeclTypeFieldPointerOp,goDeclTypeFieldSlice,goDeclTypeFieldTypeW,goDeclStruct,goDeclInterface skipwhite contained
  45. syn region goDeclTypeFieldSlice matchgroup=goContainer start=/\[/ end=/\]/ contains=goDecimalInt,goHexadecimalInt,goOctalInt nextgroup=goDeclTypeFieldPointerOp,goDeclTypeFieldSlice,goDeclTypeFieldTypeW,goDeclStruct,goDeclInterface skipwhite contained
  46. " Match \w+\.\w+ but only highlight lone \w+ or (?>\.)\w+
  47. syn match goDeclTypeFieldTypeW /\%(\w\+\.\)\?\w\+/ contains=goDeclTypeFieldTypeNS,goDeclTypeFieldType,ContainerChars,OperatorChars skipwhite contained
  48. syn match goDeclTypeFieldType /\w\+/ contained
  49. syn match goDeclTypeFieldTypeNS /\w\+\%(\.\)\@=/ contained
  50. syn match goDeclTypeField /\w\+/ nextgroup=goDeclTypeFieldPointerOp,goDeclTypeFieldSlice,goDeclTypeFieldTypeW 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. " Order is important, so redefine
  56. syn match goBuiltins /\<\v(append|cap|close|complex|copy|delete|imag|len)\ze\(/
  57. syn match goBuiltins /\<\v(make|new|panic|print|println|real|recover)\ze\(/
  58. hi link goPointerOperator Operator
  59. hi link goDeclTypeFieldPointerOp Operator
  60. hi link goTypeConstructor Type
  61. hi link goTypeOpen goContainer
  62. hi link goDeclTypeFieldType Type
  63. hi link goNewDeclType Type
  64. hi link goDeclInterface Keyword
  65. hi link goDeclStruct Keyword
  66. hi link goFunction Function
  67. hi link goMethodCall Function
  68. hi link goFunctionCall Function
  69. hi link goContainer ContainerChars