xref: /vim-8.2.3635/runtime/syntax/cabal.vim (revision 56994d21)
1" Vim syntax file
2" Language:     Haskell Cabal Build file
3" Author:	Vincent Berthoux <[email protected]>
4" Maintainer:   Marcin Szamotulski <[email protected]>
5" Previous Maintainer:	Vincent Berthoux <[email protected]>
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
35" quit when a syntax file was already loaded
36if exists("b:current_syntax")
37  finish
38endif
39
40" this file uses line continuation
41let s:cpo_save = &cpo
42set cpo&vim
43
44" set iskeyword for this syntax script
45syn iskeyword @,48-57,192-255,-
46
47" Case sensitive matches
48syn case match
49
50syn keyword cabalConditional	if else
51syn keyword cabalFunction	os arche impl flag
52syn match cabalComment		/--.*$/
53
54" Case insensitive matches
55syn case ignore
56
57syn keyword cabalCategory contained
58	\ executable
59	\ library
60	\ benchmark
61	\ test-suite
62	\ source-repository
63	\ flag
64	\ custom-setup
65	\ common
66syn match cabalCategoryTitle contained /[^{]*\ze{\?/
67syn match cabalCategoryRegion
68	\ contains=cabalCategory,cabalCategoryTitle
69	\ nextgroup=cabalCategory skipwhite
70	\ /^\c\s*\(contained\|executable\|library\|benchmark\|test-suite\|source-repository\|flag\|custom-setup\|common\)\+\s*\%(.*$\|$\)/
71syn 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
80        \ autogen-modules
81        \ asm-sources
82        \ asm-options
83	\ branch
84	\ bug-reports
85	\ build-depends
86	\ build-tools
87        \ build-tools-depends
88	\ build-type
89	\ buildable
90	\ c-sources
91	\ cabal-version
92	\ category
93	\ cc-options
94	\ copyright
95        \ cmm-sources
96        \ cmm-options
97	\ cpp-options
98        \ cxx-sources
99	\ data-dir
100	\ data-files
101	\ default
102        \ default-extensions
103	\ description
104	\ executable
105	\ exposed-modules
106	\ exposed
107	\ extensions
108        \ extra-bundled-libraries
109	\ extra-doc-files
110	\ extra-dynamic-library-flavours
111        \ extra-framework-dirs
112        \ extra-ghci-libraries
113	\ extra-lib-dirs
114	\ extra-libraries
115	\ extra-library-flavours
116	\ extra-source-files
117	\ extra-tmp-files
118	\ for example
119	\ frameworks
120	\ ghc-options
121	\ ghc-prof-options
122	\ ghc-shared-options
123        \ ghcjs-options
124        \ ghcjs-prof-options
125        \ ghcjs-shared-options
126	\ homepage
127        \ hs-source-dir
128	\ hs-source-dirs
129	\ hugs-options
130	\ import
131	\ include-dirs
132	\ includes
133	\ install-includes
134        \ js-sources
135	\ ld-options
136	\ license
137	\ license-file
138	\ location
139	\ main-is
140	\ maintainer
141	\ manual
142        \ mixins
143	\ module
144	\ name
145	\ nhc98-options
146	\ other-extensions
147        \ other-language
148        \ other-languages
149	\ 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*:.*$/
236
237" Define the default highlighting.
238" Only when an item doesn't have highlighting yet
239hi 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
257
258let b:current_syntax = "cabal"
259
260let &cpo = s:cpo_save
261unlet! s:cpo_save
262
263" vim: ts=8
264