haskell.vim (14955B)
1 " Vim syntax file 2 " 3 " Modification of vims Haskell syntax file: 4 " - match types using regular expression 5 " - highlight toplevel functions 6 " - use "syntax keyword" instead of "syntax match" where appropriate 7 " - functions and types in import and module declarations are matched 8 " - removed hs_highlight_more_types (just not needed anymore) 9 " - enable spell checking in comments and strings only 10 " - FFI highlighting 11 " - QuasiQuotation 12 " - top level Template Haskell slices 13 " - PackageImport 14 " 15 " TODO: find out which vim versions are still supported 16 " 17 " From Original file: 18 " =================== 19 " 20 " Language: Haskell 21 " Maintainer: Haskell Cafe mailinglist <haskell-cafe@haskell.org> 22 " Last Change: 2010 Feb 21 23 " Original Author: John Williams <jrw@pobox.com> 24 " 25 " Thanks to Ryan Crumley for suggestions and John Meacham for 26 " pointing out bugs. Also thanks to Ian Lynagh and Donald Bruce Stewart 27 " for providing the inspiration for the inclusion of the handling 28 " of C preprocessor directives, and for pointing out a bug in the 29 " end-of-line comment handling. 30 " 31 " Options-assign a value to these variables to turn the option on: 32 " 33 " hs_highlight_delimiters - Highlight delimiter characters--users 34 " with a light-colored background will 35 " probably want to turn this on. 36 " hs_highlight_boolean - Treat True and False as keywords. 37 " hs_highlight_types - Treat names of primitive types as keywords. 38 " hs_highlight_debug - Highlight names of debugging functions. 39 " hs_allow_hash_operator - Don't highlight seemingly incorrect C 40 " preprocessor directives but assume them to be 41 " operators 42 " 43 " 44 45 if version < 600 46 syn clear 47 elseif exists("b:current_syntax") 48 finish 49 endif 50 51 "syntax sync fromstart "mmhhhh.... is this really ok to do so? 52 syntax sync linebreaks=15 minlines=50 maxlines=500 53 54 syn match hsSpecialChar contained "\\\([0-9]\+\|o[0-7]\+\|x[0-9a-fA-F]\+\|[\"\\'&\\abfnrtv]\|^[A-Z^_\[\\\]]\)" 55 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\)" 56 syn match hsSpecialCharError contained "\\&\|'''\+" 57 sy region hsString start=+"+ skip=+\\\\\|\\"+ end=+"+ contains=hsSpecialChar,@Spell 58 sy match hsCharacter "[^a-zA-Z0-9_']'\([^\\]\|\\[^']\+\|\\'\)'"lc=1 contains=hsSpecialChar,hsSpecialCharError 59 sy match hsCharacter "^'\([^\\]\|\\[^']\+\|\\'\)'" contains=hsSpecialChar,hsSpecialCharError 60 61 " (Qualified) identifiers (no default highlighting) 62 syn match ConId "\(\<[A-Z][a-zA-Z0-9_']*\.\)\=\<[A-Z][a-zA-Z0-9_']*\>" 63 syn match VarId "\(\<[A-Z][a-zA-Z0-9_']*\.\)\=\<[a-z][a-zA-Z0-9_']*\>" 64 65 " Infix operators--most punctuation characters and any (qualified) identifier 66 " enclosed in `backquotes`. An operator starting with : is a constructor, 67 " others are variables (e.g. functions). 68 syn match hsVarSym "\(\<[A-Z][a-zA-Z0-9_']*\.\)\=[-!#$%&\*\+/<=>\?@\\^|~.][-!#$%&\*\+/<=>\?@\\^|~:.]*" 69 syn match hsConSym "\(\<[A-Z][a-zA-Z0-9_']*\.\)\=:[-!#$%&\*\+./<=>\?@\\^|~:]*" 70 syn match hsVarSym "`\(\<[A-Z][a-zA-Z0-9_']*\.\)\=[a-z][a-zA-Z0-9_']*`" 71 syn match hsConSym "`\(\<[A-Z][a-zA-Z0-9_']*\.\)\=[A-Z][a-zA-Z0-9_']*`" 72 73 " Toplevel Template Haskell support 74 "sy match hsTHTopLevel "^[a-z]\(\(.\&[^=]\)\|\(\n[^a-zA-Z0-9]\)\)*" 75 sy match hsTHIDTopLevel "^[a-z]\S*" 76 sy match hsTHTopLevel "^\$(\?" nextgroup=hsTHTopLevelName 77 sy match hsTHTopLevelName "[a-z]\S*" contained 78 79 " Reserved symbols--cannot be overloaded. 80 syn match hsDelimiter "(\|)\|\[\|\]\|,\|;\|_\|{\|}" 81 82 sy region hsInnerParen start="(" end=")" contained contains=hsInnerParen,hsConSym,hsType,hsVarSym 83 sy region hs_InfixOpFunctionName start="^(" end=")\s*[^:`]\(\W\&\S\&[^'\"`()[\]{}@]\)\+"re=s 84 \ contained keepend contains=hsInnerParen,hs_HlInfixOp 85 86 sy match hs_hlFunctionName "[a-z_]\(\S\&[^,\(\)\[\]]\)*" contained 87 sy match hs_FunctionName "^[a-z_]\(\S\&[^,\(\)\[\]]\)*" contained contains=hs_hlFunctionName 88 sy match hs_HighliteInfixFunctionName "`[a-z_][^`]*`" contained 89 sy match hs_InfixFunctionName "^\S[^=]*`[a-z_][^`]*`"me=e-1 contained contains=hs_HighliteInfixFunctionName,hsType,hsConSym,hsVarSym,hsString,hsCharacter 90 sy match hs_HlInfixOp "\(\W\&\S\&[^`(){}'[\]]\)\+" contained contains=hsString 91 sy match hs_InfixOpFunctionName "^\(\(\w\|[[\]{}]\)\+\|\(\".*\"\)\|\('.*'\)\)\s*[^:]=*\(\W\&\S\&[^='\"`()[\]{}@]\)\+" 92 \ contained contains=hs_HlInfixOp,hsCharacter 93 94 sy match hs_OpFunctionName "(\(\W\&[^(),\"]\)\+)" contained 95 "sy region hs_Function start="^["'a-z_([{]" end="=\(\s\|\n\|\w\|[([]\)" keepend extend 96 sy region hs_Function start="^["'a-zA-Z_([{]\(\(.\&[^=]\)\|\(\n\s\)\)*=" end="\(\s\|\n\|\w\|[([]\)" 97 \ contains=hs_OpFunctionName,hs_InfixOpFunctionName,hs_InfixFunctionName,hs_FunctionName,hsType,hsConSym,hsVarSym,hsString,hsCharacter 98 99 sy match hs_DeclareFunction "^[a-z_(]\S*\(\s\|\n\)*::" contains=hs_FunctionName,hs_OpFunctionName 100 101 " hi hs_InfixOpFunctionName guibg=bg 102 " hi hs_Function guibg=green 103 " hi hs_InfixFunctionName guibg=red 104 " hi hs_DeclareFunction guibg=red 105 106 sy keyword hsStructure data family class where instance default deriving 107 sy keyword hsTypedef type newtype 108 109 sy keyword hsInfix infix infixl infixr 110 sy keyword hsStatement do case of let in 111 sy keyword hsConditional if then else 112 113 "if exists("hs_highlight_types") 114 " Primitive types from the standard prelude and libraries. 115 sy match hsType "\<[A-Z]\(\S\&[^,.]\)*\>" 116 sy match hsType "()" 117 "endif 118 119 " Not real keywords, but close. 120 if exists("hs_highlight_boolean") 121 " Boolean constants from the standard prelude. 122 syn keyword hsBoolean True False 123 endif 124 125 syn region hsPackageString start=+L\="+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end='$' contains=cSpecial contained 126 sy match hsModuleName excludenl "\([A-Z]\w*\.\?\)*" contained 127 128 sy match hsImport "\<import\>\s\+\(qualified\s\+\)\?\(\<\(\w\|\.\)*\>\)" 129 \ contains=hsModuleName,hsImportLabel 130 \ nextgroup=hsImportParams,hsImportIllegal skipwhite 131 sy keyword hsImportLabel import qualified contained 132 133 sy match hsImportIllegal "\w\+" contained 134 135 sy keyword hsAsLabel as contained 136 sy keyword hsHidingLabel hiding contained 137 138 sy match hsImportParams "as\s\+\(\w\+\)" contained 139 \ contains=hsModuleName,hsAsLabel 140 \ nextgroup=hsImportParams,hsImportIllegal skipwhite 141 sy match hsImportParams "hiding" contained 142 \ contains=hsHidingLabel 143 \ nextgroup=hsImportParams,hsImportIllegal skipwhite 144 sy region hsImportParams start="(" end=")" contained 145 \ contains=hsBlockComment,hsLineComment, hsType,hsDelimTypeExport,hs_hlFunctionName,hs_OpFunctionName 146 \ nextgroup=hsImportIllegal skipwhite 147 148 " hi hsImport guibg=red 149 "hi hsImportParams guibg=bg 150 "hi hsImportIllegal guibg=bg 151 "hi hsModuleName guibg=bg 152 153 "sy match hsImport "\<import\>\(.\|[^(]\)*\((.*)\)\?" 154 " \ contains=hsPackageString,hsImportLabel,hsImportMod,hsModuleName,hsImportList 155 "sy keyword hsImportLabel import contained 156 "sy keyword hsImportMod as qualified hiding contained 157 "sy region hsImportListInner start="(" end=")" contained keepend extend contains=hs_OpFunctionName 158 "sy region hsImportList matchgroup=hsImportListParens start="("rs=s+1 end=")"re=e-1 159 " \ contained 160 " \ keepend extend 161 " \ contains=hsType,hsLineComment,hsBlockComment,hs_hlFunctionName,hsImportListInner 162 163 164 165 " new module highlighting 166 syn region hsDelimTypeExport start="\<[A-Z]\(\S\&[^,.]\)*\>(" end=")" contained 167 \ contains=hsType 168 169 sy keyword hsExportModuleLabel module contained 170 sy match hsExportModule "\<module\>\(\s\|\t\|\n\)*\([A-Z]\w*\.\?\)*" contained contains=hsExportModuleLabel,hsModuleName 171 172 sy keyword hsModuleStartLabel module contained 173 sy keyword hsModuleWhereLabel where contained 174 175 syn match hsModuleStart "^module\(\s\|\n\)*\(\<\(\w\|\.\)*\>\)\(\s\|\n\)*" 176 \ contains=hsModuleStartLabel,hsModuleName 177 \ nextgroup=hsModuleCommentA,hsModuleExports,hsModuleWhereLabel 178 179 syn region hsModuleCommentA start="{-" end="-}" 180 \ contains=hsModuleCommentA,hsCommentTodo,@Spell contained 181 \ nextgroup=hsModuleCommentA,hsModuleExports,hsModuleWhereLabel skipwhite skipnl 182 183 syn match hsModuleCommentA "--.*\n" 184 \ contains=hsCommentTodo,@Spell contained 185 \ nextgroup=hsModuleCommentA,hsModuleExports,hsModuleWhereLabel skipwhite skipnl 186 187 syn region hsModuleExports start="(" end=")" contained 188 \ nextgroup=hsModuleCommentB,hsModuleWhereLabel skipwhite skipnl 189 \ contains=hsBlockComment,hsLineComment,hsType,hsDelimTypeExport,hs_hlFunctionName,hs_OpFunctionName,hsExportModule 190 191 syn match hsModuleCommentB "--.*\n" 192 \ contains=hsCommentTodo,@Spell contained 193 \ nextgroup=hsModuleCommentB,hsModuleWhereLabel skipwhite skipnl 194 195 syn region hsModuleCommentB start="{-" end="-}" 196 \ contains=hsModuleCommentB,hsCommentTodo,@Spell contained 197 \ nextgroup=hsModuleCommentB,hsModuleWhereLabel skipwhite skipnl 198 " end module highlighting 199 200 " FFI support 201 sy keyword hsFFIForeign foreign contained 202 "sy keyword hsFFIImportExport import export contained 203 sy keyword hsFFIImportExport export contained 204 sy keyword hsFFICallConvention ccall stdcall contained 205 sy keyword hsFFISafety safe unsafe contained 206 sy region hsFFIString start=+"+ skip=+\\\\\|\\"+ end=+"+ contained contains=hsSpecialChar 207 sy match hsFFI excludenl "\<foreign\>\(.\&[^\"]\)*\"\(.\)*\"\(\s\|\n\)*\(.\)*::" 208 \ keepend 209 \ contains=hsFFIForeign,hsFFIImportExport,hsFFICallConvention,hsFFISafety,hsFFIString,hs_OpFunctionName,hs_hlFunctionName 210 211 212 sy match hsNumber "\<[0-9]\+\>\|\<0[xX][0-9a-fA-F]\+\>\|\<0[oO][0-7]\+\>" 213 sy match hsFloat "\<[0-9]\+\.[0-9]\+\([eE][-+]\=[0-9]\+\)\=\>" 214 215 " Comments 216 sy keyword hsCommentTodo TODO FIXME XXX TBD contained 217 sy match hsLineComment "---*\([^-!#$%&\*\+./<=>\?@\\^|~].*\)\?$" contains=hsCommentTodo,@Spell 218 sy region hsBlockComment start="{-" end="-}" contains=hsBlockComment,hsCommentTodo,@Spell 219 sy region hsPragma start="{-#" end="#-}" 220 221 " QuasiQuotation 222 sy region hsQQ start="\[\$" end="|\]"me=e-2 keepend contains=hsQQVarID,hsQQContent nextgroup=hsQQEnd 223 sy region hsQQNew start="\[\(.\&[^|]\&\S\)*|" end="|\]"me=e-2 keepend contains=hsQQVarIDNew,hsQQContent nextgroup=hsQQEnd 224 sy match hsQQContent ".*" contained 225 sy match hsQQEnd "|\]" contained 226 sy match hsQQVarID "\[\$\(.\&[^|]\)*|" contained 227 sy match hsQQVarIDNew "\[\(.\&[^|]\)*|" contained 228 229 if exists("hs_highlight_debug") 230 " Debugging functions from the standard prelude. 231 syn keyword hsDebug undefined error trace 232 endif 233 234 235 " C Preprocessor directives. Shamelessly ripped from c.vim and trimmed 236 " First, see whether to flag directive-like lines or not 237 if (!exists("hs_allow_hash_operator")) 238 syn match cError display "^\s*\(%:\|#\).*$" 239 endif 240 " Accept %: for # (C99) 241 syn region cPreCondit start="^\s*\(%:\|#\)\s*\(if\|ifdef\|ifndef\|elif\)\>" skip="\\$" end="$" end="//"me=s-1 contains=cComment,cCppString,cCommentError 242 syn match cPreCondit display "^\s*\(%:\|#\)\s*\(else\|endif\)\>" 243 syn region cCppOut start="^\s*\(%:\|#\)\s*if\s\+0\+\>" end=".\@=\|$" contains=cCppOut2 244 syn region cCppOut2 contained start="0" end="^\s*\(%:\|#\)\s*\(endif\>\|else\>\|elif\>\)" contains=cCppSkip 245 syn region cCppSkip contained start="^\s*\(%:\|#\)\s*\(if\>\|ifdef\>\|ifndef\>\)" skip="\\$" end="^\s*\(%:\|#\)\s*endif\>" contains=cCppSkip 246 syn region cIncluded display contained start=+"+ skip=+\\\\\|\\"+ end=+"+ 247 syn match cIncluded display contained "<[^>]*>" 248 syn match cInclude display "^\s*\(%:\|#\)\s*include\>\s*["<]" contains=cIncluded 249 syn cluster cPreProcGroup contains=cPreCondit,cIncluded,cInclude,cDefine,cCppOut,cCppOut2,cCppSkip,cCommentStartError 250 syn region cDefine matchgroup=cPreCondit start="^\s*\(%:\|#\)\s*\(define\|undef\)\>" skip="\\$" end="$" 251 syn region cPreProc matchgroup=cPreCondit start="^\s*\(%:\|#\)\s*\(pragma\>\|line\>\|warning\>\|warn\>\|error\>\)" skip="\\$" end="$" keepend 252 253 syn region cComment matchgroup=cCommentStart start="/\*" end="\*/" contains=cCommentStartError,cSpaceError contained 254 syntax match cCommentError display "\*/" contained 255 syntax match cCommentStartError display "/\*"me=e-1 contained 256 syn region cCppString start=+L\="+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end='$' contains=cSpecial contained 257 258 259 if version >= 508 || !exists("did_hs_syntax_inits") 260 if version < 508 261 let did_hs_syntax_inits = 1 262 command -nargs=+ HiLink hi link <args> 263 else 264 command -nargs=+ HiLink hi def link <args> 265 endif 266 267 HiLink hs_hlFunctionName Function 268 HiLink hs_HighliteInfixFunctionName Function 269 HiLink hs_HlInfixOp Function 270 HiLink hs_OpFunctionName Function 271 HiLink hsTypedef Statement 272 HiLink hsVarSym hsOperator 273 HiLink hsConSym hsOperator 274 if exists("hs_highlight_delimiters") 275 " Some people find this highlighting distracting. 276 HiLink hsDelimiter Delimiter 277 endif 278 279 HiLink hsModuleStartLabel Structure 280 HiLink hsExportModuleLabel Keyword 281 HiLink hsModuleWhereLabel Structure 282 HiLink hsModuleName Normal 283 284 HiLink hsImportIllegal Error 285 HiLink hsAsLabel hsImportLabel 286 HiLink hsHidingLabel hsImportLabel 287 HiLink hsImportLabel Include 288 HiLink hsImportMod Include 289 HiLink hsPackageString hsString 290 291 HiLink hsOperator Operator 292 293 HiLink hsInfix Keyword 294 HiLink hsStructure Statement 295 HiLink hsStatement Statement 296 HiLink hsConditional Conditional 297 298 HiLink hsSpecialCharError Error 299 HiLink hsSpecialChar SpecialChar 300 HiLink hsString String 301 HiLink hsFFIString String 302 HiLink hsCharacter Character 303 HiLink hsNumber Number 304 HiLink hsFloat Float 305 306 HiLink hsLiterateComment hsComment 307 HiLink hsBlockComment hsComment 308 HiLink hsLineComment hsComment 309 HiLink hsModuleCommentA hsComment 310 HiLink hsModuleCommentB hsComment 311 HiLink hsComment Comment 312 HiLink hsCommentTodo Todo 313 HiLink hsPragma SpecialComment 314 HiLink hsBoolean Boolean 315 316 if exists("hs_highlight_types") 317 HiLink hsDelimTypeExport hsType 318 HiLink hsType Type 319 endif 320 321 HiLink hsDebug Debug 322 323 HiLink cCppString hsString 324 HiLink cCommentStart hsComment 325 HiLink cCommentError hsError 326 HiLink cCommentStartError hsError 327 HiLink cInclude Include 328 HiLink cPreProc PreProc 329 HiLink cDefine Macro 330 HiLink cIncluded hsString 331 HiLink cError Error 332 HiLink cPreCondit PreCondit 333 HiLink cComment Comment 334 HiLink cCppSkip cCppOut 335 HiLink cCppOut2 cCppOut 336 HiLink cCppOut Comment 337 338 HiLink hsFFIForeign Keyword 339 HiLink hsFFIImportExport Structure 340 HiLink hsFFICallConvention Keyword 341 HiLink hsFFISafety Keyword 342 343 HiLink hsTHIDTopLevel Macro 344 HiLink hsTHTopLevelName Macro 345 346 HiLink hsQQVarID Keyword 347 HiLink hsQQVarIDNew Keyword 348 HiLink hsQQEnd Keyword 349 HiLink hsQQContent String 350 351 delcommand HiLink 352 endif 353 354 let b:current_syntax = "haskell" 355