2 if exists("b:current_syntax")
6 " this file uses line continuation
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,-,.
17 syn match cabalComment /--.*$/
24 syn keyword cabalBuildType contained
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
35 \ native-shared native-static
36 \ cvs svn darcs mercurial git
38 syn keyword cabalLanguage contained
44 " To update this in Cabal, `cabal repl Cabal` and:
45 " >>> :m *Distribution.PackageDescription.FieldGrammar
46 " >>> _syntaxFieldNames
47 syn keyword cabalFieldName contained
80 \ extra-bundled-libraries
82 \ extra-dynamic-library-flavours
83 \ extra-framework-dirs
84 \ extra-ghci-libraries
87 \ extra-library-flavours
96 \ ghcjs-shared-options
142 " To update this in Cabal, `cabal repl Cabal` and:
143 " >>> :m *Distribution.PackageDescription.FieldGrammar
144 " >>> _syntaxExtensions
145 syn keyword cabalExtension contained
149 \ AllowAmbiguousTypes
159 \ ConstrainedClassMethods
174 \ DisambiguateRecordFields
177 \ DuplicateRecordFields
181 \ ExistentialQuantification
184 \ ExtendedDefaultRules
190 \ ForeignFunctionInterface
191 \ FunctionalDependencies
194 \ GHCForeignImportPrim
195 \ GeneralisedNewtypeDeriving
196 \ GeneralizedNewtypeDeriving
202 \ ImportQualifiedPost
204 \ IncoherentInstances
211 \ LiberalTypeSynonyms
214 \ RequiredTypeArguments
216 \ MonadComprehensions
217 \ MonadFailDesugaring
220 \ MonomorphismRestriction
221 \ MultiParamTypeClasses
227 \ NewQualifiedOperators
228 \ NondecreasingIndentation
232 \ OverlappingInstances
235 \ OverloadedRecordDot
240 \ PartialTypeSignatures
245 \ PolymorphicComponents
248 \ QuantifiedConstraints
258 \ RestrictedTypeSynonyms
261 \ ScopedTypeVariables
263 \ StandaloneKindSignatures
269 \ TemplateHaskellQuotes
270 \ TraditionalRecordSyntax
277 \ TypeFamilyDependencies
280 \ TypeSynonymInstances
283 \ UndecidableInstances
284 \ UndecidableSuperClasses
291 \ NoAllowAmbiguousTypes
294 \ NoAutoDeriveTypeable
301 \ NoConstrainedClassMethods
305 \ NoDefaultSignatures
308 \ NoDeriveDataTypeable
313 \ NoDeriveTraversable
314 \ NoDerivingStrategies
316 \ NoDisambiguateRecordFields
319 \ NoDuplicateRecordFields
322 \ NoEmptyDataDeriving
323 \ NoExistentialQuantification
325 \ NoExplicitNamespaces
326 \ NoExtendedDefaultRules
328 \ NoExtensibleRecords
331 \ NoFlexibleInstances
332 \ NoForeignFunctionInterface
333 \ NoFunctionalDependencies
336 \ NoGHCForeignImportPrim
337 \ NoGeneralisedNewtypeDeriving
338 \ NoGeneralizedNewtypeDeriving
344 \ NoImportQualifiedPost
345 \ NoImpredicativeTypes
346 \ NoIncoherentInstances
353 \ NoLiberalTypeSynonyms
355 \ NoRequiredTypeArguments
357 \ NoMonadComprehensions
358 \ NoMonadFailDesugaring
361 \ NoMonomorphismRestriction
362 \ NoMultiParamTypeClasses
368 \ NoNewQualifiedOperators
369 \ NoNondecreasingIndentation
370 \ NoNullaryTypeClasses
372 \ NoNumericUnderscores
373 \ NoOverlappingInstances
376 \ NoOverloadedRecordDot
377 \ NoOverloadedStrings
381 \ NoPartialTypeSignatures
383 \ NoPatternSignatures
386 \ NoPolymorphicComponents
389 \ NoQuantifiedConstraints
399 \ NoRestrictedTypeSynonyms
402 \ NoScopedTypeVariables
403 \ NoStandaloneDeriving
404 \ NoStandaloneKindSignatures
410 \ NoTemplateHaskellQuotes
411 \ NoTraditionalRecordSyntax
412 \ NoTransformListComp
418 \ NoTypeFamilyDependencies
421 \ NoTypeSynonymInstances
424 \ NoUndecidableInstances
425 \ NoUndecidableSuperClasses
427 \ NoUnliftedDatatypes
433 " Cabal format is (mostly) case-insensitive
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\)[^:]*$/
453 syn match cabalFieldRegion
454 \ /^[a-zA-Z0-9-]\+\s*:.*\n\(\s\+.*\n\|\s*\n\)*/
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\)*/
467 syn match cabalCategoryTitle
471 syn keyword cabalCategory
472 \ contained containedin=cabalStanzaLineRegion
473 \ nextgroup=cabalCategoryTitle skipwhite
474 \ flag common source-repository library executable test-suite benchmark foreign-library
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
487 \ /\%(==\|\^\?>=\|<=\|<\|>\)\s*\d\+\%(\.\d\+\)*\%(\.\*\)\?\>/
492 syn keyword cabalCompiler contained ghc nhc yhc hugs hbc helium jhc lhc
497 syn keyword cabalConditional contained containedin=cabalConditionalRegion
500 syn keyword cabalFunction contained
503 syn region cabalFunctionRegion start=+\(os\|arch\|impl\|flag\)\s*(+ end=+)+
504 \ contained containedin=cabalConditionalRegion
505 \ contains=cabalOs,cabalFunction,cabalCompiler,cabalVersionRegion
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\)*/
519 syn match cabalFieldNameRegion contained containedin=cabalFieldRegion
520 \ contains=cabalFieldName
521 \ /^\s*[a-zA-Z0-9-]\+\s*:/
523 syn match cabalColon contained containedin=cabalFieldNameRegion
527 """""""""""""""""""""""""""""""""
529 syn keyword cabalBoolean contained containedin=cabalFieldRegion
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\)*/
541 syn match cabalPkgVersionRegion
542 \ contained containedin=cabalFieldRegion
543 \ contains=cabalFieldNameRegion,cabalVersion
544 \ /\c^version\s*:.*\n\(\s\+.*\n\|\s*\n\)*/
547 syn match cabalDescriptionNameRegion
549 \ contains=cabalFieldName
551 syn match cabalDescriptionRegion
552 \ contained containedin=cabalFieldRegion
553 \ contains=cabalDescriptionNameRegion
554 \ /\c^description\s*:.*\n\(\s\+.*\n\|\s*\n\)*/
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\)*/
571 syn match cabalBuildTypeRegion
572 \ contained containedin=cabalFieldRegion
573 \ contains=cabalFieldNameRegion,cabalBuildType
574 \ /\c^build-type\s*:.*\n\(\s\+.*\n\|\s*\n\)*/
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"