Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

add haskell syntax file.

  • Loading branch information...
commit d243283a5dd5950a72c623b339e78599924a3602 1 parent 4c408e3
Murahashi Sanemat Kenichi authored February 19, 2012

Showing 1 changed file with 360 additions and 0 deletions. Show diff stats Hide diff stats

  1. 360  .vim/syntax/haskell.vim
360  .vim/syntax/haskell.vim
... ...
@@ -0,0 +1,360 @@
  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_TypeOp "::"
  100
+sy match hs_DeclareFunction "^[a-z_(]\S*\(\s\|\n\)*::" contains=hs_FunctionName,hs_OpFunctionName,hs_TypeOp
  101
+
  102
+" hi hs_TypeOp guibg=red
  103
+
  104
+" hi hs_InfixOpFunctionName guibg=yellow
  105
+" hi hs_Function guibg=green
  106
+" hi hs_InfixFunctionName guibg=red
  107
+" hi hs_DeclareFunction guibg=red
  108
+
  109
+sy keyword hsStructure data family class where instance default deriving
  110
+sy keyword hsTypedef type newtype
  111
+
  112
+sy keyword hsInfix infix infixl infixr
  113
+sy keyword hsStatement  do case of let in
  114
+sy keyword hsConditional if then else
  115
+
  116
+"if exists("hs_highlight_types")
  117
+  " Primitive types from the standard prelude and libraries.
  118
+  sy match hsType "\<[A-Z]\(\S\&[^,.]\)*\>"
  119
+  sy match hsType "()"
  120
+"endif
  121
+
  122
+" Not real keywords, but close.
  123
+if exists("hs_highlight_boolean")
  124
+  " Boolean constants from the standard prelude.
  125
+  syn keyword hsBoolean True False
  126
+endif
  127
+
  128
+syn region	hsPackageString	start=+L\="+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end='$' contains=cSpecial contained
  129
+sy match   hsModuleName  excludenl "\([A-Z]\w*\.\?\)*" contained 
  130
+
  131
+sy match hsImport "\<import\>\s\+\(qualified\s\+\)\?\(\<\(\w\|\.\)*\>\)" 
  132
+    \ contains=hsModuleName,hsImportLabel
  133
+    \ nextgroup=hsImportParams,hsImportIllegal skipwhite
  134
+sy keyword hsImportLabel import qualified contained
  135
+
  136
+sy match hsImportIllegal "\w\+" contained
  137
+
  138
+sy keyword hsAsLabel as contained
  139
+sy keyword hsHidingLabel hiding contained
  140
+
  141
+sy match hsImportParams "as\s\+\(\w\+\)" contained
  142
+    \ contains=hsModuleName,hsAsLabel
  143
+    \ nextgroup=hsImportParams,hsImportIllegal skipwhite
  144
+sy match hsImportParams "hiding" contained
  145
+    \ contains=hsHidingLabel
  146
+    \ nextgroup=hsImportParams,hsImportIllegal skipwhite 
  147
+sy region hsImportParams start="(" end=")" contained
  148
+    \ contains=hsBlockComment,hsLineComment, hsType,hsDelimTypeExport,hs_hlFunctionName,hs_OpFunctionName
  149
+    \ nextgroup=hsImportIllegal skipwhite
  150
+
  151
+" hi hsImport guibg=red
  152
+"hi hsImportParams guibg=bg
  153
+"hi hsImportIllegal guibg=bg
  154
+"hi hsModuleName guibg=bg
  155
+
  156
+"sy match hsImport		"\<import\>\(.\|[^(]\)*\((.*)\)\?" 
  157
+"         \ contains=hsPackageString,hsImportLabel,hsImportMod,hsModuleName,hsImportList
  158
+"sy keyword hsImportLabel import contained
  159
+"sy keyword hsImportMod		as qualified hiding contained
  160
+"sy region hsImportListInner start="(" end=")" contained keepend extend contains=hs_OpFunctionName
  161
+"sy region  hsImportList matchgroup=hsImportListParens start="("rs=s+1 end=")"re=e-1
  162
+"        \ contained 
  163
+"        \ keepend extend
  164
+"        \ contains=hsType,hsLineComment,hsBlockComment,hs_hlFunctionName,hsImportListInner
  165
+
  166
+
  167
+
  168
+" new module highlighting
  169
+syn region hsDelimTypeExport start="\<[A-Z]\(\S\&[^,.]\)*\>(" end=")" contained
  170
+   \ contains=hsType
  171
+
  172
+sy keyword hsExportModuleLabel module contained
  173
+sy match hsExportModule "\<module\>\(\s\|\t\|\n\)*\([A-Z]\w*\.\?\)*" contained contains=hsExportModuleLabel,hsModuleName
  174
+
  175
+sy keyword hsModuleStartLabel module contained
  176
+sy keyword hsModuleWhereLabel where contained
  177
+
  178
+syn match hsModuleStart "^module\(\s\|\n\)*\(\<\(\w\|\.\)*\>\)\(\s\|\n\)*" 
  179
+  \ contains=hsModuleStartLabel,hsModuleName
  180
+  \ nextgroup=hsModuleCommentA,hsModuleExports,hsModuleWhereLabel
  181
+
  182
+syn region hsModuleCommentA start="{-" end="-}"
  183
+  \ contains=hsModuleCommentA,hsCommentTodo,@Spell contained
  184
+  \ nextgroup=hsModuleCommentA,hsModuleExports,hsModuleWhereLabel skipwhite skipnl
  185
+
  186
+syn match hsModuleCommentA "--.*\n"
  187
+  \ contains=hsCommentTodo,@Spell contained
  188
+  \ nextgroup=hsModuleCommentA,hsModuleExports,hsModuleWhereLabel skipwhite skipnl
  189
+
  190
+syn region hsModuleExports start="(" end=")" contained
  191
+   \ nextgroup=hsModuleCommentB,hsModuleWhereLabel skipwhite skipnl
  192
+   \ contains=hsBlockComment,hsLineComment,hsType,hsDelimTypeExport,hs_hlFunctionName,hs_OpFunctionName,hsExportModule
  193
+
  194
+syn match hsModuleCommentB "--.*\n"
  195
+  \ contains=hsCommentTodo,@Spell contained
  196
+  \ nextgroup=hsModuleCommentB,hsModuleWhereLabel skipwhite skipnl
  197
+
  198
+syn region hsModuleCommentB start="{-" end="-}"
  199
+   \ contains=hsModuleCommentB,hsCommentTodo,@Spell contained
  200
+   \ nextgroup=hsModuleCommentB,hsModuleWhereLabel skipwhite skipnl
  201
+" end module highlighting
  202
+
  203
+" FFI support
  204
+sy keyword hsFFIForeign foreign contained
  205
+"sy keyword hsFFIImportExport import export contained
  206
+sy keyword hsFFIImportExport export contained
  207
+sy keyword hsFFICallConvention ccall stdcall contained
  208
+sy keyword hsFFISafety safe unsafe contained
  209
+sy region  hsFFIString		start=+"+  skip=+\\\\\|\\"+  end=+"+  contained contains=hsSpecialChar
  210
+sy match hsFFI excludenl "\<foreign\>\(.\&[^\"]\)*\"\(.\)*\"\(\s\|\n\)*\(.\)*::"
  211
+  \ keepend
  212
+  \ contains=hsFFIForeign,hsFFIImportExport,hsFFICallConvention,hsFFISafety,hsFFIString,hs_OpFunctionName,hs_hlFunctionName
  213
+
  214
+
  215
+sy match   hsNumber		"\<[0-9]\+\>\|\<0[xX][0-9a-fA-F]\+\>\|\<0[oO][0-7]\+\>"
  216
+sy match   hsFloat		"\<[0-9]\+\.[0-9]\+\([eE][-+]\=[0-9]\+\)\=\>"
  217
+
  218
+" Comments
  219
+sy keyword hsCommentTodo    TODO FIXME XXX TBD contained
  220
+sy match   hsLineComment      "---*\([^-!#$%&\*\+./<=>\?@\\^|~].*\)\?$" contains=hsCommentTodo,@Spell
  221
+sy region  hsBlockComment     start="{-"  end="-}" contains=hsBlockComment,hsCommentTodo,@Spell
  222
+sy region  hsPragma	       start="{-#" end="#-}"
  223
+
  224
+" QuasiQuotation
  225
+sy region hsQQ start="\[\$" end="|\]"me=e-2 keepend contains=hsQQVarID,hsQQContent nextgroup=hsQQEnd
  226
+sy region hsQQNew start="\[\(.\&[^|]\&\S\)*|" end="|\]"me=e-2 keepend contains=hsQQVarIDNew,hsQQContent nextgroup=hsQQEnd
  227
+sy match hsQQContent ".*" contained
  228
+sy match hsQQEnd "|\]" contained
  229
+sy match hsQQVarID "\[\$\(.\&[^|]\)*|" contained
  230
+sy match hsQQVarIDNew "\[\(.\&[^|]\)*|" contained
  231
+
  232
+if exists("hs_highlight_debug")
  233
+  " Debugging functions from the standard prelude.
  234
+  syn keyword hsDebug undefined error trace
  235
+endif
  236
+
  237
+
  238
+" C Preprocessor directives. Shamelessly ripped from c.vim and trimmed
  239
+" First, see whether to flag directive-like lines or not
  240
+if (!exists("hs_allow_hash_operator"))
  241
+    syn match	cError		display "^\s*\(%:\|#\).*$"
  242
+endif
  243
+" Accept %: for # (C99)
  244
+syn region	cPreCondit	start="^\s*\(%:\|#\)\s*\(if\|ifdef\|ifndef\|elif\)\>" skip="\\$" end="$" end="//"me=s-1 contains=cComment,cCppString,cCommentError
  245
+syn match	cPreCondit	display "^\s*\(%:\|#\)\s*\(else\|endif\)\>"
  246
+syn region	cCppOut		start="^\s*\(%:\|#\)\s*if\s\+0\+\>" end=".\@=\|$" contains=cCppOut2
  247
+syn region	cCppOut2	contained start="0" end="^\s*\(%:\|#\)\s*\(endif\>\|else\>\|elif\>\)" contains=cCppSkip
  248
+syn region	cCppSkip	contained start="^\s*\(%:\|#\)\s*\(if\>\|ifdef\>\|ifndef\>\)" skip="\\$" end="^\s*\(%:\|#\)\s*endif\>" contains=cCppSkip
  249
+syn region	cIncluded	display contained start=+"+ skip=+\\\\\|\\"+ end=+"+
  250
+syn match	cIncluded	display contained "<[^>]*>"
  251
+syn match	cInclude	display "^\s*\(%:\|#\)\s*include\>\s*["<]" contains=cIncluded
  252
+syn cluster	cPreProcGroup	contains=cPreCondit,cIncluded,cInclude,cDefine,cCppOut,cCppOut2,cCppSkip,cCommentStartError
  253
+syn region	cDefine		matchgroup=cPreCondit start="^\s*\(%:\|#\)\s*\(define\|undef\)\>" skip="\\$" end="$"
  254
+syn region	cPreProc	matchgroup=cPreCondit start="^\s*\(%:\|#\)\s*\(pragma\>\|line\>\|warning\>\|warn\>\|error\>\)" skip="\\$" end="$" keepend
  255
+
  256
+syn region	cComment	matchgroup=cCommentStart start="/\*" end="\*/" contains=cCommentStartError,cSpaceError contained
  257
+syntax match	cCommentError	display "\*/" contained
  258
+syntax match	cCommentStartError display "/\*"me=e-1 contained
  259
+syn region	cCppString	start=+L\="+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end='$' contains=cSpecial contained
  260
+
  261
+
  262
+if version >= 508 || !exists("did_hs_syntax_inits")
  263
+  if version < 508
  264
+    let did_hs_syntax_inits = 1
  265
+    command -nargs=+ HiLink hi link <args>
  266
+  else
  267
+    command -nargs=+ HiLink hi def link <args>
  268
+  endif
  269
+
  270
+  HiLink hs_hlFunctionName    Function
  271
+  HiLink hs_HighliteInfixFunctionName Function
  272
+  HiLink hs_HlInfixOp       Function
  273
+  HiLink hs_OpFunctionName  Function
  274
+  HiLink hsTypedef          Typedef
  275
+  HiLink hsVarSym           hsOperator
  276
+  HiLink hsConSym           hsOperator
  277
+  if exists("hs_highlight_delimiters")
  278
+    " Some people find this highlighting distracting.
  279
+	HiLink hsDelimiter        Delimiter
  280
+  endif
  281
+
  282
+  HiLink hsModuleStartLabel Structure
  283
+  HiLink hsExportModuleLabel Keyword
  284
+  HiLink hsModuleWhereLabel Structure
  285
+  HiLink hsModuleName       Normal
  286
+  
  287
+  HiLink hsImportIllegal    Error
  288
+  HiLink hsAsLabel          hsImportLabel
  289
+  HiLink hsHidingLabel      hsImportLabel
  290
+  HiLink hsImportLabel      Include
  291
+  HiLink hsImportMod        Include
  292
+  HiLink hsPackageString    hsString
  293
+
  294
+  HiLink hsOperator         Operator
  295
+
  296
+  HiLink hsInfix            Keyword
  297
+  HiLink hsStructure        Structure
  298
+  HiLink hsStatement        Statement
  299
+  HiLink hsConditional      Conditional
  300
+
  301
+  HiLink hsSpecialCharError Error
  302
+  HiLink hsSpecialChar      SpecialChar
  303
+  HiLink hsString           String
  304
+  HiLink hsFFIString        String
  305
+  HiLink hsCharacter        Character
  306
+  HiLink hsNumber           Number
  307
+  HiLink hsFloat            Float
  308
+
  309
+  HiLink hsLiterateComment		  hsComment
  310
+  HiLink hsBlockComment     hsComment
  311
+  HiLink hsLineComment      hsComment
  312
+  HiLink hsModuleCommentA   hsComment
  313
+  HiLink hsModuleCommentB   hsComment
  314
+  HiLink hsComment          Comment
  315
+  HiLink hsCommentTodo      Todo
  316
+  HiLink hsPragma           SpecialComment
  317
+  HiLink hsBoolean			  Boolean
  318
+
  319
+  if exists("hs_highlight_types")
  320
+      HiLink hsDelimTypeExport  hsType
  321
+      HiLink hsType             Type
  322
+  endif
  323
+
  324
+  HiLink hsDebug            Debug
  325
+
  326
+  HiLink hs_TypeOp          hsOperator
  327
+
  328
+  HiLink cCppString         hsString
  329
+  HiLink cCommentStart      hsComment
  330
+  HiLink cCommentError      hsError
  331
+  HiLink cCommentStartError hsError
  332
+  HiLink cInclude           Include
  333
+  HiLink cPreProc           PreProc
  334
+  HiLink cDefine            Macro
  335
+  HiLink cIncluded          hsString
  336
+  HiLink cError             Error
  337
+  HiLink cPreCondit         PreCondit
  338
+  HiLink cComment           Comment
  339
+  HiLink cCppSkip           cCppOut
  340
+  HiLink cCppOut2           cCppOut
  341
+  HiLink cCppOut            Comment
  342
+
  343
+  HiLink hsFFIForeign       Keyword
  344
+  HiLink hsFFIImportExport  Structure
  345
+  HiLink hsFFICallConvention Keyword
  346
+  HiLink hsFFISafety         Keyword
  347
+
  348
+  HiLink hsTHIDTopLevel   Macro
  349
+  HiLink hsTHTopLevelName Macro
  350
+
  351
+  HiLink hsQQVarID Keyword
  352
+  HiLink hsQQVarIDNew Keyword
  353
+  HiLink hsQQEnd   Keyword
  354
+  HiLink hsQQContent String
  355
+
  356
+  delcommand HiLink
  357
+endif
  358
+
  359
+let b:current_syntax = "haskell"
  360
+

0 notes on commit d243283

Please sign in to comment.
Something went wrong with that request. Please try again.