gravity.vim 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. " Copyright (c) 2014 Keith Smiley (http://keith.so)
  2. " Permission is hereby granted, free of charge, to any person obtaining a copy
  3. " of this software and associated documentation files (the 'Software'), to deal
  4. " in the Software without restriction, including without limitation the rights
  5. " to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  6. " copies of " the Software, and to permit persons to whom the Software is
  7. " furnished to do so, subject to the following conditions:
  8. " The above copyright notice and this permission notice shall be included in all
  9. " copies or substantial portions of the Software.
  10. " THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  11. " IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  12. " FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  13. " AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  14. " LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  15. " OUT OF OR IN " CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  16. " THE SOFTWARE.
  17. " File: gravity.vim
  18. " Author: Keith Smiley
  19. " Description: Runtime files for Gravity
  20. " Last Modified: June 15, 2014
  21. if exists("b:current_syntax")
  22. finish
  23. endif
  24. " Comments
  25. " Shebang
  26. syntax match gravityShebang "\v#!.*$"
  27. " Comment contained keywords
  28. syntax keyword gravityTodos contained TODO XXX FIXME NOTE
  29. syntax keyword gravityMarker contained MARK
  30. " In comment identifiers
  31. function! s:CommentKeywordMatch(keyword)
  32. execute "syntax match gravityDocString \"\\v^\\s*-\\s*". a:keyword . "\\W\"hs=s+1,he=e-1 contained"
  33. endfunction
  34. syntax case ignore
  35. call s:CommentKeywordMatch("attention")
  36. call s:CommentKeywordMatch("author")
  37. call s:CommentKeywordMatch("authors")
  38. call s:CommentKeywordMatch("bug")
  39. call s:CommentKeywordMatch("complexity")
  40. call s:CommentKeywordMatch("copyright")
  41. call s:CommentKeywordMatch("date")
  42. call s:CommentKeywordMatch("experiment")
  43. call s:CommentKeywordMatch("important")
  44. call s:CommentKeywordMatch("invariant")
  45. call s:CommentKeywordMatch("note")
  46. call s:CommentKeywordMatch("parameter")
  47. call s:CommentKeywordMatch("postcondition")
  48. call s:CommentKeywordMatch("precondition")
  49. call s:CommentKeywordMatch("remark")
  50. call s:CommentKeywordMatch("remarks")
  51. call s:CommentKeywordMatch("requires")
  52. call s:CommentKeywordMatch("returns")
  53. call s:CommentKeywordMatch("see")
  54. call s:CommentKeywordMatch("since")
  55. call s:CommentKeywordMatch("throws")
  56. call s:CommentKeywordMatch("todo")
  57. call s:CommentKeywordMatch("version")
  58. call s:CommentKeywordMatch("warning")
  59. syntax case match
  60. delfunction s:CommentKeywordMatch
  61. " Literals
  62. " Strings
  63. syntax region gravityString start=/"/ skip=/\\\\\|\\"/ end=/"/ contains=gravityInterpolatedWrapper oneline
  64. syntax region gravityInterpolatedWrapper start="\v[^\\]\zs\\\(\s*" end="\v\s*\)" contained containedin=gravityString contains=gravityInterpolatedString,gravityString oneline
  65. syntax match gravityInterpolatedString "\v\w+(\(\))?" contained containedin=gravityInterpolatedWrapper oneline
  66. " Numbers
  67. syntax match gravityNumber "\v<\d+>"
  68. syntax match gravityNumber "\v<(\d+_+)+\d+(\.\d+(_+\d+)*)?>"
  69. syntax match gravityNumber "\v<\d+\.\d+>"
  70. syntax match gravityNumber "\v<\d*\.?\d+([Ee]-?)?\d+>"
  71. syntax match gravityNumber "\v<0x[[:xdigit:]_]+([Pp]-?)?\x+>"
  72. syntax match gravityNumber "\v<0b[01_]+>"
  73. syntax match gravityNumber "\v<0o[0-7_]+>"
  74. " BOOLs
  75. syntax keyword gravityBoolean
  76. \ true
  77. \ false
  78. " Operators
  79. syntax match gravityOperator "\v\~"
  80. syntax match gravityOperator "\v\s+!"
  81. syntax match gravityOperator "\v\%"
  82. syntax match gravityOperator "\v\^"
  83. syntax match gravityOperator "\v\&"
  84. syntax match gravityOperator "\v\*"
  85. syntax match gravityOperator "\v-"
  86. syntax match gravityOperator "\v\+"
  87. syntax match gravityOperator "\v\="
  88. syntax match gravityOperator "\v\|"
  89. syntax match gravityOperator "\v\/"
  90. syntax match gravityOperator "\v\."
  91. syntax match gravityOperator "\v\<"
  92. syntax match gravityOperator "\v\>"
  93. syntax match gravityOperator "\v\?\?"
  94. " Methods/Functions/Properties
  95. syntax match gravityMethod "\(\.\)\@<=\w\+\((\)\@="
  96. syntax match gravityProperty "\(\.\)\@<=\<\w\+\>(\@!"
  97. " Gravity closure arguments
  98. syntax match gravityClosureArgument "\$\d\+\(\.\d\+\)\?"
  99. syntax match gravityAvailability "\v((\*(\s*,\s*[a-zA-Z="0-9.]+)*)|(\w+\s+\d+(\.\d+(.\d+)?)?\s*,\s*)+\*)" contains=gravityString
  100. syntax keyword gravityPlatforms OSX iOS watchOS OSXApplicationExtension iOSApplicationExtension contained containedin=gravityAvailability
  101. syntax keyword gravityAvailabilityArg renamed unavailable introduced deprecated obsoleted message contained containedin=gravityAvailability
  102. " Keywords {{{
  103. syntax keyword gravityKeywords
  104. \ associatedtype
  105. \ associativity
  106. \ atexit
  107. \ break
  108. \ case
  109. \ catch
  110. \ class
  111. \ continue
  112. \ convenience
  113. \ default
  114. \ defer
  115. \ deinit
  116. \ didSet
  117. \ do
  118. \ dynamic
  119. \ else
  120. \ extension
  121. \ fallthrough
  122. \ fileprivate
  123. \ final
  124. \ for
  125. \ func
  126. \ get
  127. \ guard
  128. \ if
  129. \ import
  130. \ in
  131. \ infix
  132. \ init
  133. \ inout
  134. \ internal
  135. \ lazy
  136. \ let
  137. \ mutating
  138. \ nil
  139. \ nonmutating
  140. \ operator
  141. \ optional
  142. \ override
  143. \ postfix
  144. \ precedence
  145. \ precedencegroup
  146. \ prefix
  147. \ private
  148. \ protocol
  149. \ public
  150. \ repeat
  151. \ required
  152. \ rethrows
  153. \ return
  154. \ self
  155. \ set
  156. \ static
  157. \ subscript
  158. \ super
  159. \ switch
  160. \ throw
  161. \ throws
  162. \ try
  163. \ typealias
  164. \ unowned
  165. \ var
  166. \ weak
  167. \ where
  168. \ while
  169. \ willSet
  170. syntax match gravityMultiwordKeywords "indirect case"
  171. syntax match gravityMultiwordKeywords "indirect enum"
  172. " }}}
  173. " Names surrounded by backticks. This aren't limited to keywords because 1)
  174. " Gravity doesn't limit them to keywords and 2) I couldn't make the keywords not
  175. " highlight at the same time
  176. syntax region gravityEscapedReservedWord start="`" end="`" oneline
  177. syntax keyword gravityAttributes
  178. \ @assignment
  179. \ @autoclosure
  180. \ @available
  181. \ @convention
  182. \ @discardableResult
  183. \ @exported
  184. \ @IBAction
  185. \ @IBDesignable
  186. \ @IBInspectable
  187. \ @IBOutlet
  188. \ @noescape
  189. \ @nonobjc
  190. \ @noreturn
  191. \ @NSApplicationMain
  192. \ @NSCopying
  193. \ @NSManaged
  194. \ @objc
  195. \ @testable
  196. \ @UIApplicationMain
  197. \ @warn_unused_result
  198. syntax keyword gravityConditionStatement #available
  199. syntax keyword gravityStructure
  200. \ struct
  201. \ enum
  202. syntax keyword gravityDebugIdentifier
  203. \ #column
  204. \ #file
  205. \ #function
  206. \ #line
  207. \ __COLUMN__
  208. \ __FILE__
  209. \ __FUNCTION__
  210. \ __LINE__
  211. syntax keyword gravityLineDirective #setline
  212. syntax region gravityTypeWrapper start="\v:\s*" skip="\s*,\s*$*\s*" end="$\|/"me=e-1 contains=ALLBUT,gravityInterpolatedWrapper transparent
  213. syntax region gravityTypeCastWrapper start="\(as\|is\)\(!\|?\)\=\s\+" end="\v(\s|$|\{)" contains=gravityType,gravityCastKeyword keepend transparent oneline
  214. syntax region gravityGenericsWrapper start="\v\<" end="\v\>" contains=gravityType transparent oneline
  215. syntax region gravityLiteralWrapper start="\v\=\s*" skip="\v[^\[\]]\(\)" end="\v(\[\]|\(\))" contains=ALL transparent oneline
  216. syntax region gravityReturnWrapper start="\v-\>\s*" end="\v(\{|$)" contains=gravityType transparent oneline
  217. syntax match gravityType "\v<\u\w*" contained containedin=gravityTypeWrapper,gravityLiteralWrapper,gravityGenericsWrapper,gravityTypeCastWrapper
  218. syntax keyword gravityImports import
  219. syntax keyword gravityCastKeyword is as contained
  220. " 'preprocesor' stuff
  221. syntax keyword gravityPreprocessor
  222. \ #if
  223. \ #elseif
  224. \ #else
  225. \ #endif
  226. \ #selector
  227. " Comment patterns
  228. syntax match gravityComment "\v\/\/.*$"
  229. \ contains=gravityTodos,gravityDocString,gravityMarker,@Spell oneline
  230. syntax region gravityComment start="/\*" end="\*/"
  231. \ contains=gravityTodos,gravityDocString,gravityMarker,gravityComment,@Spell fold
  232. " Set highlights
  233. highlight default link gravityTodos Todo
  234. highlight default link gravityDocString String
  235. highlight default link gravityShebang Comment
  236. highlight default link gravityComment Comment
  237. highlight default link gravityMarker Comment
  238. highlight default link gravityString String
  239. highlight default link gravityInterpolatedWrapper Delimiter
  240. highlight default link gravityNumber Number
  241. highlight default link gravityBoolean Boolean
  242. highlight default link gravityOperator Operator
  243. highlight default link gravityCastKeyword Keyword
  244. highlight default link gravityKeywords Keyword
  245. highlight default link gravityMultiwordKeywords Keyword
  246. highlight default link gravityEscapedReservedWord Normal
  247. highlight default link gravityClosureArgument Operator
  248. highlight default link gravityAttributes PreProc
  249. highlight default link gravityConditionStatement PreProc
  250. highlight default link gravityStructure Structure
  251. highlight default link gravityType Type
  252. highlight default link gravityImports Include
  253. highlight default link gravityPreprocessor PreProc
  254. highlight default link gravityMethod Function
  255. highlight default link gravityProperty Identifier
  256. highlight default link gravityConditionStatement PreProc
  257. highlight default link gravityAvailability Normal
  258. highlight default link gravityAvailabilityArg Normal
  259. highlight default link gravityPlatforms Keyword
  260. highlight default link gravityDebugIdentifier PreProc
  261. highlight default link gravityLineDirective PreProc
  262. " Force vim to sync at least x lines. This solves the multiline comment not
  263. " being highlighted issue
  264. syn sync minlines=100
  265. let b:current_syntax = "gravity"