go.vim 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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 goDeclaration /\<func\>/ nextgroup=goReceiverRegion,goFunction skipwhite skipnl
  45. syn region goReceiverRegion matchgroup=goContainer start=/(/ end=/)/ contains=goReceiver nextgroup=goFunction contained
  46. syn match goReceiver /\(\w\|[ *]\)\+/ contained contains=goReceiverVar,goPointerOperator skipwhite skipnl contained
  47. syn match goReceiverVar /\w\+/ nextgroup=goPointerOperator,goReceiverType skipwhite skipnl contained
  48. syn match goPointerOperator /\*/ nextgroup=goReceiverType contained skipwhite skipnl
  49. syn match goReceiverType /\w\+/ contained
  50. "TODO: add goDeclTypeW
  51. syn cluster validFuncRegionContains contains=@goTypes,goField,goDeclaration,GoBuiltins,goDeclStruct,goDeclInterface,OperatorChars,ContainerChars,goString,goRawString,@goNumber,goTypeConstructor,goMethodCall
  52. syn match goFunctionTagLine /\w\+(.*)\(\s*(.*)\|\s\S\+\)\?/ nextgroup=goFunction contains=goFunction,goFunctionParamRegion,goFunctionReturnRegion,goFunctionReturn,OperatorChars,ContainerChars,goComment
  53. syn region goFunctionParamRegion matchgroup=goContainer start=/(/ end=/)/ contains=@validFuncRegionContains nextgroup=goFunctionReturnRegion,goFunctionReturn skipwhite keepend contained
  54. syn region goFunctionReturnRegion matchgroup=goContainer start=/(/ end=/)/ contains=@validFuncRegionContains skipwhite keepend contained
  55. syn match goFunctionReturn /\w\+/ contains=@validFuncRegionContains skipwhite contained
  56. syn match goFunction /\w\+\((\)\@1=/ nextgroup=goFunctionParamRegion skipwhite contained
  57. syn match goFunctionCall /\(\.\)\@1<!\w\+\((\)\@1=/
  58. endif
  59. if g:go_highlight_methods != 0
  60. syn clear goMethodCall
  61. syn match goMethodCall /\(\.\)\@1<=\w\+\((\)\@1=/
  62. endif
  63. " Order is important, so redefine
  64. syn match goBuiltins /\<\v(append|cap|close|complex|copy|delete|imag|len)\ze\(/
  65. syn match goBuiltins /\<\v(make|new|panic|print|println|real|recover)\ze\(/
  66. hi link goPointerOperator Operator
  67. hi link goDeclTypeFieldPointerOp Operator
  68. hi link goTypeConstructor Type
  69. hi link goTypeOpen goContainer
  70. hi link goDeclTypeFieldType Type
  71. hi link goNewDeclType Type
  72. hi link goDeclTypeType Type
  73. hi link goDeclInterface Keyword
  74. hi link goDeclStruct Keyword
  75. hi link goFunction Function
  76. hi link goMethodCall Function
  77. hi link goFunctionCall Function
  78. hi link goContainer ContainerChars