blob: 92e6b8331e5c3a3cf622cdf4eb03ae2edc3fb813 [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 Moolenaar23515b42020-11-29 14:36:24 +01007" Last Change: 21 Nov 2020
Bram Moolenaar7c63fbc2018-05-17 13:15:23 +02008" 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
Bram Moolenaar00a927d2010-05-14 23:24:24 +020020" 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
Bram Moolenaar89bcfda2016-08-30 23:26:57 +020035" quit when a syntax file was already loaded
36if exists("b:current_syntax")
Bram Moolenaar00a927d2010-05-14 23:24:24 +020037 finish
38endif
39
Bram Moolenaar7c63fbc2018-05-17 13:15:23 +020040" this file uses line continuation
41let s:cpo_save = &cpo
42set cpo&vim
Bram Moolenaar00a927d2010-05-14 23:24:24 +020043
Bram Moolenaar7c63fbc2018-05-17 13:15:23 +020044" set iskeyword for this syntax script
45syn iskeyword @,48-57,192-255,-
Bram Moolenaar00a927d2010-05-14 23:24:24 +020046
Bram Moolenaar7c63fbc2018-05-17 13:15:23 +020047" Case sensitive matches
48syn case match
Bram Moolenaar00a927d2010-05-14 23:24:24 +020049
Bram Moolenaar7c63fbc2018-05-17 13:15:23 +020050syn keyword cabalConditional if else
51syn keyword cabalFunction os arche impl flag
52syn match cabalComment /--.*$/
Bram Moolenaar00a927d2010-05-14 23:24:24 +020053
Bram Moolenaar7c63fbc2018-05-17 13:15:23 +020054" Case insensitive matches
55syn case ignore
Bram Moolenaar00a927d2010-05-14 23:24:24 +020056
Bram Moolenaar7c63fbc2018-05-17 13:15:23 +020057syn keyword cabalCategory contained
58 \ executable
59 \ library
60 \ benchmark
61 \ test-suite
62 \ source-repository
63 \ flag
64 \ custom-setup
Bram Moolenaar4f4d51a2020-10-11 13:57:40 +020065 \ common
Bram Moolenaar7c63fbc2018-05-17 13:15:23 +020066syn match cabalCategoryTitle contained /[^{]*\ze{\?/
67syn match cabalCategoryRegion
68 \ contains=cabalCategory,cabalCategoryTitle
69 \ nextgroup=cabalCategory skipwhite
Bram Moolenaar4f4d51a2020-10-11 13:57:40 +020070 \ /^\c\s*\(contained\|executable\|library\|benchmark\|test-suite\|source-repository\|flag\|custom-setup\|common\)\+\s*\%(.*$\|$\)/
Bram Moolenaar7c63fbc2018-05-17 13:15:23 +020071syn keyword cabalTruth true false
72
73" cabalStatementRegion which limits the scope of cabalStatement keywords, this
74" way they are not highlighted in description.
75syn region cabalStatementRegion start=+^\s*\(--\)\@<!\k\+\s*:+ end=+:+
76syn keyword cabalStatement contained containedin=cabalStatementRegion
77 \ default-language
78 \ default-extensions
79 \ author
Bram Moolenaar4f4d51a2020-10-11 13:57:40 +020080 \ autogen-modules
Bram Moolenaar23515b42020-11-29 14:36:24 +010081 \ asm-sources
82 \ asm-options
Bram Moolenaar7c63fbc2018-05-17 13:15:23 +020083 \ branch
84 \ bug-reports
85 \ build-depends
86 \ build-tools
Bram Moolenaar23515b42020-11-29 14:36:24 +010087 \ build-tools-depends
Bram Moolenaar7c63fbc2018-05-17 13:15:23 +020088 \ build-type
89 \ buildable
90 \ c-sources
91 \ cabal-version
92 \ category
93 \ cc-options
94 \ copyright
Bram Moolenaar23515b42020-11-29 14:36:24 +010095 \ cmm-sources
96 \ cmm-options
Bram Moolenaar7c63fbc2018-05-17 13:15:23 +020097 \ cpp-options
Bram Moolenaar23515b42020-11-29 14:36:24 +010098 \ cxx-sources
Bram Moolenaar7c63fbc2018-05-17 13:15:23 +020099 \ data-dir
100 \ data-files
101 \ default
Bram Moolenaar23515b42020-11-29 14:36:24 +0100102 \ default-extensions
Bram Moolenaar7c63fbc2018-05-17 13:15:23 +0200103 \ description
104 \ executable
105 \ exposed-modules
106 \ exposed
107 \ extensions
Bram Moolenaar23515b42020-11-29 14:36:24 +0100108 \ extra-bundled-libraries
Bram Moolenaar7c63fbc2018-05-17 13:15:23 +0200109 \ extra-doc-files
Bram Moolenaar23515b42020-11-29 14:36:24 +0100110 \ extra-dynamic-library-flavours
111 \ extra-framework-dirs
112 \ extra-ghci-libraries
Bram Moolenaar7c63fbc2018-05-17 13:15:23 +0200113 \ extra-lib-dirs
114 \ extra-libraries
Bram Moolenaar23515b42020-11-29 14:36:24 +0100115 \ extra-library-flavours
Bram Moolenaar7c63fbc2018-05-17 13:15:23 +0200116 \ extra-source-files
Bram Moolenaar23515b42020-11-29 14:36:24 +0100117 \ extra-tmp-files
Bram Moolenaar7c63fbc2018-05-17 13:15:23 +0200118 \ for example
119 \ frameworks
120 \ ghc-options
121 \ ghc-prof-options
122 \ ghc-shared-options
Bram Moolenaar23515b42020-11-29 14:36:24 +0100123 \ ghcjs-options
124 \ ghcjs-prof-options
125 \ ghcjs-shared-options
Bram Moolenaar7c63fbc2018-05-17 13:15:23 +0200126 \ homepage
Bram Moolenaar23515b42020-11-29 14:36:24 +0100127 \ hs-source-dir
Bram Moolenaar7c63fbc2018-05-17 13:15:23 +0200128 \ hs-source-dirs
129 \ hugs-options
Bram Moolenaar4f4d51a2020-10-11 13:57:40 +0200130 \ import
Bram Moolenaar7c63fbc2018-05-17 13:15:23 +0200131 \ include-dirs
132 \ includes
133 \ install-includes
Bram Moolenaar23515b42020-11-29 14:36:24 +0100134 \ js-sources
Bram Moolenaar7c63fbc2018-05-17 13:15:23 +0200135 \ ld-options
136 \ license
137 \ license-file
138 \ location
139 \ main-is
140 \ maintainer
141 \ manual
Bram Moolenaar23515b42020-11-29 14:36:24 +0100142 \ mixins
Bram Moolenaar7c63fbc2018-05-17 13:15:23 +0200143 \ module
144 \ name
145 \ nhc98-options
146 \ other-extensions
Bram Moolenaar23515b42020-11-29 14:36:24 +0100147 \ other-language
148 \ other-languages
Bram Moolenaar7c63fbc2018-05-17 13:15:23 +0200149 \ other-modules
150 \ package-url
151 \ pkgconfig-depends
152 \ setup-depends
153 \ stability
154 \ subdir
155 \ synopsis
156 \ tag
157 \ tested-with
158 \ type
159 \ version
160 \ virtual-modules
161
162" operators and version operators
163syn match cabalOperator /&&\|||\|!/
164syn match cabalVersionOperator contained
165 \ /!\|==\|\^\?>=\|<=\|<\|>/
166" match version: `[%]\@<!` is to exclude `%20` in http addresses.
167syn match cabalVersion contained
168 \ /[%$_-]\@<!\<\d\+\%(\.\d\+\)*\%(\.\*\)\?\>/
169" cabalVersionRegion which limits the scope of cabalVersion pattern.
170syn match cabalVersionRegionA
171 \ contains=cabalVersionOperator,cabalVersion
172 \ keepend
173 \ /\%(==\|\^\?>=\|<=\|<\|>\)\s*\d\+\%(\.\d\+\)*\%(\.\*\)\?\>/
174" version inside `version: ...`
175syn match cabalVersionRegionB
176 \ contains=cabalStatementRegion,cabalVersionOperator,cabalVersion
177 \ /^\s*\%(cabal-\)\?version\s*:.*$/
178
179syn keyword cabalLanguage Haskell98 Haskell2010
180
181" title region
182syn match cabalName contained /:\@<=.*/
183syn match cabalNameRegion
184 \ contains=cabalStatementRegion,cabalName
185 \ nextgroup=cabalStatementRegion
186 \ oneline
187 \ /^\c\s*name\s*:.*$/
188
189" author region
190syn match cabalAuthor contained /:\@<=.*/
191syn match cabalAuthorRegion
192 \ contains=cabalStatementRegion,cabalStatement,cabalAuthor
193 \ nextgroup=cabalStatementRegion
194 \ oneline
195 \ /^\c\s*author\s*:.*$/
196
197" maintainer region
198syn match cabalMaintainer contained /:\@<=.*/
199syn match cabalMaintainerRegion
200 \ contains=cabalStatementRegion,cabalStatement,cabalMaintainer
201 \ nextgroup=cabalStatementRegion
202 \ oneline
203 \ /^\c\s*maintainer\s*:.*$/
204
205" license region
206syn match cabalLicense contained /:\@<=.*/
207syn match cabalLicenseRegion
208 \ contains=cabalStatementRegion,cabalStatement,cabalLicense
209 \ nextgroup=cabalStatementRegion
210 \ oneline
211 \ /^\c\s*license\s*:.*$/
212
213" license-file region
214syn match cabalLicenseFile contained /:\@<=.*/
215syn match cabalLicenseFileRegion
216 \ contains=cabalStatementRegion,cabalStatement,cabalLicenseFile
217 \ nextgroup=cabalStatementRegion
218 \ oneline
219 \ /^\c\s*license-file\s*:.*$/
220
221" tested-with region with compilers and versions
222syn keyword cabalCompiler contained ghc nhc yhc hugs hbc helium jhc lhc
223syn match cabalTestedWithRegion
224 \ contains=cabalStatementRegion,cabalStatement,cabalCompiler,cabalVersionRegionA
225 \ nextgroup=cabalStatementRegion
226 \ oneline
227 \ /^\c\s*tested-with\s*:.*$/
228
229" build type keywords
230syn keyword cabalBuildType contained
231 \ simple custom configure
232syn match cabalBuildTypeRegion
233 \ contains=cabalStatementRegion,cabalStatement,cabalBuildType
234 \ nextgroup=cabalStatementRegion
235 \ /^\c\s*build-type\s*:.*$/
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200236
237" Define the default highlighting.
Bram Moolenaar89bcfda2016-08-30 23:26:57 +0200238" Only when an item doesn't have highlighting yet
Bram Moolenaar7c63fbc2018-05-17 13:15:23 +0200239hi def link cabalName Title
240hi def link cabalAuthor Normal
241hi def link cabalMaintainer Normal
242hi def link cabalCategoryTitle Title
243hi def link cabalLicense Normal
244hi def link cabalLicenseFile Normal
245hi def link cabalBuildType Keyword
246hi def link cabalVersion Number
247hi def link cabalTruth Boolean
248hi def link cabalComment Comment
249hi def link cabalStatement Statement
250hi def link cabalLanguage Type
251hi def link cabalCategory Type
252hi def link cabalFunction Function
253hi def link cabalConditional Conditional
254hi def link cabalOperator Operator
255hi def link cabalVersionOperator Operator
256hi def link cabalCompiler Constant
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200257
258let b:current_syntax = "cabal"
259
Bram Moolenaar7c63fbc2018-05-17 13:15:23 +0200260let &cpo = s:cpo_save
261unlet! s:cpo_save
262
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200263" vim: ts=8