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