blob: 74cda51266fd1d5fd36dd14685978810c63671a6 [file] [log] [blame]
Bram Moolenaar00a927d2010-05-14 23:24:24 +02001" Vim syntax file
Bram Moolenaar7c63fbc2018-05-17 13:15:23 +02002" 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
Bram Moolenaar76db9e02022-11-09 21:21:04 +00007" Last Change: 22 Oct 2022
8" v1.6: Added support for foreign-libraries
9" Added highlighting for various fields
Bram Moolenaar7c63fbc2018-05-17 13:15:23 +020010" v1.5: Incorporated changes from
11" https://github.com/sdiehl/haskell-vim-proto/blob/master/vim/syntax/cabal.vim
12" Use `syn keyword` instead of `syn match`.
13" Added cabalStatementRegion to limit matches of keywords, which fixes
14" the highlighting of description's value.
15" Added cabalVersionRegion to limit the scope of cabalVersionOperator
16" and cabalVersion matches.
17" Added cabalLanguage keyword.
18" Added calbalTitle, cabalAuthor and cabalMaintainer syntax groups.
19" Added ! and ^>= operators (calbal 2.0)
20" Added build-type keywords
21" v1.4: Add benchmark support, thanks to Simon Meier
Bram Moolenaar00a927d2010-05-14 23:24:24 +020022" v1.3: Updated to the last version of cabal
23" Added more highlighting for cabal function, true/false
24" and version number. Also added missing comment highlighting.
25" Cabal known compiler are highlighted too.
26"
27" V1.2: Added cpp-options which was missing. Feature implemented
28" by GHC, found with a GHC warning, but undocumented.
29" Whatever...
30"
31" v1.1: Fixed operator problems and added ftdetect file
32" (thanks to Sebastian Schwarz)
33"
34" v1.0: Cabal syntax in vimball format
35" (thanks to Magnus Therning)
36
Bram Moolenaar89bcfda2016-08-30 23:26:57 +020037" quit when a syntax file was already loaded
38if exists("b:current_syntax")
Bram Moolenaar00a927d2010-05-14 23:24:24 +020039 finish
40endif
41
Bram Moolenaar7c63fbc2018-05-17 13:15:23 +020042" this file uses line continuation
43let s:cpo_save = &cpo
44set cpo&vim
Bram Moolenaar00a927d2010-05-14 23:24:24 +020045
Bram Moolenaar7c63fbc2018-05-17 13:15:23 +020046" set iskeyword for this syntax script
47syn iskeyword @,48-57,192-255,-
Bram Moolenaar00a927d2010-05-14 23:24:24 +020048
Bram Moolenaar7c63fbc2018-05-17 13:15:23 +020049" Case sensitive matches
50syn case match
Bram Moolenaar00a927d2010-05-14 23:24:24 +020051
Bram Moolenaar7c63fbc2018-05-17 13:15:23 +020052syn keyword cabalConditional if else
53syn keyword cabalFunction os arche impl flag
54syn match cabalComment /--.*$/
Bram Moolenaar00a927d2010-05-14 23:24:24 +020055
Bram Moolenaar7c63fbc2018-05-17 13:15:23 +020056" Case insensitive matches
57syn case ignore
Bram Moolenaar00a927d2010-05-14 23:24:24 +020058
Bram Moolenaar7c63fbc2018-05-17 13:15:23 +020059syn keyword cabalCategory contained
60 \ executable
61 \ library
62 \ benchmark
63 \ test-suite
64 \ source-repository
65 \ flag
Bram Moolenaar76db9e02022-11-09 21:21:04 +000066 \ foreign-library
Bram Moolenaar7c63fbc2018-05-17 13:15:23 +020067 \ custom-setup
Bram Moolenaar4f4d51a2020-10-11 13:57:40 +020068 \ common
Bram Moolenaar7c63fbc2018-05-17 13:15:23 +020069syn match cabalCategoryTitle contained /[^{]*\ze{\?/
70syn match cabalCategoryRegion
71 \ contains=cabalCategory,cabalCategoryTitle
72 \ nextgroup=cabalCategory skipwhite
Bram Moolenaar76db9e02022-11-09 21:21:04 +000073 \ /^\c\s*\(contained\|executable\|library\|benchmark\|test-suite\|source-repository\|flag\|foreign-library\|custom-setup\|common\)\+\s*\%(.*$\|$\)/
Bram Moolenaar7c63fbc2018-05-17 13:15:23 +020074syn keyword cabalTruth true false
75
76" cabalStatementRegion which limits the scope of cabalStatement keywords, this
77" way they are not highlighted in description.
78syn region cabalStatementRegion start=+^\s*\(--\)\@<!\k\+\s*:+ end=+:+
79syn keyword cabalStatement contained containedin=cabalStatementRegion
80 \ default-language
81 \ default-extensions
82 \ author
Bram Moolenaar76db9e02022-11-09 21:21:04 +000083 \ autogen-includes
Bram Moolenaar4f4d51a2020-10-11 13:57:40 +020084 \ autogen-modules
Bram Moolenaar23515b42020-11-29 14:36:24 +010085 \ asm-sources
86 \ asm-options
Bram Moolenaar7c63fbc2018-05-17 13:15:23 +020087 \ branch
88 \ bug-reports
89 \ build-depends
90 \ build-tools
Bram Moolenaar76db9e02022-11-09 21:21:04 +000091 \ build-tool-depends
Bram Moolenaar7c63fbc2018-05-17 13:15:23 +020092 \ build-type
93 \ buildable
94 \ c-sources
95 \ cabal-version
96 \ category
97 \ cc-options
98 \ copyright
Bram Moolenaar23515b42020-11-29 14:36:24 +010099 \ cmm-sources
100 \ cmm-options
Bram Moolenaar7c63fbc2018-05-17 13:15:23 +0200101 \ cpp-options
Bram Moolenaar76db9e02022-11-09 21:21:04 +0000102 \ cxx-options
Bram Moolenaar23515b42020-11-29 14:36:24 +0100103 \ cxx-sources
Bram Moolenaar7c63fbc2018-05-17 13:15:23 +0200104 \ data-dir
105 \ data-files
106 \ default
Bram Moolenaar23515b42020-11-29 14:36:24 +0100107 \ default-extensions
Bram Moolenaar7c63fbc2018-05-17 13:15:23 +0200108 \ description
109 \ executable
110 \ exposed-modules
111 \ exposed
112 \ extensions
Bram Moolenaar23515b42020-11-29 14:36:24 +0100113 \ extra-bundled-libraries
Bram Moolenaar7c63fbc2018-05-17 13:15:23 +0200114 \ extra-doc-files
Bram Moolenaar23515b42020-11-29 14:36:24 +0100115 \ extra-dynamic-library-flavours
116 \ extra-framework-dirs
117 \ extra-ghci-libraries
Bram Moolenaar7c63fbc2018-05-17 13:15:23 +0200118 \ extra-lib-dirs
Bram Moolenaar76db9e02022-11-09 21:21:04 +0000119 \ extra-lib-dirs-static
Bram Moolenaar7c63fbc2018-05-17 13:15:23 +0200120 \ extra-libraries
Bram Moolenaar76db9e02022-11-09 21:21:04 +0000121 \ extra-libraries-static
Bram Moolenaar23515b42020-11-29 14:36:24 +0100122 \ extra-library-flavours
Bram Moolenaar7c63fbc2018-05-17 13:15:23 +0200123 \ extra-source-files
Bram Moolenaar23515b42020-11-29 14:36:24 +0100124 \ extra-tmp-files
Bram Moolenaar7c63fbc2018-05-17 13:15:23 +0200125 \ for example
126 \ frameworks
127 \ ghc-options
128 \ ghc-prof-options
129 \ ghc-shared-options
Bram Moolenaar23515b42020-11-29 14:36:24 +0100130 \ ghcjs-options
131 \ ghcjs-prof-options
132 \ ghcjs-shared-options
Bram Moolenaar7c63fbc2018-05-17 13:15:23 +0200133 \ homepage
Bram Moolenaar23515b42020-11-29 14:36:24 +0100134 \ hs-source-dir
Bram Moolenaar7c63fbc2018-05-17 13:15:23 +0200135 \ hs-source-dirs
136 \ hugs-options
Bram Moolenaar4f4d51a2020-10-11 13:57:40 +0200137 \ import
Bram Moolenaar7c63fbc2018-05-17 13:15:23 +0200138 \ include-dirs
139 \ includes
140 \ install-includes
Bram Moolenaar23515b42020-11-29 14:36:24 +0100141 \ js-sources
Bram Moolenaar7c63fbc2018-05-17 13:15:23 +0200142 \ ld-options
Bram Moolenaar76db9e02022-11-09 21:21:04 +0000143 \ lib-version-info
144 \ lib-version-linux
Bram Moolenaar7c63fbc2018-05-17 13:15:23 +0200145 \ license
146 \ license-file
147 \ location
148 \ main-is
149 \ maintainer
150 \ manual
Bram Moolenaar23515b42020-11-29 14:36:24 +0100151 \ mixins
Bram Moolenaar7c63fbc2018-05-17 13:15:23 +0200152 \ module
Bram Moolenaar76db9e02022-11-09 21:21:04 +0000153 \ mod-def-file
Bram Moolenaar7c63fbc2018-05-17 13:15:23 +0200154 \ name
155 \ nhc98-options
Bram Moolenaar76db9e02022-11-09 21:21:04 +0000156 \ options
Bram Moolenaar7c63fbc2018-05-17 13:15:23 +0200157 \ other-extensions
Bram Moolenaar23515b42020-11-29 14:36:24 +0100158 \ other-language
159 \ other-languages
Bram Moolenaar7c63fbc2018-05-17 13:15:23 +0200160 \ other-modules
161 \ package-url
162 \ pkgconfig-depends
Bram Moolenaar76db9e02022-11-09 21:21:04 +0000163 \ scope
Bram Moolenaar7c63fbc2018-05-17 13:15:23 +0200164 \ setup-depends
Bram Moolenaar76db9e02022-11-09 21:21:04 +0000165 \ signatures
Bram Moolenaar7c63fbc2018-05-17 13:15:23 +0200166 \ stability
167 \ subdir
168 \ synopsis
Bram Moolenaar76db9e02022-11-09 21:21:04 +0000169 \ reexported-modules
Bram Moolenaar7c63fbc2018-05-17 13:15:23 +0200170 \ tag
171 \ tested-with
Bram Moolenaar76db9e02022-11-09 21:21:04 +0000172 \ test-module
Bram Moolenaar7c63fbc2018-05-17 13:15:23 +0200173 \ type
174 \ version
175 \ virtual-modules
176
177" operators and version operators
178syn match cabalOperator /&&\|||\|!/
179syn match cabalVersionOperator contained
180 \ /!\|==\|\^\?>=\|<=\|<\|>/
181" match version: `[%]\@<!` is to exclude `%20` in http addresses.
182syn match cabalVersion contained
183 \ /[%$_-]\@<!\<\d\+\%(\.\d\+\)*\%(\.\*\)\?\>/
184" cabalVersionRegion which limits the scope of cabalVersion pattern.
185syn match cabalVersionRegionA
186 \ contains=cabalVersionOperator,cabalVersion
187 \ keepend
188 \ /\%(==\|\^\?>=\|<=\|<\|>\)\s*\d\+\%(\.\d\+\)*\%(\.\*\)\?\>/
189" version inside `version: ...`
190syn match cabalVersionRegionB
191 \ contains=cabalStatementRegion,cabalVersionOperator,cabalVersion
192 \ /^\s*\%(cabal-\)\?version\s*:.*$/
193
194syn keyword cabalLanguage Haskell98 Haskell2010
195
196" title region
197syn match cabalName contained /:\@<=.*/
198syn match cabalNameRegion
199 \ contains=cabalStatementRegion,cabalName
200 \ nextgroup=cabalStatementRegion
201 \ oneline
202 \ /^\c\s*name\s*:.*$/
203
204" author region
205syn match cabalAuthor contained /:\@<=.*/
206syn match cabalAuthorRegion
207 \ contains=cabalStatementRegion,cabalStatement,cabalAuthor
208 \ nextgroup=cabalStatementRegion
209 \ oneline
210 \ /^\c\s*author\s*:.*$/
211
212" maintainer region
213syn match cabalMaintainer contained /:\@<=.*/
214syn match cabalMaintainerRegion
215 \ contains=cabalStatementRegion,cabalStatement,cabalMaintainer
216 \ nextgroup=cabalStatementRegion
217 \ oneline
218 \ /^\c\s*maintainer\s*:.*$/
219
220" license region
221syn match cabalLicense contained /:\@<=.*/
222syn match cabalLicenseRegion
223 \ contains=cabalStatementRegion,cabalStatement,cabalLicense
224 \ nextgroup=cabalStatementRegion
225 \ oneline
226 \ /^\c\s*license\s*:.*$/
227
228" license-file region
229syn match cabalLicenseFile contained /:\@<=.*/
230syn match cabalLicenseFileRegion
231 \ contains=cabalStatementRegion,cabalStatement,cabalLicenseFile
232 \ nextgroup=cabalStatementRegion
233 \ oneline
234 \ /^\c\s*license-file\s*:.*$/
235
236" tested-with region with compilers and versions
237syn keyword cabalCompiler contained ghc nhc yhc hugs hbc helium jhc lhc
238syn match cabalTestedWithRegion
239 \ contains=cabalStatementRegion,cabalStatement,cabalCompiler,cabalVersionRegionA
240 \ nextgroup=cabalStatementRegion
241 \ oneline
242 \ /^\c\s*tested-with\s*:.*$/
243
244" build type keywords
245syn keyword cabalBuildType contained
246 \ simple custom configure
247syn match cabalBuildTypeRegion
248 \ contains=cabalStatementRegion,cabalStatement,cabalBuildType
249 \ nextgroup=cabalStatementRegion
250 \ /^\c\s*build-type\s*:.*$/
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200251
252" Define the default highlighting.
Bram Moolenaar89bcfda2016-08-30 23:26:57 +0200253" Only when an item doesn't have highlighting yet
Bram Moolenaar7c63fbc2018-05-17 13:15:23 +0200254hi def link cabalName Title
255hi def link cabalAuthor Normal
256hi def link cabalMaintainer Normal
257hi def link cabalCategoryTitle Title
258hi def link cabalLicense Normal
259hi def link cabalLicenseFile Normal
260hi def link cabalBuildType Keyword
261hi def link cabalVersion Number
262hi def link cabalTruth Boolean
263hi def link cabalComment Comment
264hi def link cabalStatement Statement
265hi def link cabalLanguage Type
266hi def link cabalCategory Type
267hi def link cabalFunction Function
268hi def link cabalConditional Conditional
269hi def link cabalOperator Operator
270hi def link cabalVersionOperator Operator
271hi def link cabalCompiler Constant
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200272
273let b:current_syntax = "cabal"
274
Bram Moolenaar7c63fbc2018-05-17 13:15:23 +0200275let &cpo = s:cpo_save
276unlet! s:cpo_save
277
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200278" vim: ts=8