go.vim 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. if !exists("g:go_highlight_fields")
  2. let g:go_highlight_fields = 0
  3. endif
  4. if g:go_highlight_fields != 0
  5. syn match goField /\(\.\)\@1<=\w\+\([.\ \n\r\:\)\[,+-\*}\\\]]\)\@=/
  6. endif
  7. " Order matters...
  8. if !exists("g:go_highlight_functions")
  9. let g:go_highlight_functions = 0
  10. endif
  11. if g:go_highlight_functions != 0
  12. " FIXME: This is too greedy
  13. syn match listOfTypes /\([^ ,)]\+\(,\|)\)\@=\)\+/ contains=@goDeclarations,@goDeclTypeBegin,goMapKeyRegion,goFunctionParamRegion,goFunctionReturnRegion,goDeclStructRegion,goDeclInterfaceRegion contained
  14. syn match listOfVars /\([,(]\s*\)\@<=\w\+\(\(, \w\+\)*, \w\+ \)\@=/ contained
  15. endif
  16. if !exists("g:go_highlight_types")
  17. let g:go_highlight_types = 0
  18. endif
  19. if g:go_highlight_types != 0
  20. syn clear goTypeDecl
  21. syn clear goTypeName
  22. syn clear goDeclType
  23. syn match goTypeConstructor /\<\w\+\({\)\@1=/
  24. syn cluster validTypeContains contains=goComment,goDeclSIName,goDeclTypeField,goDeclTypeName
  25. " FIXME: not sure I _need_ to state goDecl*Region
  26. syn cluster validStructContains contains=goComment,goDeclSIName,goDeclTypeField,goDeclTypeSep,@goDeclEmbeddedType,goString,goRawString,goMapType,goMapKeyRegion,goDeclStructRegion,goDeclInterfaceRegion,goPointerOperator
  27. syn cluster validInterfaceContains contains=goComment,goFunction,@goDeclEmbeddedType,goDeclInterfaceRegion
  28. syn match goDeclTypeField /\w\+/ nextgroup=goDeclTypeSep,@goDeclTypeBegin skipwhite contained
  29. syn match goDeclTypeSep /,/ nextgroup=goDeclTypeField skipwhite contained
  30. syn match goDeclEmbeddedType /\w\+\s*\($\|\/\)\@=/ skipwhite contained
  31. syn match goDeclEmbeddedTypeNS /\w\+\.\(\w\+\)\@=/ contains=OperatorChars nextgroup=goDeclEmbeddedType skipwhite contained
  32. syn match goDeclTypeName /\w\+/ nextgroup=@goDeclTypeBegin skipwhite contained
  33. syn cluster goDeclEmbeddedType contains=goDeclEmbeddedType,goDeclEmbeddedTypeNS
  34. syn match goTypeDecl /\<type\>/ nextgroup=goDeclTypeName,goTypeRegion skipwhite skipnl
  35. syn region goTypeRegion matchgroup=goContainer start=/(/ end=/)/ contains=@validTypeContains skipwhite fold contained
  36. syn region goDeclStructRegion matchgroup=goContainer start=/{/ end=/}/ contains=@validStructContains skipwhite fold contained
  37. syn region goDeclInterfaceRegion matchgroup=goContainer start=/{/ end=/}/ contains=@validInterfaceContains skipwhite fold contained
  38. syn match goDeclTypeStart /\*/ contains=OperatorChars nextgroup=goDeclTypeStart,goDeclTypeNamespace,goDeclTypeType,goMapType,@goDeclarations skipwhite contained
  39. syn region goDeclTypeStart matchgroup=goContainer start=/\[/ end=/\]/ contains=@goNumbers nextgroup=goDeclTypeStart,goDeclTypeNamespace,goDeclTypeType,goMapType,@goDeclarations skipwhite transparent contained
  40. syn match goDeclTypeType /\w\+/ contains=goMapType,@goDeclarations skipwhite contained
  41. syn match goDeclTypeNamespace /\w\+\./ contains=OperatorChars nextgroup=goDeclTypeType skipwhite contained
  42. syn cluster goDeclTypeBegin contains=goDeclTypeStart,goDeclTypeType,goDeclTypeNamespace,goDeclaration,goMapType,goDeclStruct,goDeclInterface
  43. syn region goMapKeyRegion matchgroup=goContainer start=/\[/ end=/\]/ contains=@goDeclTypeBegin,goDeclaration nextgroup=@goDeclTypeBegin skipwhite contained
  44. syn keyword goMapType map nextgroup=goMapKeyRegion skipwhite
  45. " This is important in order to differentiate "field type" from "field struct"
  46. " and "field interface"
  47. " FIXME: seems fishy, see @validStructContains
  48. syn match goDeclSIName /\w\+\(\s\([*\[\] ]\)*\<\(struct\|interface\)\>\)\@=/ nextgroup=@goDeclTypeBegin,goDeclStruct,goDeclInterface skipwhite contained
  49. syn match goDeclStruct /\<struct\>/ nextgroup=goDeclStructRegion skipwhite skipnl
  50. syn match goDeclInterface /\<interface\>/ nextgroup=goDeclInterfaceRegion skipwhite skipnl
  51. syn match goVarName /[^, ]\+/ nextgroup=goVarSep,@goDeclTypeBegin,goMapType skipwhite contained
  52. syn match goVarSep /,/ nextgroup=goVarName skipwhite contained
  53. syn region goVarRegion matchgroup=goContainer start=/(/ end=/)/ transparent contained
  54. syn keyword goVarDecl var nextgroup=goVarName,goVarRegion skipwhite
  55. syn region goTypeAssertionRegion matchgroup=goContainer start=/(/ end=/)/ contains=@goDeclTypeBegin,goMapType,goMapKeyRegion skipwhite contained
  56. syn match goTypeAssertionOp /\.\((\)\@=/ nextgroup=goTypeAssertionRegion skipwhite
  57. endif
  58. if g:go_highlight_functions != 0
  59. syn clear goFunctionCall
  60. syn clear goFunction
  61. syn clear goReceiverType
  62. syn match goFunctionCall /\(\.\)\@1<!\w\+\((\)\@1=/ nextgroup=goFuncMethCallRegion
  63. " FIXME: [^,()] is a lazy hack-fix that works in-tandem with listOfTypes
  64. syn match goFunctionReturn /[^,()]\{-}\({\|\/\|$\)\@=/ contains=@goDeclarations,@goDeclTypeBegin,goComment skipwhite contained
  65. syn region goFunctionParamRegion matchgroup=goContainer start=/(/ end=/)/ contains=@goDeclarations,listOfTypes,listOfVars,OperatorChars nextgroup=goFunctionReturn,goFunctionReturnRegion skipwhite transparent contained
  66. syn region goFunctionReturnRegion matchgroup=goContainer start=/(/ end=/)/ contains=@goDeclarations,listOfTypes,listOfVars,OperatorChars skipwhite transparent contained
  67. syn match goFunction /\w\+\((\)\@1=/ nextgroup=goFunctionParamRegion skipwhite contained
  68. syn match goDeclaration /\<func\>/ nextgroup=goReceiverRegion,goFunction,goFunctionParamRegion skipwhite skipnl
  69. " Use the space between func and ( to determine if the next group is a
  70. " receiver or an inlined function (which matches gofmt)
  71. syn region goReceiverRegion matchgroup=goContainer start=/ (/ end=/)/ contains=goReceiverVar,goPointerOperator,@goDeclTypeBegin nextgroup=goFunction skipwhite contained
  72. syn match goReceiverVar /\w\+ / nextgroup=goPointerOperator,@goDeclTypeBegin skipnl contained
  73. syn match goPointerOperator /\*/ nextgroup=@goDeclTypeBegin skipwhite skipnl contained
  74. endif
  75. if !exists("g:go_highlight_methods")
  76. let g:go_highlight_methods = 0
  77. endif
  78. if g:go_highlight_methods != 0
  79. syn clear goMethodCall
  80. syn match goMethodCall /\(\.\)\@1<=\w\+\((\)\@1=/ nextgroup=goFuncMethCallRegion
  81. endif
  82. syn cluster goDeclarations contains=goDeclaration,goDeclStruct,goDeclInterface
  83. syn cluster goTypes contains=goType,goSignedInts,goUnsignedInts,goFloats,goComplexes
  84. syn cluster goNumbers contains=goDecimalInt,goHexadecimalInt,goOctalInt,goFloat,goImaginary,goImaginaryFloat
  85. syn region goFuncMethCallRegion matchgroup=goContainer start=/(/ end=/)/ transparent contained
  86. syn match goLiteralStructField /\w\+\ze:[^=]/
  87. " Order is important, so redefine
  88. syn match goBuiltins /\<\(append\|cap\|close\|complex\|copy\|delete\|imag\|len\)\((\)\@=/ nextgroup=goBuiltinRegion
  89. syn match goBuiltins /\<\(make\|new\|panic\|print\|println\|real\|recover\)\((\)\@=/ nextgroup=goBuiltinRegion
  90. syn region goBuiltinRegion matchgroup=goContainer start=/(/ end=/)/ transparent contained
  91. hi link goPointerOperator Operator
  92. hi link goTypeAssertionOp Operator
  93. hi link goVarSep Operator
  94. hi link goDeclTypeSep Operator
  95. hi link goTypeConstructor Type
  96. hi link goDeclSIName Type
  97. hi link goDeclTypeType Type
  98. hi link goMapType Type
  99. hi link goDeclTypeName Type
  100. hi link goDeclEmbeddedType Type
  101. hi link goVarDecl goDeclaration
  102. hi link goDeclInterface goDeclaration
  103. hi link goDeclStruct goDeclaration
  104. hi link goFunction Function
  105. hi link goMethodCall Function
  106. hi link goFunctionCall Function
  107. hi link goContainer ContainerChars
  108. hi link goLiteralStructField Special