go.vim 5.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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_types")
  10. let g:go_highlight_types = 0
  11. endif
  12. if g:go_highlight_types != 0
  13. syn match goTypeConstructor /\<\w\+\({\)\@1=/
  14. " handle map[type]type
  15. " handle field, field type
  16. " This is most likely bad... probably very bad.. and brittle?
  17. syn clear goTypeDecl
  18. syn clear goTypeName
  19. syn clear goDeclType
  20. syn cluster validTypeContains contains=goComment,goNewDeclType,goDeclTypeField,goDeclTypeW,goDeclTypeFieldSlice,goDeclTypeFieldPointerOp,goString,goRawString,OperatorChars,goContainer
  21. syn cluster validStructContains contains=goComment,goNewDeclType,goDeclTypeField,goDeclTypeW,goString,goRawString,OperatorChars,goContainer
  22. syn cluster validInterfaceContains contains=goComment,goFunctionTagLine,OperatorChars,goContainer
  23. syn match goTypeDecl /\<type\>/ nextgroup=goNewDeclType,goTypeRegion skipwhite skipnl
  24. syn region goTypeRegion matchgroup=goContainer start=/(/ end=/)/ contains=@validTypeContains fold contained
  25. syn region goDeclStructRegion matchgroup=goContainer start=/{/ end=/}/ contains=@validStructContains fold contained
  26. syn region goDeclInterfaceRegion matchgroup=goContainer start=/{/ end=/}/ contains=@validInterfaceContains fold contained
  27. syn match goDeclTypeFieldPointerOp /\*/ nextgroup=goDeclTypeFieldPointerOp,goDeclTypeFieldSlice,goDeclTypeW,goDeclStruct,goDeclInterface skipwhite contained
  28. syn region goDeclTypeFieldSlice matchgroup=goContainer start=/\[/ end=/\]/ contains=goDecimalInt,goHexadecimalInt,goOctalInt nextgroup=goDeclTypeFieldPointerOp,goDeclTypeFieldSlice,goDeclTypeW,goDeclStruct,goDeclInterface skipwhite contained
  29. " Match \w+\.\w+ but only highlight lone \w+ or (?>\.)\w+
  30. syn match goDeclTypeW /\%(\w\+\.\)\?\w\+\(\[.*\]\S\+\)\?/ contains=goDeclTypeNS,goDeclTypeType,goDeclTypeMap,ContainerChars,OperatorChars,goDeclaration skipwhite contained
  31. syn match goDeclTypeType /\w\+/ nextgroup=goDeclTypeMap skipwhite contained
  32. syn region goDeclTypeMap matchgroup=goContainer start=/\[/ end=/\]/ contains=goDeclTypeW,ContainerChars,OperatorChars nextgroup=goDeclTypeW skipwhite keepend contained
  33. syn match goDeclTypeNS /\w\+\(\.\)\@1=/ skipwhite contained
  34. syn match goDeclTypeField /\w\+/ nextgroup=goDeclTypeFieldPointerOp,goDeclTypeFieldSlice,goDeclTypeW skipwhite contained
  35. syn match goNewDeclType /\w\+\ze\s\+\<\(struct\|interface\)\>/ nextgroup=goDeclStruct,goDeclInterface skipwhite contained
  36. syn match goDeclStruct /\<struct\>/ nextgroup=goDeclStructRegion skipwhite skipnl
  37. syn match goDeclInterface /\<interface\>/ nextgroup=goDeclInterfaceRegion skipwhite skipnl
  38. endif
  39. if !exists("g:go_highlight_functions")
  40. let g:go_highlight_functions = 0
  41. endif
  42. if g:go_highlight_functions != 0
  43. syn clear goFunctionCall
  44. syn clear goFunction
  45. syn match goDeclaration /\<func\>/ nextgroup=goReceiverRegion,goFunction skipwhite skipnl
  46. syn region goReceiverRegion matchgroup=goContainer start=/(/ end=/)/ contains=goReceiver nextgroup=goFunction contained
  47. syn match goReceiver /\(\w\|[ *]\)\+/ contained contains=goReceiverVar skipwhite skipnl contained
  48. syn cluster validFuncRegionContains contains=@goTypes,goField,goDeclaration,GoBuiltins,goDeclStruct,goDeclInterface,OperatorChars,goContainer,goString,goRawString,@goNumber,goTypeConstructor
  49. " fix comment
  50. syn match goFunctionTagLine /\w\+(.\{-})\(\s*(.\{-})\|\s\S\+\)\?\(\s*\|$\)/ nextgroup=goFunction contains=goFunction,goFunctionParamRegion,goFunctionReturnRegion,goFunctionReturn,OperatorChars,goContainer,goComment
  51. syn region goFunctionParamRegion matchgroup=goContainer start=/(/ end=/)/ contains=@validFuncRegionContains nextgroup=goFunctionReturnRegion,goFunctionReturn skipwhite contained
  52. syn region goFunctionReturnRegion matchgroup=goContainer start=/(/ end=/)/ contains=@validFuncRegionContains skipwhite contained
  53. syn match goFunctionReturn /\w\+/ contains=@validFuncRegionContains skipwhite contained
  54. syn match goFunction /\w\+\ze(/ nextgroup=goFunctionParamRegion skipwhite contained
  55. endif
  56. " Order is important, so redefine
  57. syn match goBuiltins /\<\v(append|cap|close|complex|copy|delete|imag|len)\ze\(/
  58. syn match goBuiltins /\<\v(make|new|panic|print|println|real|recover)\ze\(/
  59. hi link goPointerOperator Operator
  60. hi link goDeclTypeFieldPointerOp Operator
  61. hi link goTypeConstructor Type
  62. hi link goTypeOpen goContainer
  63. hi link goDeclTypeFieldType Type
  64. hi link goNewDeclType Type
  65. hi link goDeclTypeType Type
  66. hi link goDeclInterface Keyword
  67. hi link goDeclStruct Keyword
  68. hi link goFunction Function
  69. hi link goMethodCall Function
  70. hi link goFunctionCall Function
  71. hi link goContainer ContainerChars