vim

Fork of vim, an acceptable text editor
git clone git://git.laack.co/vim.git
Log | Files | Refs | README | LICENSE

cabal.vim (8102B)


      1 " Vim syntax file
      2 " 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
      7 " Last Change:  22 Oct 2022
      8 "
      9 " 2026 Apr 29 by Léana: add missing haskell language editions
     10 " 2026 Apr 20 by Vim project: remove wrong oneline keyword #20018
     11 " 2026 Jun 26 by Vim project: add elif keyword #20623
     12 "
     13 " v1.6: Added support for foreign-libraries
     14 "       Added highlighting for various fields
     15 " v1.5: Incorporated changes from
     16 "       https://github.com/sdiehl/haskell-vim-proto/blob/master/vim/syntax/cabal.vim
     17 "       Use `syn keyword` instead of `syn match`.
     18 "       Added cabalStatementRegion to limit matches of keywords, which fixes
     19 "       the highlighting of description's value.
     20 "       Added cabalVersionRegion to limit the scope of cabalVersionOperator
     21 "       and cabalVersion matches.
     22 "       Added cabalLanguage keyword.
     23 "       Added calbalTitle, cabalAuthor and cabalMaintainer syntax groups.
     24 "       Added ! and ^>= operators (calbal 2.0)
     25 "       Added build-type keywords
     26 " v1.4: Add benchmark support, thanks to Simon Meier
     27 " v1.3: Updated to the last version of cabal
     28 "       Added more highlighting for cabal function, true/false
     29 "       and version number. Also added missing comment highlighting.
     30 "       Cabal known compiler are highlighted too.
     31 "
     32 " V1.2: Added cpp-options which was missing. Feature implemented
     33 "       by GHC, found with a GHC warning, but undocumented.
     34 "       Whatever...
     35 "
     36 " v1.1: Fixed operator problems and added ftdetect file
     37 "       (thanks to Sebastian Schwarz)
     38 "
     39 " v1.0: Cabal syntax in vimball format
     40 "       (thanks to Magnus Therning)
     41 
     42 " quit when a syntax file was already loaded
     43 if exists("b:current_syntax")
     44   finish
     45 endif
     46 
     47 " this file uses line continuation
     48 let s:cpo_save = &cpo
     49 set cpo&vim
     50 
     51 " set iskeyword for this syntax script
     52 syn iskeyword @,48-57,192-255,-
     53 
     54 " Case sensitive matches
     55 syn case match
     56 
     57 syn keyword cabalConditional	if elif else
     58 syn keyword cabalFunction	os arche impl flag
     59 syn match cabalComment		/--.*$/
     60 
     61 " Case insensitive matches
     62 syn case ignore
     63 
     64 syn keyword cabalCategory contained
     65 	\ executable
     66 	\ library
     67 	\ benchmark
     68 	\ test-suite
     69 	\ source-repository
     70 	\ flag
     71         \ foreign-library
     72 	\ custom-setup
     73 	\ common
     74 syn match cabalCategoryTitle contained /[^{]*\ze{\?/
     75 syn match cabalCategoryRegion
     76 	\ contains=cabalCategory,cabalCategoryTitle
     77 	\ nextgroup=cabalCategory skipwhite
     78 	\ /^\c\s*\(contained\|executable\|library\|benchmark\|test-suite\|source-repository\|flag\|foreign-library\|custom-setup\|common\)\+\s*\%(.*$\|$\)/
     79 syn keyword cabalTruth true false
     80 
     81 " cabalStatementRegion which limits the scope of cabalStatement keywords, this
     82 " way they are not highlighted in description.
     83 syn region cabalStatementRegion start=+^\s*\(--\)\@<!\k\+\s*:+ end=+:+
     84 syn keyword cabalStatement contained containedin=cabalStatementRegion
     85 	\ default-language
     86 	\ default-extensions
     87 	\ author
     88         \ autogen-includes
     89         \ autogen-modules
     90         \ asm-sources
     91         \ asm-options
     92 	\ branch
     93 	\ bug-reports
     94 	\ build-depends
     95 	\ build-tools
     96         \ build-tool-depends
     97 	\ build-type
     98 	\ buildable
     99 	\ c-sources
    100 	\ cabal-version
    101 	\ category
    102 	\ cc-options
    103 	\ copyright
    104         \ cmm-sources
    105         \ cmm-options
    106 	\ cpp-options
    107         \ cxx-options
    108         \ cxx-sources
    109 	\ data-dir
    110 	\ data-files
    111 	\ default
    112         \ default-extensions
    113 	\ description
    114 	\ executable
    115 	\ exposed-modules
    116 	\ exposed
    117 	\ extensions
    118         \ extra-bundled-libraries
    119 	\ extra-doc-files
    120 	\ extra-dynamic-library-flavours
    121         \ extra-framework-dirs
    122         \ extra-ghci-libraries
    123 	\ extra-lib-dirs
    124 	\ extra-lib-dirs-static
    125 	\ extra-libraries
    126 	\ extra-libraries-static
    127 	\ extra-library-flavours
    128 	\ extra-source-files
    129 	\ extra-tmp-files
    130 	\ for example
    131 	\ frameworks
    132 	\ ghc-options
    133 	\ ghc-prof-options
    134 	\ ghc-shared-options
    135         \ ghcjs-options
    136         \ ghcjs-prof-options
    137         \ ghcjs-shared-options
    138 	\ homepage
    139         \ hs-source-dir
    140 	\ hs-source-dirs
    141 	\ hugs-options
    142 	\ import
    143 	\ include-dirs
    144 	\ includes
    145 	\ install-includes
    146         \ js-sources
    147 	\ ld-options
    148         \ lib-version-info
    149         \ lib-version-linux
    150 	\ license
    151 	\ license-file
    152 	\ location
    153 	\ main-is
    154 	\ maintainer
    155 	\ manual
    156         \ mixins
    157 	\ module
    158         \ mod-def-file
    159 	\ name
    160 	\ nhc98-options
    161         \ options
    162 	\ other-extensions
    163         \ other-language
    164         \ other-languages
    165 	\ other-modules
    166 	\ package-url
    167 	\ pkgconfig-depends
    168         \ scope
    169 	\ setup-depends
    170         \ signatures
    171 	\ stability
    172 	\ subdir
    173 	\ synopsis
    174         \ reexported-modules
    175 	\ tag
    176 	\ tested-with
    177         \ test-module
    178 	\ type
    179 	\ version
    180 	\ virtual-modules
    181 
    182 " operators and version operators
    183 syn match cabalOperator /&&\|||\|!/
    184 syn match cabalVersionOperator contained
    185 	\ /!\|==\|\^\?>=\|<=\|<\|>/
    186 " match version: `[%]\@<!` is to exclude `%20` in http addresses.
    187 syn match cabalVersion contained
    188 	\ /[%$_-]\@<!\<\d\+\%(\.\d\+\)*\%(\.\*\)\?\>/
    189 " cabalVersionRegion which limits the scope of cabalVersion pattern.
    190 syn match cabalVersionRegionA
    191 	\ contains=cabalVersionOperator,cabalVersion
    192 	\ keepend
    193 	\ /\%(==\|\^\?>=\|<=\|<\|>\)\s*\d\+\%(\.\d\+\)*\%(\.\*\)\?\>/
    194 " version inside `version: ...`
    195 syn match cabalVersionRegionB
    196 	\ contains=cabalStatementRegion,cabalVersionOperator,cabalVersion
    197 	\ /^\s*\%(cabal-\)\?version\s*:.*$/
    198 
    199 " See the following link for all Haskell language editions supported by Cabal.
    200 " https://cabal.readthedocs.io/en/stable/cabal-package-description-file.html#pkg-field-default-language
    201 syn keyword cabalLanguage Haskell98 Haskell2010 GHC2021 GHC2024
    202 
    203 " title region
    204 syn match cabalName contained /:\@<=.*/
    205 syn match cabalNameRegion
    206 	\ contains=cabalStatementRegion,cabalName
    207 	\ nextgroup=cabalStatementRegion
    208 	\ /^\c\s*name\s*:.*$/
    209 
    210 " author region
    211 syn match cabalAuthor contained /:\@<=.*/
    212 syn match cabalAuthorRegion
    213 	\ contains=cabalStatementRegion,cabalStatement,cabalAuthor
    214 	\ nextgroup=cabalStatementRegion
    215 	\ /^\c\s*author\s*:.*$/
    216 
    217 " maintainer region
    218 syn match cabalMaintainer contained /:\@<=.*/
    219 syn match cabalMaintainerRegion
    220 	\ contains=cabalStatementRegion,cabalStatement,cabalMaintainer
    221 	\ nextgroup=cabalStatementRegion
    222 	\ /^\c\s*maintainer\s*:.*$/
    223 
    224 " license region
    225 syn match cabalLicense contained /:\@<=.*/
    226 syn match cabalLicenseRegion
    227 	\ contains=cabalStatementRegion,cabalStatement,cabalLicense
    228 	\ nextgroup=cabalStatementRegion
    229 	\ /^\c\s*license\s*:.*$/
    230 
    231 " license-file region
    232 syn match cabalLicenseFile contained /:\@<=.*/
    233 syn match cabalLicenseFileRegion
    234 	\ contains=cabalStatementRegion,cabalStatement,cabalLicenseFile
    235 	\ nextgroup=cabalStatementRegion
    236 	\ /^\c\s*license-file\s*:.*$/
    237 
    238 " tested-with region with compilers and versions
    239 syn keyword cabalCompiler contained ghc nhc yhc hugs hbc helium jhc lhc
    240 syn match cabalTestedWithRegion
    241 	\ contains=cabalStatementRegion,cabalStatement,cabalCompiler,cabalVersionRegionA
    242 	\ nextgroup=cabalStatementRegion
    243 	\ /^\c\s*tested-with\s*:.*$/
    244 
    245 " build type keywords
    246 syn keyword cabalBuildType contained
    247 	\ simple custom configure
    248 syn match cabalBuildTypeRegion
    249 	\ contains=cabalStatementRegion,cabalStatement,cabalBuildType
    250 	\ nextgroup=cabalStatementRegion
    251 	\ /^\c\s*build-type\s*:.*$/
    252 
    253 " Define the default highlighting.
    254 " Only when an item doesn't have highlighting yet
    255 hi def link cabalName	      Title
    256 hi def link cabalAuthor	      Normal
    257 hi def link cabalMaintainer   Normal
    258 hi def link cabalCategoryTitle Title
    259 hi def link cabalLicense      Normal
    260 hi def link cabalLicenseFile  Normal
    261 hi def link cabalBuildType    Keyword
    262 hi def link cabalVersion      Number
    263 hi def link cabalTruth        Boolean
    264 hi def link cabalComment      Comment
    265 hi def link cabalStatement    Statement
    266 hi def link cabalLanguage     Type
    267 hi def link cabalCategory     Type
    268 hi def link cabalFunction     Function
    269 hi def link cabalConditional  Conditional
    270 hi def link cabalOperator     Operator
    271 hi def link cabalVersionOperator Operator
    272 hi def link cabalCompiler     Constant
    273 
    274 let b:current_syntax = "cabal"
    275 
    276 let &cpo = s:cpo_save
    277 unlet! s:cpo_save
    278 
    279 " vim: ts=8