go.vim 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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 contained
  25. syn region goDeclInterfaceRegion matchgroup=goContainer start=/{/ end=/}/ contains=@validInterfaceContains fold contained
  26. syn match goDeclTypeFieldPointerOp /\*/ nextgroup=goDeclTypeFieldPointerOp,goDeclTypeFieldSlice,goDeclTypeW,goDeclStruct,goDeclInterface skipwhite contained
  27. syn region goDeclTypeFieldSlice matchgroup=goContainer start=/\[/ end=/\]/ contains=goDecimalInt,goHexadecimalInt,goOctalInt nextgroup=goDeclTypeFieldPointerOp,goDeclTypeFieldSlice,goDeclTypeW,goDeclStruct,goDeclInterface skipwhite contained
  28. " Match \w+\.\w+ but only highlight lone \w+ or (?>\.)\w+
  29. syn match goDeclTypeW /\%(\w\+\.\)\?\w\+\(\[.*\]\S\+\)\?/ contains=goDeclTypeNS,goDeclTypeType,goDeclTypeMap,ContainerChars,OperatorChars,goDeclaration skipwhite contained
  30. syn match goDeclTypeType /\w\+/ nextgroup=goDeclTypeMap skipwhite contained
  31. syn region goDeclTypeMap matchgroup=goContainer start=/\[/ end=/\]/ contains=goDeclTypeW,ContainerChars,OperatorChars nextgroup=goDeclTypeW skipwhite keepend contained
  32. syn match goDeclTypeNS /\w\+\(\.\)\@1=/ skipwhite 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 match goFunctionCall /\(\.\)\@1<!\w\+\((\)\@1=/
  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,goPointerOperator skipwhite skipnl contained
  48. syn match goReceiverVar /\w\+/ nextgroup=goPointerOperator,goReceiverType skipwhite skipnl contained
  49. syn match goPointerOperator /\*/ nextgroup=goReceiverType contained skipwhite skipnl
  50. syn match goReceiverType /\w\+/ contained
  51. "TODO: add goDeclTypeW
  52. syn cluster validFuncRegionContains contains=@goTypes,goField,goDeclaration,GoBuiltins,goDeclStruct,goDeclInterface,OperatorChars,ContainerChars,goString,goRawString,@goNumber,goTypeConstructor,goMethodCall
  53. syn match goFunctionTagLine /\w\+(.*)\(\s*(.*)\|\s\S\+\)\?/ nextgroup=goFunction contains=goFunction,goFunctionParamRegion,goFunctionReturnRegion,goFunctionReturn,OperatorChars,ContainerChars,goComment
  54. syn region goFunctionParamRegion matchgroup=goContainer start=/(/ end=/)/ contains=@validFuncRegionContains nextgroup=goFunctionReturnRegion,goFunctionReturn skipwhite keepend contained
  55. syn region goFunctionReturnRegion matchgroup=goContainer start=/(/ end=/)/ contains=@validFuncRegionContains skipwhite keepend contained
  56. syn match goFunctionReturn /\w\+/ contains=@validFuncRegionContains skipwhite contained
  57. syn match goFunction /\w\+\((\)\@1=/ nextgroup=goFunctionParamRegion skipwhite contained
  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