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