cabal.vim 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  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: 15 May 2018
  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. syn match cabalCategoryTitle contained /[^{]*\ze{\?/
  59. syn match cabalCategoryRegion
  60. \ contains=cabalCategory,cabalCategoryTitle
  61. \ nextgroup=cabalCategory skipwhite
  62. \ /^\c\s*\(contained\|executable\|library\|benchmark\|test-suite\|source-repository\|flag\|custom-setup\)\+\s*\%(.*$\|$\)/
  63. syn keyword cabalTruth true false
  64. " cabalStatementRegion which limits the scope of cabalStatement keywords, this
  65. " way they are not highlighted in description.
  66. syn region cabalStatementRegion start=+^\s*\(--\)\@<!\k\+\s*:+ end=+:+
  67. syn keyword cabalStatement contained containedin=cabalStatementRegion
  68. \ default-language
  69. \ default-extensions
  70. \ author
  71. \ branch
  72. \ bug-reports
  73. \ build-depends
  74. \ build-tools
  75. \ build-type
  76. \ buildable
  77. \ c-sources
  78. \ cabal-version
  79. \ category
  80. \ cc-options
  81. \ copyright
  82. \ cpp-options
  83. \ data-dir
  84. \ data-files
  85. \ default
  86. \ description
  87. \ executable
  88. \ exposed-modules
  89. \ exposed
  90. \ extensions
  91. \ extra-tmp-files
  92. \ extra-doc-files
  93. \ extra-lib-dirs
  94. \ extra-libraries
  95. \ extra-source-files
  96. \ exta-tmp-files
  97. \ for example
  98. \ frameworks
  99. \ ghc-options
  100. \ ghc-prof-options
  101. \ ghc-shared-options
  102. \ homepage
  103. \ hs-source-dirs
  104. \ hugs-options
  105. \ include-dirs
  106. \ includes
  107. \ install-includes
  108. \ ld-options
  109. \ license
  110. \ license-file
  111. \ location
  112. \ main-is
  113. \ maintainer
  114. \ manual
  115. \ module
  116. \ name
  117. \ nhc98-options
  118. \ other-extensions
  119. \ other-modules
  120. \ package-url
  121. \ pkgconfig-depends
  122. \ setup-depends
  123. \ stability
  124. \ subdir
  125. \ synopsis
  126. \ tag
  127. \ tested-with
  128. \ type
  129. \ version
  130. \ virtual-modules
  131. " operators and version operators
  132. syn match cabalOperator /&&\|||\|!/
  133. syn match cabalVersionOperator contained
  134. \ /!\|==\|\^\?>=\|<=\|<\|>/
  135. " match version: `[%]\@<!` is to exclude `%20` in http addresses.
  136. syn match cabalVersion contained
  137. \ /[%$_-]\@<!\<\d\+\%(\.\d\+\)*\%(\.\*\)\?\>/
  138. " cabalVersionRegion which limits the scope of cabalVersion pattern.
  139. syn match cabalVersionRegionA
  140. \ contains=cabalVersionOperator,cabalVersion
  141. \ keepend
  142. \ /\%(==\|\^\?>=\|<=\|<\|>\)\s*\d\+\%(\.\d\+\)*\%(\.\*\)\?\>/
  143. " version inside `version: ...`
  144. syn match cabalVersionRegionB
  145. \ contains=cabalStatementRegion,cabalVersionOperator,cabalVersion
  146. \ /^\s*\%(cabal-\)\?version\s*:.*$/
  147. syn keyword cabalLanguage Haskell98 Haskell2010
  148. " title region
  149. syn match cabalName contained /:\@<=.*/
  150. syn match cabalNameRegion
  151. \ contains=cabalStatementRegion,cabalName
  152. \ nextgroup=cabalStatementRegion
  153. \ oneline
  154. \ /^\c\s*name\s*:.*$/
  155. " author region
  156. syn match cabalAuthor contained /:\@<=.*/
  157. syn match cabalAuthorRegion
  158. \ contains=cabalStatementRegion,cabalStatement,cabalAuthor
  159. \ nextgroup=cabalStatementRegion
  160. \ oneline
  161. \ /^\c\s*author\s*:.*$/
  162. " maintainer region
  163. syn match cabalMaintainer contained /:\@<=.*/
  164. syn match cabalMaintainerRegion
  165. \ contains=cabalStatementRegion,cabalStatement,cabalMaintainer
  166. \ nextgroup=cabalStatementRegion
  167. \ oneline
  168. \ /^\c\s*maintainer\s*:.*$/
  169. " license region
  170. syn match cabalLicense contained /:\@<=.*/
  171. syn match cabalLicenseRegion
  172. \ contains=cabalStatementRegion,cabalStatement,cabalLicense
  173. \ nextgroup=cabalStatementRegion
  174. \ oneline
  175. \ /^\c\s*license\s*:.*$/
  176. " license-file region
  177. syn match cabalLicenseFile contained /:\@<=.*/
  178. syn match cabalLicenseFileRegion
  179. \ contains=cabalStatementRegion,cabalStatement,cabalLicenseFile
  180. \ nextgroup=cabalStatementRegion
  181. \ oneline
  182. \ /^\c\s*license-file\s*:.*$/
  183. " tested-with region with compilers and versions
  184. syn keyword cabalCompiler contained ghc nhc yhc hugs hbc helium jhc lhc
  185. syn match cabalTestedWithRegion
  186. \ contains=cabalStatementRegion,cabalStatement,cabalCompiler,cabalVersionRegionA
  187. \ nextgroup=cabalStatementRegion
  188. \ oneline
  189. \ /^\c\s*tested-with\s*:.*$/
  190. " build type keywords
  191. syn keyword cabalBuildType contained
  192. \ simple custom configure
  193. syn match cabalBuildTypeRegion
  194. \ contains=cabalStatementRegion,cabalStatement,cabalBuildType
  195. \ nextgroup=cabalStatementRegion
  196. \ /^\c\s*build-type\s*:.*$/
  197. " Define the default highlighting.
  198. " Only when an item doesn't have highlighting yet
  199. hi def link cabalName Title
  200. hi def link cabalAuthor Normal
  201. hi def link cabalMaintainer Normal
  202. hi def link cabalCategoryTitle Title
  203. hi def link cabalLicense Normal
  204. hi def link cabalLicenseFile Normal
  205. hi def link cabalBuildType Keyword
  206. hi def link cabalVersion Number
  207. hi def link cabalTruth Boolean
  208. hi def link cabalComment Comment
  209. hi def link cabalStatement Statement
  210. hi def link cabalLanguage Type
  211. hi def link cabalCategory Type
  212. hi def link cabalFunction Function
  213. hi def link cabalConditional Conditional
  214. hi def link cabalOperator Operator
  215. hi def link cabalVersionOperator Operator
  216. hi def link cabalCompiler Constant
  217. let b:current_syntax = "cabal"
  218. let &cpo = s:cpo_save
  219. unlet! s:cpo_save
  220. " vim: ts=8