go.vim 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. " This is most likely bad... probably very bad.. and brittle?
  15. " mostly, it's incomplete but kinda matches gofmt, so theres that at least
  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,goNestedInterfaceType
  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 goNestedInterfaceType /\w\+/ contained
  27. " I think I hate this
  28. syn cluster goDeclTypeContains contains=goDeclTypeNS,goDeclTypeType,goDeclTypeMapType,goDeclTypeMap,ContainerChars,OperatorChars,goDeclaration,goDeclStruct,goDeclInterface
  29. " Match \w+\.\w+ but only highlight lone \w+ or (?>\.)\w+
  30. syn match goDeclTypeW /\(\[.*\]\|\*\)*\(\w\+\.\)\?\w\+\(\[.*\]\S\+\)\?/ contains=@goDeclTypeContains skipwhite contained
  31. " this is actually horribly broken for nested maps but appears to work.. 🤷
  32. syn match goDeclTypeType /\w\+/ contains=@goNumber nextgroup=goDeclTypeMap skipwhite contained
  33. syn region goDeclTypeMap matchgroup=goContainer start=/\[/ end=/\]/ contains=goDeclTypeW,ContainerChars nextgroup=goDeclTypeW skipwhite contained
  34. syn match goDeclTypeNS /\w\+\(\.\)\@1=/ skipwhite contained
  35. syn match goDeclTypeFieldPointerOp /\*/ nextgroup=goDeclTypeFieldPointerOp,goDeclTypeFieldSlice,goDeclTypeW,goDeclStruct,goDeclInterface skipwhite contained
  36. syn region goDeclTypeFieldSlice matchgroup=goContainer start=/\[/ end=/\]/ contains=goDecimalInt,goHexadecimalInt,goOctalInt nextgroup=goDeclTypeFieldPointerOp,goDeclTypeFieldSlice,goDeclTypeW,goDeclStruct,goDeclInterface skipwhite keepend contained
  37. syn match goDeclTypeField /\w\+/ nextgroup=goDeclTypeW skipwhite contained
  38. syn match goNewDeclType /\w\+\(\s\([*\[\] ]\)*\<\(struct\|interface\)\>\)\@=/ nextgroup=goDeclTypeFieldPointerOp,goDeclTypeFieldSlice,goDeclStruct,goDeclInterface skipwhite contained
  39. syn match goDeclStruct /\<struct\>/ nextgroup=goDeclStructRegion skipwhite skipnl
  40. syn match goDeclInterface /\<interface\>/ nextgroup=goDeclInterfaceRegion skipwhite skipnl
  41. syn match goVarVar /[^, ]\+/ nextgroup=goVarSep,goDeclTypeW skipwhite contained
  42. syn match goVarSep /,/ nextgroup=goVarVar skipwhite contained
  43. syn keyword goVarDecl var nextgroup=goVarVar skipwhite
  44. endif
  45. if !exists("g:go_highlight_functions")
  46. let g:go_highlight_functions = 0
  47. endif
  48. if g:go_highlight_functions != 0
  49. syn clear goFunctionCall
  50. syn clear goFunction
  51. syn clear goReceiverType
  52. syn match goFunctionCall /\(\.\)\@1<!\w\+\((\)\@1=/
  53. syn match goFunctionTagLine /\w\+(.*)\s*\((.*)\|\S\+\)\?/ nextgroup=goFunction contains=goFunction,goDeclaration,goFunctionParamRegion,goFunctionReturnRegion,goFunctionReturn,OperatorChars,ContainerChars,goComment contained
  54. " This works but much like everything else, it is quite fragile. It doesn't
  55. " handle inline interfaces or structs (but should it, really?). Though, that
  56. " is probably more because of the terrible goDeclTypeW.. who knows...
  57. " Whatever.. it seems to fit 98% of my use cases
  58. syn match listOfTypes /\(\S\+\ze[,)]\)\+/ contains=goDeclTypeW,ContainerChars contained
  59. syn match listOfVars /\(, \|(\)\@<=\w\+\(\(, \w\+\)*, \w\+ \)\@=/ contained
  60. syn match goFunctionReturn /[^{, ]\+/ contains=goDeclaration,goDeclTypeW skipwhite contained
  61. syn region goFunctionParamRegion matchgroup=goContainer start=/(/ end=/)/ contains=goDeclaration,listOfTypes,listOfVars,ContainerChars,OperatorChars nextgroup=goFunctionReturn,goFunctionReturnRegion skipwhite contained
  62. syn region goFunctionReturnRegion matchgroup=goContainer start=/(/ end=/)/ contains=goDeclaration,listOfTypes,listOfVars,ContainerChars,OperatorChars skipwhite contained
  63. syn match goFunction /\w\+\((\)\@1=/ nextgroup=goFunctionParamRegion skipwhite contained
  64. syn match goDeclaration /\<func\>/ nextgroup=goReceiverRegion,goFunction,goFunctionParamRegion skipwhite skipnl
  65. " Use the space between func and ( to determine if the next group is a
  66. " receiver or an inlined function
  67. syn region goReceiverRegion matchgroup=goContainer start=/ (/ end=/)/ contains=goReceiver nextgroup=goFunction skipwhite contained
  68. syn match goReceiver /\(\w\|[ *]\)\+/ contains=goReceiverVar,goPointerOperator skipwhite skipnl contained
  69. syn match goReceiverVar /\w\+/ nextgroup=goPointerOperator,goDeclTypeW skipwhite skipnl contained
  70. syn match goPointerOperator /\*/ nextgroup=goDeclTypeW skipwhite skipnl contained
  71. endif
  72. if !exists("g:go_highlight_methods")
  73. let g:go_highlight_methods = 0
  74. endif
  75. if g:go_highlight_methods != 0
  76. syn clear goMethodCall
  77. syn match goMethodCall /\(\.\)\@1<=\w\+\((\)\@1=/
  78. endif
  79. " Order is important, so redefine
  80. syn match goBuiltins /\<\v(append|cap|close|complex|copy|delete|imag|len)\ze\(/
  81. syn match goBuiltins /\<\v(make|new|panic|print|println|real|recover)\ze\(/
  82. hi link goPointerOperator Operator
  83. hi link goDeclTypeFieldPointerOp Operator
  84. hi link goTypeConstructor Type
  85. hi link goTypeOpen goContainer
  86. hi link goDeclTypeFieldType Type
  87. hi link goNewDeclType Type
  88. hi link goDeclTypeType Type
  89. hi link goTypeVar Type
  90. hi link goNestedInterfaceType Type
  91. hi link goVarDecl goDeclaration
  92. hi link goVarSep Operator
  93. hi link goDeclInterface goDeclaration
  94. hi link goDeclStruct goDeclaration
  95. hi link goFunction Function
  96. hi link goMethodCall Function
  97. hi link goFunctionCall Function
  98. hi link goContainer ContainerChars