.vim/syntax/haskell.vim 11.6 KiB raw
1
" Vim syntax file
2
"
3
" Modification of vims Haskell syntax file:
4
"   - match types using regular expression
5
"   - use "syntax keyword" instead of "syntax match" where appropriate
6
"   - functions and types in import and module declarations are matched
7
"   - removed hs_highlight_more_types (just not needed anymore)
8
"   - enable spell checking in comments and strings only
9
"   - FFI highlighting
10
"   - QuasiQuotation
11
"   - top level Template Haskell slices
12
"   - PackageImport
13
"
14
" From Original file:
15
" ===================
16
"
17
" Language:		    Haskell
18
" Maintainer:		Haskell Cafe mailinglist <haskell-cafe@haskell.org>
19
" Last Change:		2010 Feb 21
20
" Original Author:	John Williams <jrw@pobox.com>
21
"
22
" Thanks to Ryan Crumley for suggestions and John Meacham for
23
" pointing out bugs. Also thanks to Ian Lynagh and Donald Bruce Stewart
24
" for providing the inspiration for the inclusion of the handling
25
" of C preprocessor directives, and for pointing out a bug in the
26
" end-of-line comment handling.
27
"
28
" Options-assign a value to these variables to turn the option on:
29
"
30
" hs_allow_hash_operator - Don't highlight seemingly incorrect C
31
"			   preprocessor directives but assume them to be
32
"			   operators
33
"
34
35
if exists("b:current_syntax")
36
  finish
37
endif
38
39
"syntax sync fromstart "mmhhhh.... is this really ok to do so?
40
syntax sync linebreaks=15 minlines=50 maxlines=500
41
42
syn match  hsSpecialChar	contained "\\\([0-9]\+\|o[0-7]\+\|x[0-9a-fA-F]\+\|[\"\\'&\\abfnrtv]\|^[A-Z^_\[\\\]]\)"
43
syn match  hsSpecialChar	contained "\\\(NUL\|SOH\|STX\|ETX\|EOT\|ENQ\|ACK\|BEL\|BS\|HT\|LF\|VT\|FF\|CR\|SO\|SI\|DLE\|DC1\|DC2\|DC3\|DC4\|NAK\|SYN\|ETB\|CAN\|EM\|SUB\|ESC\|FS\|GS\|RS\|US\|SP\|DEL\)"
44
syn match  hsSpecialCharError	contained "\\&\|'''\+"
45
sy region  hsString		start=+"+  skip=+\\\\\|\\"+  end=+"+  contains=hsSpecialChar,@Spell
46
sy match   hsCharacter		"[^a-zA-Z0-9_']'\([^\\]\|\\[^']\+\|\\'\)'"lc=1 contains=hsSpecialChar,hsSpecialCharError
47
sy match   hsCharacter		"^'\([^\\]\|\\[^']\+\|\\'\)'" contains=hsSpecialChar,hsSpecialCharError
48
sy match   hsOpFunctionName "(\(\W\&[^(),\"]\)\+)" contained
49
sy match   hsHlFunctionName "[a-z_]\(\S\&[^,\(\)\[\]]\)*" contained
50
51
52
53
" (Qualified) identifiers (no default highlighting)
54
syn match ConId "\(\<[A-Z][a-zA-Z0-9_']*\.\)\=\<[A-Z][a-zA-Z0-9_']*\>"
55
syn match VarId "\(\<[A-Z][a-zA-Z0-9_']*\.\)\=\<[a-z][a-zA-Z0-9_']*\>"
56
57
" Infix operators--most punctuation characters and any (qualified) identifier
58
" enclosed in `backquotes`. An operator starting with : is a constructor,
59
" others are variables (e.g. functions).
60
syn match hsVarSym "\(\<[A-Z][a-zA-Z0-9_']*\.\)\=[-!#$%&\*\+/<=>\?@\\^|~.][-!#$%&\*\+/<=>\?@\\^|~:.]*"
61
syn match hsConSym "\(\<[A-Z][a-zA-Z0-9_']*\.\)\=:[-!#$%&\*\+./<=>\?@\\^|~:]*"
62
syn match hsVarSym "`\(\<[A-Z][a-zA-Z0-9_']*\.\)\=[a-z][a-zA-Z0-9_']*`"
63
syn match hsConSym "`\(\<[A-Z][a-zA-Z0-9_']*\.\)\=[A-Z][a-zA-Z0-9_']*`"
64
65
" Reserved symbols--cannot be overloaded.
66
syn match hsDelimiter  "(\|)\|\[\|\]\|,\|;\|_\|{\|}"
67
68
sy region hsInnerParen start="(" end=")" contained contains=hsInnerParen,hsConSym,hsType,hsVarSym
69
70
sy keyword hsStructure data family class where instance default deriving
71
sy keyword hsTypedef type newtype
72
sy keyword hsPattern pattern
73
74
sy keyword hsInfix infix infixl infixr
75
sy keyword hsStatement  do case of let in
76
sy keyword hsConditional if then else
77
78
" Primitive types from the standard prelude and libraries.
79
sy match hsType "\<[A-Z]\(\S\&[^,.{}]\)*\>"
80
sy match hsType "()"
81
82
syn keyword hsBoolean True False
83
84
syn region	hsPackageString	start=+L\="+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end='$' contains=cSpecial contained
85
sy match   hsModuleName  excludenl "\([A-Z]\w*\.\?\)*" contained
86
87
sy match hsImport "\<import\>\s\+\(qualified\s\+\)\?\(\<\(\w\|\.\)*\>\)\s*\(()\)\?"
88
    \ contains=hsModuleName,hsImportLabel
89
    \ nextgroup=hsImportParams,hsImportIllegal skipwhite
90
sy keyword hsImportLabel import qualified contained
91
92
sy match hsImportIllegal "\w\+" contained
93
94
sy keyword hsAsLabel as contained
95
sy keyword hsHidingLabel hiding contained
96
97
sy match hsImportParams "as\s\+\(\w\+\)" contained
98
    \ contains=hsModuleName,hsAsLabel
99
    \ nextgroup=hsImportParams,hsImportIllegal skipwhite
100
sy match hsImportParams "hiding" contained
101
    \ contains=hsHidingLabel
102
    \ nextgroup=hsImportParams,hsImportIllegal skipwhite
103
sy region hsImportParams start="(" end=")" contained
104
    \ contains=hsBlockComment,hsLineComment, hsType,hsDelimTypeExport,hsHlFunctionName,hsOpFunctionName
105
    \ nextgroup=hsImportIllegal skipwhite
106
107
" new module highlighting
108
syn region hsDelimTypeExport start="\<[A-Z]\(\S\&[^,.]\)*\>(" end=")" contained
109
   \ contains=hsType
110
111
sy keyword hsExportModuleLabel module contained
112
sy match hsExportModule "\<module\>\(\s\|\t\|\n\)*\([A-Z]\w*\.\?\)*" contained contains=hsExportModuleLabel,hsModuleName
113
114
sy keyword hsModuleStartLabel module contained
115
sy keyword hsModuleWhereLabel where contained
116
117
syn match hsModuleStart "^module\(\s\|\n\)*\(\<\(\w\|\.\)*\>\)\(\s\|\n\)*"
118
  \ contains=hsModuleStartLabel,hsModuleName
119
  \ nextgroup=hsModuleCommentA,hsModuleExports,hsModuleWhereLabel
120
121
syn region hsModuleCommentA start="{-" end="-}"
122
  \ contains=hsModuleCommentA,hsCommentTodo,@Spell contained
123
  \ nextgroup=hsModuleCommentA,hsModuleExports,hsModuleWhereLabel skipwhite skipnl
124
125
syn match hsModuleCommentA "--.*\n"
126
  \ contains=hsCommentTodo,@Spell contained
127
  \ nextgroup=hsModuleCommentA,hsModuleExports,hsModuleWhereLabel skipwhite skipnl
128
129
syn region hsModuleExports start="(" end=")" contained
130
   \ nextgroup=hsModuleCommentB,hsModuleWhereLabel skipwhite skipnl
131
   \ contains=hsBlockComment,hsLineComment,hsType,hsDelimTypeExport,hsHlFunctionName,hsOpFunctionName,hsExportModule,hsPattern
132
133
syn match hsModuleCommentB "--.*\n"
134
  \ contains=hsCommentTodo,@Spell contained
135
  \ nextgroup=hsModuleCommentB,hsModuleWhereLabel skipwhite skipnl
136
137
syn region hsModuleCommentB start="{-" end="-}"
138
   \ contains=hsModuleCommentB,hsCommentTodo,@Spell contained
139
   \ nextgroup=hsModuleCommentB,hsModuleWhereLabel skipwhite skipnl
140
" end module highlighting
141
142
" FFI support
143
sy keyword hsFFIForeign foreign contained
144
"sy keyword hsFFIImportExport import export contained
145
sy keyword hsFFIImportExport export contained
146
sy keyword hsFFICallConvention ccall stdcall contained
147
sy keyword hsFFISafety safe unsafe contained
148
sy region  hsFFIString		start=+"+  skip=+\\\\\|\\"+  end=+"+  contained contains=hsSpecialChar
149
sy match hsFFI excludenl "\<foreign\>\(.\&[^\"]\)*\"\(.\)*\"\(\s\|\n\)*\(.\)*::"
150
  \ keepend
151
  \ contains=hsFFIForeign,hsFFIImportExport,hsFFICallConvention,hsFFISafety,hsFFIString,hsOpFunctionName,hsHlFunctionName
152
153
154
sy match   hsNumber		"\<[0-9]\+\>\|\<0[xX][0-9a-fA-F]\+\>\|\<0[oO][0-7]\+\>\|\<[0-9][0-9_]\+\>"
155
sy match   hsFloat		"\<[0-9]\+\.[0-9]\+\([eE][-+]\=[0-9]\+\)\=\>"
156
157
" Comments
158
sy keyword hsCommentTodo    TODO FIXME XXX TBD contained
159
sy match   hsLineComment      "---*\([^-!#$%&\*\+./<=>\?@\\^|~].*\)\?$" contains=hsCommentTodo,@Spell
160
sy region  hsBlockComment     start="{-"  end="-}" contains=hsBlockComment,hsCommentTodo,@Spell
161
sy region  hsPragma	       start="{-#" end="#-}"
162
163
" QuasiQuotation
164
sy region hsQQ start="\[\$" end="|\]"me=e-2 keepend contains=hsQQVarID,hsQQContent nextgroup=hsQQEnd
165
sy region hsQQNew start="\[\(.\&[^|]\&\S\)*|" end="|\]"me=e-2 keepend contains=hsQQVarIDNew,hsQQContent nextgroup=hsQQEnd
166
sy match hsQQContent ".*" contained
167
sy match hsQQEnd "|\]" contained
168
sy match hsQQVarID "\[\$\(.\&[^|]\)*|" contained
169
sy match hsQQVarIDNew "\[\(.\&[^|]\)*|" contained
170
171
" Debugging functions from the standard prelude.
172
syn keyword hsDebug trace traceM traceShowM
173
syn keyword hsUndefined undefined error
174
175
" C Preprocessor directives. Shamelessly ripped from c.vim and trimmed
176
" First, see whether to flag directive-like lines or not
177
if (!exists("hs_allow_hash_operator"))
178
    syn match	cError		display "^\s*\(%:\|#\).*$"
179
endif
180
181
" Accept %: for # (C99)
182
syn region	cPreCondit	start="^\s*\(%:\|#\)\s*\(if\|ifdef\|ifndef\|elif\)\>" skip="\\$" end="$" end="//"me=s-1 contains=cComment,cCppString,cCommentError
183
syn match	cPreCondit	display "^\s*\(%:\|#\)\s*\(else\|endif\)\>"
184
syn region	cCppOut		start="^\s*\(%:\|#\)\s*if\s\+0\+\>" end=".\@=\|$" contains=cCppOut2
185
syn region	cCppOut2	contained start="0" end="^\s*\(%:\|#\)\s*\(endif\>\|else\>\|elif\>\)" contains=cCppSkip
186
syn region	cCppSkip	contained start="^\s*\(%:\|#\)\s*\(if\>\|ifdef\>\|ifndef\>\)" skip="\\$" end="^\s*\(%:\|#\)\s*endif\>" contains=cCppSkip
187
syn region	cIncluded	display contained start=+"+ skip=+\\\\\|\\"+ end=+"+
188
syn match	cIncluded	display contained "<[^>]*>"
189
syn match	cInclude	display "^\s*\(%:\|#\)\s*include\>\s*["<]" contains=cIncluded
190
syn cluster	cPreProcGroup	contains=cPreCondit,cIncluded,cInclude,cDefine,cCppOut,cCppOut2,cCppSkip,cCommentStartError
191
syn region	cDefine		matchgroup=cPreCondit start="^\s*\(%:\|#\)\s*\(define\|undef\)\>" skip="\\$" end="$"
192
syn region	cPreProc	matchgroup=cPreCondit start="^\s*\(%:\|#\)\s*\(pragma\>\|line\>\|warning\>\|warn\>\|error\>\)" skip="\\$" end="$" keepend
193
194
syn region	cComment	matchgroup=cCommentStart start="/\*" end="\*/" contains=cCommentStartError,cSpaceError contained
195
syntax match	cCommentError	display "\*/" contained
196
syntax match	cCommentStartError display "/\*"me=e-1 contained
197
syn region	cCppString	start=+L\="+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end='$' contains=cSpecial contained
198
199
hi def link hsTypedef          Typedef
200
hi def link hsPattern          Keyword
201
hi def link hsVarSym           hsOperator
202
hi def link hsConSym           hsOperator
203
hi def link hsDelimiter        Delimiter
204
205
hi def link hsModuleStartLabel Structure
206
hi def link hsExportModuleLabel Keyword
207
hi def link hsModuleWhereLabel Structure
208
hi def link hsModuleName       Normal
209
210
hi def link hsImportIllegal    Error
211
hi def link hsAsLabel          hsImportLabel
212
hi def link hsHidingLabel      hsImportLabel
213
hi def link hsImportLabel      Include
214
hi def link hsImportMod        Include
215
hi def link hsPackageString    hsString
216
217
hi def link hsOperator         Operator
218
219
hi def link hsInfix            Keyword
220
hi def link hsStructure        Structure
221
hi def link hsStatement        Statement
222
hi def link hsConditional      Conditional
223
224
hi def link hsSpecialCharError Error
225
hi def link hsSpecialChar      SpecialChar
226
hi def link hsString           String
227
hi def link hsFFIString        String
228
hi def link hsCharacter        Character
229
hi def link hsNumber           Number
230
hi def link hsFloat            Float
231
232
hi def link hsLiterateComment		  hsComment
233
hi def link hsBlockComment     hsComment
234
hi def link hsLineComment      hsComment
235
hi def link hsModuleCommentA   hsComment
236
hi def link hsModuleCommentB   hsComment
237
hi def link hsComment          Comment
238
hi def link hsCommentTodo      Todo
239
hi def link hsPragma           SpecialComment
240
hi def link hsBoolean			  Boolean
241
242
hi def link hsDelimTypeExport  hsType
243
hi def link hsType             Type
244
245
hi def link hsDebug            Debug
246
hi def link hsUndefined        Keyword
247
248
hi def link cCppString         hsString
249
hi def link cCommentStart      hsComment
250
hi def link cCommentError      hsError
251
hi def link cCommentStartError hsError
252
hi def link cInclude           Include
253
hi def link cPreProc           PreProc
254
hi def link cDefine            Macro
255
hi def link cIncluded          hsString
256
hi def link cError             Error
257
hi def link cPreCondit         PreCondit
258
hi def link cComment           Comment
259
hi def link cCppSkip           cCppOut
260
hi def link cCppOut2           cCppOut
261
hi def link cCppOut            Comment
262
263
hi def link hsFFIForeign       Keyword
264
hi def link hsFFIImportExport  Structure
265
hi def link hsFFICallConvention Keyword
266
hi def link hsFFISafety         Keyword
267
268
hi def link hsTHIDTopLevel   Macro
269
hi def link hsTHTopLevelName Macro
270
271
hi def link hsQQVarID Keyword
272
hi def link hsQQVarIDNew Keyword
273
hi def link hsQQEnd   Keyword
274
hi def link hsQQContent String
275
276
let b:current_syntax = "haskell"