Merge pull request #9898 from haskell/mergify/bp/3.12/pr-9865
[cabal.git] / editors / vim / syntax / cabal.vim
blob2e6361ba9ccd2d2eff4c0daccb0fb072c5f18f58
1 " Vim syntax file
2 if exists("b:current_syntax")
3   finish
4 endif
6 " this file uses line continuation
7 let s:cpo_save = &cpo
8 set cpo&vim
10 " Lexical structure, keywords and comments
11 """"""""""""""""""""""""""""""""""""""""""
13 " set iskeyword for this syntax script
14 syn iskeyword a-z,A-Z,48-57,192-255,-,.
16 " Comments
17 syn match cabalComment    /--.*$/
19 " Enumerations
20 """"""""""""""
22 syn case match
24 syn keyword cabalBuildType contained
25   \ Simple
26   \ Configure
27   \ Custom
29 " test-suite,benchmark: exitcode-stdio-1.0, detailed-0.9
30 " foreign-library:      native-shared, native-static
31 " source-repository:    git, ...
32 syn keyword cabalCompType contained
33   \ exitcode-stdio-1.0
34   \ detailed-0.0
35   \ native-shared native-static
36   \ cvs svn darcs mercurial git
38 syn keyword cabalLanguage contained
39   \ Haskell98
40   \ Haskell2010
41   \ GHC2021
42   \ GHC2024
44 " To update this in Cabal, `cabal repl Cabal` and:
45 " >>> :m *Distribution.PackageDescription.FieldGrammar
46 " >>> _syntaxFieldNames
47 syn keyword cabalFieldName contained
48   \ asm-options
49   \ asm-sources
50   \ author
51   \ autogen-includes
52   \ autogen-modules
53   \ benchmark-module
54   \ branch
55   \ bug-reports
56   \ build-depends
57   \ build-tool-depends
58   \ build-tools
59   \ build-type
60   \ buildable
61   \ c-sources
62   \ cabal-version
63   \ category
64   \ cc-options
65   \ cmm-options
66   \ cmm-sources
67   \ copyright
68   \ cpp-options
69   \ cxx-options
70   \ cxx-sources
71   \ data-dir
72   \ data-files
73   \ default
74   \ default-extensions
75   \ default-language
76   \ description
77   \ exposed
78   \ exposed-modules
79   \ extensions
80   \ extra-bundled-libraries
81   \ extra-doc-files
82   \ extra-dynamic-library-flavours
83   \ extra-framework-dirs
84   \ extra-ghci-libraries
85   \ extra-lib-dirs
86   \ extra-libraries
87   \ extra-library-flavours
88   \ extra-source-files
89   \ extra-tmp-files
90   \ frameworks
91   \ ghc-options
92   \ ghc-prof-options
93   \ ghc-shared-options
94   \ ghcjs-options
95   \ ghcjs-prof-options
96   \ ghcjs-shared-options
97   \ homepage
98   \ hs-source-dir
99   \ hs-source-dirs
100   \ hsc2hs-options
101   \ hugs-options
102   \ include-dirs
103   \ includes
104   \ install-includes
105   \ jhc-options
106   \ js-sources
107   \ ld-options
108   \ lib-version-info
109   \ lib-version-linux
110   \ license
111   \ license-file
112   \ license-files
113   \ location
114   \ main-is
115   \ maintainer
116   \ manual
117   \ mixins
118   \ mod-def-file
119   \ module
120   \ name
121   \ nhc98-options
122   \ options
123   \ other-extensions
124   \ other-languages
125   \ other-modules
126   \ package-url
127   \ pkgconfig-depends
128   \ reexported-modules
129   \ scope
130   \ setup-depends
131   \ signatures
132   \ stability
133   \ subdir
134   \ synopsis
135   \ tag
136   \ test-module
137   \ tested-with
138   \ type
139   \ version
140   \ virtual-modules
142 " To update this in Cabal, `cabal repl Cabal` and:
143 " >>> :m *Distribution.PackageDescription.FieldGrammar
144 " >>> _syntaxExtensions
145 syn keyword cabalExtension contained
146   \ Safe
147   \ Trustworthy
148   \ Unsafe
149   \ AllowAmbiguousTypes
150   \ ApplicativeDo
151   \ Arrows
152   \ AutoDeriveTypeable
153   \ BangPatterns
154   \ BinaryLiterals
155   \ BlockArguments
156   \ CApiFFI
157   \ CPP
158   \ CUSKs
159   \ ConstrainedClassMethods
160   \ ConstraintKinds
161   \ DataKinds
162   \ DatatypeContexts
163   \ DefaultSignatures
164   \ DeepSubsumption
165   \ DeriveAnyClass
166   \ DeriveDataTypeable
167   \ DeriveFoldable
168   \ DeriveFunctor
169   \ DeriveGeneric
170   \ DeriveLift
171   \ DeriveTraversable
172   \ DerivingStrategies
173   \ DerivingVia
174   \ DisambiguateRecordFields
175   \ DoAndIfThenElse
176   \ DoRec
177   \ DuplicateRecordFields
178   \ EmptyCase
179   \ EmptyDataDecls
180   \ EmptyDataDeriving
181   \ ExistentialQuantification
182   \ ExplicitForAll
183   \ ExplicitNamespaces
184   \ ExtendedDefaultRules
185   \ ExtendedLiterals
186   \ ExtensibleRecords
187   \ FieldSelectors
188   \ FlexibleContexts
189   \ FlexibleInstances
190   \ ForeignFunctionInterface
191   \ FunctionalDependencies
192   \ GADTSyntax
193   \ GADTs
194   \ GHCForeignImportPrim
195   \ GeneralisedNewtypeDeriving
196   \ GeneralizedNewtypeDeriving
197   \ Generics
198   \ HereDocuments
199   \ HexFloatLiterals
200   \ ImplicitParams
201   \ ImplicitPrelude
202   \ ImportQualifiedPost
203   \ ImpredicativeTypes
204   \ IncoherentInstances
205   \ InstanceSigs
206   \ InterruptibleFFI
207   \ JavaScriptFFI
208   \ KindSignatures
209   \ LambdaCase
210   \ LexicalNegation
211   \ LiberalTypeSynonyms
212   \ LinearTypes
213   \ ListTuplePuns
214   \ RequiredTypeArguments
215   \ MagicHash
216   \ MonadComprehensions
217   \ MonadFailDesugaring
218   \ MonoLocalBinds
219   \ MonoPatBinds
220   \ MonomorphismRestriction
221   \ MultiParamTypeClasses
222   \ MultiWayIf
223   \ NPlusKPatterns
224   \ NamedFieldPuns
225   \ NamedWildCards
226   \ NegativeLiterals
227   \ NewQualifiedOperators
228   \ NondecreasingIndentation
229   \ NullaryTypeClasses
230   \ NumDecimals
231   \ NumericUnderscores
232   \ OverlappingInstances
233   \ OverloadedLabels
234   \ OverloadedLists
235   \ OverloadedRecordDot
236   \ OverloadedStrings
237   \ PackageImports
238   \ ParallelArrays
239   \ ParallelListComp
240   \ PartialTypeSignatures
241   \ PatternGuards
242   \ PatternSignatures
243   \ PatternSynonyms
244   \ PolyKinds
245   \ PolymorphicComponents
246   \ PostfixOperators
247   \ QualifiedDo
248   \ QuantifiedConstraints
249   \ QuasiQuotes
250   \ Rank2Types
251   \ RankNTypes
252   \ RebindableSyntax
253   \ RecordPuns
254   \ RecordWildCards
255   \ RecursiveDo
256   \ RegularPatterns
257   \ RelaxedPolyRec
258   \ RestrictedTypeSynonyms
259   \ RoleAnnotations
260   \ SafeImports
261   \ ScopedTypeVariables
262   \ StandaloneDeriving
263   \ StandaloneKindSignatures
264   \ StarIsType
265   \ StaticPointers
266   \ Strict
267   \ StrictData
268   \ TemplateHaskell
269   \ TemplateHaskellQuotes
270   \ TraditionalRecordSyntax
271   \ TransformListComp
272   \ TupleSections
273   \ TypeAbstractions
274   \ TypeApplications
275   \ TypeData
276   \ TypeFamilies
277   \ TypeFamilyDependencies
278   \ TypeInType
279   \ TypeOperators
280   \ TypeSynonymInstances
281   \ UnboxedSums
282   \ UnboxedTuples
283   \ UndecidableInstances
284   \ UndecidableSuperClasses
285   \ UnicodeSyntax
286   \ UnliftedDatatypes
287   \ UnliftedFFITypes
288   \ UnliftedNewtypes
289   \ ViewPatterns
290   \ XmlSyntax
291   \ NoAllowAmbiguousTypes
292   \ NoApplicativeDo
293   \ NoArrows
294   \ NoAutoDeriveTypeable
295   \ NoBangPatterns
296   \ NoBinaryLiterals
297   \ NoBlockArguments
298   \ NoCApiFFI
299   \ NoCPP
300   \ NoCUSKs
301   \ NoConstrainedClassMethods
302   \ NoConstraintKinds
303   \ NoDataKinds
304   \ NoDatatypeContexts
305   \ NoDefaultSignatures
306   \ NoDeepSubsumption
307   \ NoDeriveAnyClass
308   \ NoDeriveDataTypeable
309   \ NoDeriveFoldable
310   \ NoDeriveFunctor
311   \ NoDeriveGeneric
312   \ NoDeriveLift
313   \ NoDeriveTraversable
314   \ NoDerivingStrategies
315   \ NoDerivingVia
316   \ NoDisambiguateRecordFields
317   \ NoDoAndIfThenElse
318   \ NoDoRec
319   \ NoDuplicateRecordFields
320   \ NoEmptyCase
321   \ NoEmptyDataDecls
322   \ NoEmptyDataDeriving
323   \ NoExistentialQuantification
324   \ NoExplicitForAll
325   \ NoExplicitNamespaces
326   \ NoExtendedDefaultRules
327   \ NoExtendedLiterals
328   \ NoExtensibleRecords
329   \ NoFieldSelectors
330   \ NoFlexibleContexts
331   \ NoFlexibleInstances
332   \ NoForeignFunctionInterface
333   \ NoFunctionalDependencies
334   \ NoGADTSyntax
335   \ NoGADTs
336   \ NoGHCForeignImportPrim
337   \ NoGeneralisedNewtypeDeriving
338   \ NoGeneralizedNewtypeDeriving
339   \ NoGenerics
340   \ NoHereDocuments
341   \ NoHexFloatLiterals
342   \ NoImplicitParams
343   \ NoImplicitPrelude
344   \ NoImportQualifiedPost
345   \ NoImpredicativeTypes
346   \ NoIncoherentInstances
347   \ NoInstanceSigs
348   \ NoInterruptibleFFI
349   \ NoJavaScriptFFI
350   \ NoKindSignatures
351   \ NoLambdaCase
352   \ NoLexicalNegation
353   \ NoLiberalTypeSynonyms
354   \ NoLinearTypes
355   \ NoRequiredTypeArguments
356   \ NoMagicHash
357   \ NoMonadComprehensions
358   \ NoMonadFailDesugaring
359   \ NoMonoLocalBinds
360   \ NoMonoPatBinds
361   \ NoMonomorphismRestriction
362   \ NoMultiParamTypeClasses
363   \ NoMultiWayIf
364   \ NoNPlusKPatterns
365   \ NoNamedFieldPuns
366   \ NoNamedWildCards
367   \ NoNegativeLiterals
368   \ NoNewQualifiedOperators
369   \ NoNondecreasingIndentation
370   \ NoNullaryTypeClasses
371   \ NoNumDecimals
372   \ NoNumericUnderscores
373   \ NoOverlappingInstances
374   \ NoOverloadedLabels
375   \ NoOverloadedLists
376   \ NoOverloadedRecordDot
377   \ NoOverloadedStrings
378   \ NoPackageImports
379   \ NoParallelArrays
380   \ NoParallelListComp
381   \ NoPartialTypeSignatures
382   \ NoPatternGuards
383   \ NoPatternSignatures
384   \ NoPatternSynonyms
385   \ NoPolyKinds
386   \ NoPolymorphicComponents
387   \ NoPostfixOperators
388   \ NoQualifiedDo
389   \ NoQuantifiedConstraints
390   \ NoQuasiQuotes
391   \ NoRank2Types
392   \ NoRankNTypes
393   \ NoRebindableSyntax
394   \ NoRecordPuns
395   \ NoRecordWildCards
396   \ NoRecursiveDo
397   \ NoRegularPatterns
398   \ NoRelaxedPolyRec
399   \ NoRestrictedTypeSynonyms
400   \ NoRoleAnnotations
401   \ NoSafeImports
402   \ NoScopedTypeVariables
403   \ NoStandaloneDeriving
404   \ NoStandaloneKindSignatures
405   \ NoStarIsType
406   \ NoStaticPointers
407   \ NoStrict
408   \ NoStrictData
409   \ NoTemplateHaskell
410   \ NoTemplateHaskellQuotes
411   \ NoTraditionalRecordSyntax
412   \ NoTransformListComp
413   \ NoTupleSections
414   \ NoTypeAbstractions
415   \ NoTypeApplications
416   \ NoTypeData
417   \ NoTypeFamilies
418   \ NoTypeFamilyDependencies
419   \ NoTypeInType
420   \ NoTypeOperators
421   \ NoTypeSynonymInstances
422   \ NoUnboxedSums
423   \ NoUnboxedTuples
424   \ NoUndecidableInstances
425   \ NoUndecidableSuperClasses
426   \ NoUnicodeSyntax
427   \ NoUnliftedDatatypes
428   \ NoUnliftedFFITypes
429   \ NoUnliftedNewtypes
430   \ NoViewPatterns
431   \ NoXmlSyntax
433 " Cabal format is (mostly) case-insensitive
434 syn case ignore
436 " Structure regions
437 """""""""""""""""""
439 " Top level stanzas, cannot be nested, only library can be have optional name
440 syn match cabalStanzaLineRegion
441   \ /^\clibrary\(\s\+\k\+\)\=\s*$/
443 " Top level stanzas with an identifier
444 syn match cabalStanzaLineRegion
445   \ /^\c\(flag\|common\|source-repository\|executable\|test-suite\|benchmark\|foreign-library\)\s\+\k\+\s*$/
447 " Conditionals are nested
448 syn match cabalConditionalRegion
449   \ contains=cabalOperator,cabalBoolean
450   \ /^\c\s\+\(if\|elif\|else\)[^:]*$/
452 " Unindented fields
453 syn match cabalFieldRegion
454   \ /^[a-zA-Z0-9-]\+\s*:.*\n\(\s\+.*\n\|\s*\n\)*/
456 " Indented fields
458 " We use backreferences to fake the recognition of indentation.
459 " Unfortunately I don't know a way to anchor contained
460 " matches to the boundaries of the enclosing region.
461 syn match cabalFieldRegion
462   \ /^\(\s\+\)[a-zA-Z0-9-]\+\s*:.*\n\(\1\s\+.*\n\|\s*\n\)*/
464 " Component stanzas
465 """""""""""""""""""
467 syn match cabalCategoryTitle
468   \ contained
469   \ /\c[a-z0-9-]\+/
471 syn keyword cabalCategory
472   \ contained containedin=cabalStanzaLineRegion
473   \ nextgroup=cabalCategoryTitle skipwhite
474   \ flag common source-repository library executable test-suite benchmark foreign-library
476 " Version ranges
477 """"""""""""""""
479 syn match cabalOperator        contained /&&\|||\|!/
480 syn match cabalVersionOperator contained /==\|\^\?>=\|<=\|<\|>/
481 " match version: `[%]\@<!` is to exclude `%20` in http addresses.
482 syn match cabalVersion         contained /[%$_-]\@<!\<\d\+\%(\.\d\+\)*\%(\.\*\)\?\>/
483 " cabalVersionRegion which limits the scope of cabalVersion pattern.
484 syn match cabalVersionRegion
485   \ contains=cabalVersionOperator,cabalVersion
486   \ keepend
487   \ /\%(==\|\^\?>=\|<=\|<\|>\)\s*\d\+\%(\.\d\+\)*\%(\.\*\)\?\>/
489 " Compilers
490 """""""""""
492 syn keyword cabalCompiler contained ghc nhc yhc hugs hbc helium jhc lhc
494 " Conditionals
495 """"""""""""""
497 syn keyword cabalConditional contained containedin=cabalConditionalRegion
498   \ if elif else
500 syn keyword cabalFunction contained
501   \ os arch impl flag
503 syn region cabalFunctionRegion start=+\(os\|arch\|impl\|flag\)\s*(+ end=+)+
504   \ contained containedin=cabalConditionalRegion
505   \ contains=cabalOs,cabalFunction,cabalCompiler,cabalVersionRegion
507 " Common stanzas
508 """"""""""""""""
510 syn match cabalImportName contained /\c\<[a-z0-9-]\+\>/
511 syn keyword cabalImport contained import
512 syn match cabalImportRegion
513   \ contains=cabalImport,cabalColon,cabalImportName
514   \ /^\c\(\s\+\)import\s*:.*\n\(\1\s\+.*\n\|\s*\n\)*/
516 " Fields names
517 """"""""""""""
519 syn match cabalFieldNameRegion contained containedin=cabalFieldRegion
520   \ contains=cabalFieldName
521   \ /^\s*[a-zA-Z0-9-]\+\s*:/
523 syn match cabalColon contained containedin=cabalFieldNameRegion
524   \ /:/
526 " Field Values
527 """""""""""""""""""""""""""""""""
529 syn keyword cabalBoolean contained containedin=cabalFieldRegion
530   \ true false
532 " cabal-version
533 syn match cabalSpecVersion contained
534   \ /\(>=\s*1\.\(0\|2\|4\|6\|8\|10\)\|1\.\(12\|16\|18\|20\|22\|24\)\|2\.\(0\|2\|4\)\|3\.\(\0\|4\|6\)\)/
535 syn match cabalSpecVersionRegion
536   \ contained containedin=cabalFieldRegion
537   \ contains=cabalFieldNameRegion,cabalSpecVersion
538   \ /\c^cabal-version\s*:.*\n\(\s\+.*\n\|\s*\n\)*/
540 " version
541 syn match cabalPkgVersionRegion
542   \ contained containedin=cabalFieldRegion
543   \ contains=cabalFieldNameRegion,cabalVersion
544   \ /\c^version\s*:.*\n\(\s\+.*\n\|\s*\n\)*/
546 " description
547 syn match cabalDescriptionNameRegion
548   \ contained
549   \ contains=cabalFieldName
550   \ /\c^description/
551 syn match cabalDescriptionRegion
552   \ contained containedin=cabalFieldRegion
553   \ contains=cabalDescriptionNameRegion
554   \ /\c^description\s*:.*\n\(\s\+.*\n\|\s*\n\)*/
556 " tested-with
557 syn match cabalTestedWithRegion
558   \ contained containedin=cabalFieldRegion
559   \ contains=cabalFieldNameRegion,cabalVersionRegion,cabalOperator,cabalCompiler
560   \ /\c^tested-with\s*:.*\n\(\s\+.*\n\|\s*\n\)*/
562 " build-depends,build-tool-depends
564 " fields with version ranges
565 syn match cabalDependsRegion
566   \ contained containedin=cabalFieldRegion
567   \ contains=cabalFieldNameRegion,cabalVersionRegion,cabalOperator
568   \ /\c^\(\s\+\)\(build-depends\|build-tool-depends\)\s*:.*\n\(\1\s\+.*\n\|\s*\n\)*/
570 " build-type
571 syn match cabalBuildTypeRegion
572   \ contained containedin=cabalFieldRegion
573   \ contains=cabalFieldNameRegion,cabalBuildType
574   \ /\c^build-type\s*:.*\n\(\s\+.*\n\|\s*\n\)*/
576 " type
577 syn match cabalCompTypeRegion
578   \ contained containedin=cabalFieldRegion
579   \ contains=cabalFieldNameRegion,cabalCompType
580   \ /\c^\(\s\+\)type\s*:.*\n\(\1\s\+.*\n\|\s*\n\)*/
582 " default-extensions other-extensions extensions
583 syn match cabalExtensionsRegion
584   \ contained containedin=cabalFieldRegion
585   \ contains=cabalFieldNameRegion,cabalExtension
586   \ /^\c\(\s\+\)\(default-extensions\|other-extensions\|extensions\)\s*:.*\n\(\1\s\+.*\n\|\s*\n\)*/
588 " default-language other-languages
589 syn match cabalLanguagesRegion
590   \ contained containedin=cabalFieldRegion
591   \ contains=cabalFieldNameRegion,cabalLanguage
592   \ /^\c\(\s\+\)\(default-language\|other-languages\)\s*:.*\n\(\1\s\+.*\n\|\s*\n\)*/
594 " Define the default highlighting
595 """""""""""""""""""""""""""""""""
597 hi link cabalComment           Comment
599 " We highlight stanza region, as it makes component name highlighted
600 hi link cabalStanzaLineRegion  NONE
601 hi link cabalFieldRegion       NONE
602 hi link cabalFieldNameRegion   NONE
603 hi link cabalConditionalRegion NONE
605 hi link cabalCategory          Type
606 hi link cabalCategoryTitle     Title
608 hi link cabalImport            Type
609 hi link cabalImportName        Title
611 hi link cabalFunction          Function
613 hi link cabalConditional       Conditional
614 hi link cabalOperator          Operator
615 hi link cabalVersionOperator   Special
616 hi link cabalSpecVersion       Special
617 hi link cabalVersion           Special
619 hi link cabalFieldName         Keyword
620 hi link cabalColon             Operator
621 hi link cabalBoolean           Boolean
623 hi link cabalBuildType         Constant
624 hi link cabalCompiler          Constant
625 hi link cabalCompType          Constant
626 hi link cabalExtension         Constant
627 hi link cabalLanguage          Constant
628 hi link cabalOs                Constant
630 let b:current_syntax="mini-cabal"
632 " vim: ts=2