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