go.vim 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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
  20. syn cluster validStructContains contains=goComment,goNewDeclType,goDeclTypeField,goString,goRawString
  21. syn cluster validInterfaceContains contains=goComment,goFunction,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 and could be better
  28. syn cluster goDeclTypeContains contains=goDeclTypeNS,goDeclTypeType,goMapKeyRegion,ContainerChars,OperatorChars,goDeclaration,goDeclStruct,goDeclInterface,goExtraType
  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. " NOTE: I think fixing goDeclTypeW would fix mismatched brackets
  33. syn match goDeclTypeType /\w\+/ contains=@goNumber nextgroup=goMapKeyRegion skipwhite contained
  34. syn region goMapKeyRegion matchgroup=goContainer start=/\[/ end=/\]/ contains=goDeclTypeW,ContainerChars nextgroup=goDeclTypeW skipwhite contained
  35. syn match goDeclTypeNS /\w\+\(\.\)\@1=/ skipwhite contained
  36. syn keyword goMapType map nextgroup=goMapKeyRegion
  37. syn match goDeclTypeFieldPointerOp /\*/ nextgroup=goDeclTypeFieldPointerOp,goDeclTypeFieldSlice,goDeclTypeW,goDeclStruct,goDeclInterface skipwhite contained
  38. syn region goDeclTypeFieldSlice matchgroup=goContainer start=/\[/ end=/\]/ nextgroup=goDeclTypeFieldPointerOp,goDeclTypeFieldSlice,goDeclTypeW,goDeclStruct,goDeclInterface skipwhite transparent contained
  39. syn match goDeclTypeField /\w\+/ nextgroup=goDeclTypeW skipwhite contained
  40. " This is important in order to differentiate "field type" from "field struct"
  41. " and "field interface"
  42. syn match goNewDeclType /\w\+\(\s\([*\[\] ]\)*\<\(struct\|interface\)\>\)\@=/ nextgroup=goDeclTypeFieldPointerOp,goDeclTypeFieldSlice,goDeclStruct,goDeclInterface skipwhite contained
  43. syn match goDeclStruct /\<struct\>/ nextgroup=goDeclStructRegion skipwhite skipnl
  44. syn match goDeclInterface /\<interface\>/ nextgroup=goDeclInterfaceRegion skipwhite skipnl
  45. syn match goVarVar /[^, ]\+/ nextgroup=goVarSep,goDeclTypeW skipwhite contained
  46. syn match goVarSep /,/ nextgroup=goVarVar skipwhite contained
  47. " TODO:
  48. syn region goVarRegion matchgroup=goContainer start=/(/ end=/)/ transparent contained
  49. syn keyword goVarDecl var nextgroup=goVarVar,goVarRegion skipwhite
  50. " NOTE: incomplete, but good enough for now
  51. syn region goTypeAssertionRegion matchgroup=goContainer start=/(/ end=/)/ contains=goDeclTypeW skipwhite contained
  52. syn match goTypeAssertionOp /\.\((\)\@=/ nextgroup=goTypeAssertionRegion skipwhite
  53. endif
  54. if !exists("g:go_highlight_functions")
  55. let g:go_highlight_functions = 0
  56. endif
  57. if g:go_highlight_functions != 0
  58. syn clear goFunctionCall
  59. syn clear goFunction
  60. syn clear goReceiverType
  61. syn match goFunctionCall /\(\.\)\@1<!\w\+\((\)\@1=/ nextgroup=goFuncMethCallRegion
  62. " This works but much like everything else, it is quite fragile. It doesn't
  63. " handle inline interfaces or structs (but should it, really?). Though, that
  64. " is probably more because of the terrible goDeclTypeW.. who knows...
  65. " Whatever.. it seems to fit 98% of my use cases
  66. " NOTE: I think fixing goDeclTypeW would fix inlined interface/structs
  67. syn match listOfTypes /\(\S\+\ze[,)]\)\+/ contains=goDeclTypeW,ContainerChars contained
  68. syn match listOfVars /\([,(]\s*\)\@<=\w\+\(\(, \w\+\)*, \w\+ \)\@=/ contained
  69. " TODO: change to "does not start with , or {"
  70. syn match goFunctionReturn /[^{, ]\+/ contains=goDeclaration,goDeclTypeW skipwhite contained
  71. " NOTE: I think fixing goDeclTypeW would the need for "keepend extend"
  72. " Also transparent might help... (use only contains=listOfTypes,listOfVars ?)
  73. syn region goFunctionParamRegion matchgroup=goContainer start=/(/ end=/)/ contains=goDeclaration,listOfTypes,listOfVars,ContainerChars,OperatorChars nextgroup=goFunctionReturn,goFunctionReturnRegion skipwhite keepend extend contained
  74. syn region goFunctionReturnRegion matchgroup=goContainer start=/(/ end=/)/ contains=goDeclaration,listOfTypes,listOfVars,ContainerChars,OperatorChars skipwhite keepend extend contained
  75. syn match goFunction /\w\+\((\)\@1=/ nextgroup=goFunctionParamRegion skipwhite contained
  76. syn match goDeclaration /\<func\>/ nextgroup=goReceiverRegion,goFunction,goFunctionParamRegion skipwhite skipnl
  77. " Use the space between func and ( to determine if the next group is a
  78. " receiver or an inlined function (which matches gofmt)
  79. syn region goReceiverRegion matchgroup=goContainer start=/ (/ end=/)/ contains=goReceiver nextgroup=goFunction skipwhite contained
  80. syn match goReceiver /\(\w\|[ *]\)\+/ contains=goReceiverVar,goPointerOperator skipwhite skipnl contained
  81. syn match goReceiverVar /\w\+/ nextgroup=goPointerOperator,goDeclTypeW skipwhite skipnl contained
  82. syn match goPointerOperator /\*/ nextgroup=goDeclTypeW skipwhite skipnl contained
  83. endif
  84. if !exists("g:go_highlight_methods")
  85. let g:go_highlight_methods = 0
  86. endif
  87. if g:go_highlight_methods != 0
  88. syn clear goMethodCall
  89. syn match goMethodCall /\(\.\)\@1<=\w\+\((\)\@1=/ nextgroup=goFuncMethCallRegion
  90. endif
  91. syn region goFuncMethCallRegion matchgroup=goContainer start=/(/ end=/)/ contained transparent
  92. syn match goLiteralStructField /\w\+\ze:[^=]/
  93. " Order is important, so redefine
  94. syn match goBuiltins /\<\(append\|cap\|close\|complex\|copy\|delete\|imag\|len\)\((\)\@=/ nextgroup=goBuiltinRegion
  95. syn match goBuiltins /\<\(make\|new\|panic\|print\|println\|real\|recover\)\((\)\@=/ nextgroup=goBuiltinRegion
  96. syn region goBuiltinRegion matchgroup=goContainer start=/(/ end=/)/ transparent contained
  97. hi link goPointerOperator Operator
  98. hi link goDeclTypeFieldPointerOp Operator
  99. hi link goTypeAssertionOp Operator
  100. hi link goTypeConstructor Type
  101. hi link goTypeOpen goContainer
  102. hi link goDeclTypeFieldType Type
  103. hi link goNewDeclType Type
  104. hi link goDeclTypeType Type
  105. hi link goTypeVar Type
  106. hi link goNestedInterfaceType Type
  107. hi link goVarDecl goDeclaration
  108. hi link goVarSep Operator
  109. hi link goDeclInterface goDeclaration
  110. hi link goDeclStruct goDeclaration
  111. hi link goFunction Function
  112. hi link goMethodCall Function
  113. hi link goFunctionCall Function
  114. hi link goContainer ContainerChars
  115. hi link goLiteralStructField Special