cabal.vim 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. " Vim syntax file
  2. " Language: Haskell Cabal Build file
  3. " Author: Vincent Berthoux <twinside@gmail.com>
  4. " Maintainer: Marcin Szamotulski <profunctor@pm.me>
  5. " Previous Maintainer: Vincent Berthoux <twinside@gmail.com>
  6. " File Types: .cabal
  7. " Last Change: 21 Nov 2020
  8. " v1.5: Incorporated changes from
  9. " https://github.com/sdiehl/haskell-vim-proto/blob/master/vim/syntax/cabal.vim
  10. " Use `syn keyword` instead of `syn match`.
  11. " Added cabalStatementRegion to limit matches of keywords, which fixes
  12. " the highlighting of description's value.
  13. " Added cabalVersionRegion to limit the scope of cabalVersionOperator
  14. " and cabalVersion matches.
  15. " Added cabalLanguage keyword.
  16. " Added calbalTitle, cabalAuthor and cabalMaintainer syntax groups.
  17. " Added ! and ^>= operators (calbal 2.0)
  18. " Added build-type keywords
  19. " v1.4: Add benchmark support, thanks to Simon Meier
  20. " v1.3: Updated to the last version of cabal
  21. " Added more highlighting for cabal function, true/false
  22. " and version number. Also added missing comment highlighting.
  23. " Cabal known compiler are highlighted too.
  24. "
  25. " V1.2: Added cpp-options which was missing. Feature implemented
  26. " by GHC, found with a GHC warning, but undocumented.
  27. " Whatever...
  28. "
  29. " v1.1: Fixed operator problems and added ftdetect file
  30. " (thanks to Sebastian Schwarz)
  31. "
  32. " v1.0: Cabal syntax in vimball format
  33. " (thanks to Magnus Therning)
  34. " quit when a syntax file was already loaded
  35. if exists("b:current_syntax")
  36. finish
  37. endif
  38. " this file uses line continuation
  39. let s:cpo_save = &cpo
  40. set cpo&vim
  41. " set iskeyword for this syntax script
  42. syn iskeyword @,48-57,192-255,-
  43. " Case sensitive matches
  44. syn case match
  45. syn keyword cabalConditional if else
  46. syn keyword cabalFunction os arche impl flag
  47. syn match cabalComment /--.*$/
  48. " Case insensitive matches
  49. syn case ignore
  50. syn keyword cabalCategory contained
  51. \ executable
  52. \ library
  53. \ benchmark
  54. \ test-suite
  55. \ source-repository
  56. \ flag
  57. \ custom-setup
  58. \ common
  59. syn match cabalCategoryTitle contained /[^{]*\ze{\?/
  60. syn match cabalCategoryRegion
  61. \ contains=cabalCategory,cabalCategoryTitle
  62. \ nextgroup=cabalCategory skipwhite
  63. \ /^\c\s*\(contained\|executable\|library\|benchmark\|test-suite\|source-repository\|flag\|custom-setup\|common\)\+\s*\%(.*$\|$\)/
  64. syn keyword cabalTruth true false
  65. " cabalStatementRegion which limits the scope of cabalStatement keywords, this
  66. " way they are not highlighted in description.
  67. syn region cabalStatementRegion start=+^\s*\(--\)\@<!\k\+\s*:+ end=+:+
  68. syn keyword cabalStatement contained containedin=cabalStatementRegion
  69. \ default-language
  70. \ default-extensions
  71. \ author
  72. \ autogen-modules
  73. \ asm-sources
  74. \ asm-options
  75. \ branch
  76. \ bug-reports
  77. \ build-depends
  78. \ build-tools
  79. \ build-tools-depends
  80. \ build-type
  81. \ buildable
  82. \ c-sources
  83. \ cabal-version
  84. \ category
  85. \ cc-options
  86. \ copyright
  87. \ cmm-sources
  88. \ cmm-options
  89. \ cpp-options
  90. \ cxx-sources
  91. \ data-dir
  92. \ data-files
  93. \ default
  94. \ default-extensions
  95. \ description
  96. \ executable
  97. \ exposed-modules
  98. \ exposed
  99. \ extensions
  100. \ extra-bundled-libraries
  101. \ extra-doc-files
  102. \ extra-dynamic-library-flavours
  103. \ extra-framework-dirs
  104. \ extra-ghci-libraries
  105. \ extra-lib-dirs
  106. \ extra-libraries
  107. \ extra-library-flavours
  108. \ extra-source-files
  109. \ extra-tmp-files
  110. \ for example
  111. \ frameworks
  112. \ ghc-options
  113. \ ghc-prof-options
  114. \ ghc-shared-options
  115. \ ghcjs-options
  116. \ ghcjs-prof-options
  117. \ ghcjs-shared-options
  118. \ homepage
  119. \ hs-source-dir
  120. \ hs-source-dirs
  121. \ hugs-options
  122. \ import
  123. \ include-dirs
  124. \ includes
  125. \ install-includes
  126. \ js-sources
  127. \ ld-options
  128. \ license
  129. \ license-file
  130. \ location
  131. \ main-is
  132. \ maintainer
  133. \ manual
  134. \ mixins
  135. \ module
  136. \ name
  137. \ nhc98-options
  138. \ other-extensions
  139. \ other-language
  140. \ other-languages
  141. \ other-modules
  142. \ package-url
  143. \ pkgconfig-depends
  144. \ setup-depends
  145. \ stability
  146. \ subdir
  147. \ synopsis
  148. \ tag
  149. \ tested-with
  150. \ type
  151. \ version
  152. \ virtual-modules
  153. " operators and version operators
  154. syn match cabalOperator /&&\|||\|!/
  155. syn match cabalVersionOperator contained
  156. \ /!\|==\|\^\?>=\|<=\|<\|>/
  157. " match version: `[%]\@<!` is to exclude `%20` in http addresses.
  158. syn match cabalVersion contained
  159. \ /[%$_-]\@<!\<\d\+\%(\.\d\+\)*\%(\.\*\)\?\>/
  160. " cabalVersionRegion which limits the scope of cabalVersion pattern.
  161. syn match cabalVersionRegionA
  162. \ contains=cabalVersionOperator,cabalVersion
  163. \ keepend
  164. \ /\%(==\|\^\?>=\|<=\|<\|>\)\s*\d\+\%(\.\d\+\)*\%(\.\*\)\?\>/
  165. " version inside `version: ...`
  166. syn match cabalVersionRegionB
  167. \ contains=cabalStatementRegion,cabalVersionOperator,cabalVersion
  168. \ /^\s*\%(cabal-\)\?version\s*:.*$/
  169. syn keyword cabalLanguage Haskell98 Haskell2010
  170. " title region
  171. syn match cabalName contained /:\@<=.*/
  172. syn match cabalNameRegion
  173. \ contains=cabalStatementRegion,cabalName
  174. \ nextgroup=cabalStatementRegion
  175. \ oneline
  176. \ /^\c\s*name\s*:.*$/
  177. " author region
  178. syn match cabalAuthor contained /:\@<=.*/
  179. syn match cabalAuthorRegion
  180. \ contains=cabalStatementRegion,cabalStatement,cabalAuthor
  181. \ nextgroup=cabalStatementRegion
  182. \ oneline
  183. \ /^\c\s*author\s*:.*$/
  184. " maintainer region
  185. syn match cabalMaintainer contained /:\@<=.*/
  186. syn match cabalMaintainerRegion
  187. \ contains=cabalStatementRegion,cabalStatement,cabalMaintainer
  188. \ nextgroup=cabalStatementRegion
  189. \ oneline
  190. \ /^\c\s*maintainer\s*:.*$/
  191. " license region
  192. syn match cabalLicense contained /:\@<=.*/
  193. syn match cabalLicenseRegion
  194. \ contains=cabalStatementRegion,cabalStatement,cabalLicense
  195. \ nextgroup=cabalStatementRegion
  196. \ oneline
  197. \ /^\c\s*license\s*:.*$/
  198. " license-file region
  199. syn match cabalLicenseFile contained /:\@<=.*/
  200. syn match cabalLicenseFileRegion
  201. \ contains=cabalStatementRegion,cabalStatement,cabalLicenseFile
  202. \ nextgroup=cabalStatementRegion
  203. \ oneline
  204. \ /^\c\s*license-file\s*:.*$/
  205. " tested-with region with compilers and versions
  206. syn keyword cabalCompiler contained ghc nhc yhc hugs hbc helium jhc lhc
  207. syn match cabalTestedWithRegion
  208. \ contains=cabalStatementRegion,cabalStatement,cabalCompiler,cabalVersionRegionA
  209. \ nextgroup=cabalStatementRegion
  210. \ oneline
  211. \ /^\c\s*tested-with\s*:.*$/
  212. " build type keywords
  213. syn keyword cabalBuildType contained
  214. \ simple custom configure
  215. syn match cabalBuildTypeRegion
  216. \ contains=cabalStatementRegion,cabalStatement,cabalBuildType
  217. \ nextgroup=cabalStatementRegion
  218. \ /^\c\s*build-type\s*:.*$/
  219. " Define the default highlighting.
  220. " Only when an item doesn't have highlighting yet
  221. hi def link cabalName Title
  222. hi def link cabalAuthor Normal
  223. hi def link cabalMaintainer Normal
  224. hi def link cabalCategoryTitle Title
  225. hi def link cabalLicense Normal
  226. hi def link cabalLicenseFile Normal
  227. hi def link cabalBuildType Keyword
  228. hi def link cabalVersion Number
  229. hi def link cabalTruth Boolean
  230. hi def link cabalComment Comment
  231. hi def link cabalStatement Statement
  232. hi def link cabalLanguage Type
  233. hi def link cabalCategory Type
  234. hi def link cabalFunction Function
  235. hi def link cabalConditional Conditional
  236. hi def link cabalOperator Operator
  237. hi def link cabalVersionOperator Operator
  238. hi def link cabalCompiler Constant
  239. let b:current_syntax = "cabal"
  240. let &cpo = s:cpo_save
  241. unlet! s:cpo_save
  242. " vim: ts=8