go.vim 5.8 KB

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