3 " Maintainer: Haskell Cafe mailinglist <haskell-cafe@haskell.org>
4 " Last Change: 2008 Dec 15
5 " Original Author: John Williams <jrw@pobox.com>
7 " Thanks to Ryan Crumley for suggestions and John Meacham for
8 " pointing out bugs. Also thanks to Ian Lynagh and Donald Bruce Stewart
9 " for providing the inspiration for the inclusion of the handling
10 " of C preprocessor directives, and for pointing out a bug in the
11 " end-of-line comment handling.
13 " Options-assign a value to these variables to turn the option on:
15 " hs_highlight_delimiters - Highlight delimiter characters--users
16 " with a light-colored background will
17 " probably want to turn this on.
18 " hs_highlight_boolean - Treat True and False as keywords.
19 " hs_highlight_types - Treat names of primitive types as keywords.
20 " hs_highlight_more_types - Treat names of other common types as keywords.
21 " hs_highlight_debug - Highlight names of debugging functions.
22 " hs_allow_hash_operator - Don't highlight seemingly incorrect C
23 " preprocessor directives but assume them to be
26 " 2004 Feb 19: Added C preprocessor directive handling, corrected eol comments
27 " cleaned away literate haskell support (should be entirely in
29 " 2004 Feb 20: Cleaned up C preprocessor directive handling, fixed single \
30 " in eol comment character class
31 " 2004 Feb 23: Made the leading comments somewhat clearer where it comes
32 " to attribution of work.
33 " 2008 Dec 15: Added comments as contained element in import statements
35 " Remove any old syntax stuff hanging around
38 elseif exists("b:current_syntax")
42 " (Qualified) identifiers (no default highlighting)
43 syn match ConId "\(\<[A-Z][a-zA-Z0-9_']*\.\)\=\<[A-Z][a-zA-Z0-9_']*\>"
44 syn match VarId "\(\<[A-Z][a-zA-Z0-9_']*\.\)\=\<[a-z][a-zA-Z0-9_']*\>"
46 syn match hsTopDecl "^[a-z][a-zA-Z0-9_']*"
48 " Infix operators--most punctuation characters and any (qualified) identifier
49 " enclosed in `backquotes`. An operator starting with : is a constructor,
50 " others are variables (e.g. functions).
51 syn match hsVarSym "\(\<[A-Z][a-zA-Z0-9_']*\.\)\=[-!#$%&\*\+/<=>\?@\\^|~.][-!#$%&\*\+/<=>\?@\\^|~:.]*"
52 syn match hsConSym "\(\<[A-Z][a-zA-Z0-9_']*\.\)\=:[-!#$%&\*\+./<=>\?@\\^|~:]*"
53 syn match hsVarSym "`\(\<[A-Z][a-zA-Z0-9_']*\.\)\=[a-z][a-zA-Z0-9_']*`"
54 syn match hsConSym "`\(\<[A-Z][a-zA-Z0-9_']*\.\)\=[A-Z][a-zA-Z0-9_']*`"
56 " Reserved symbols--cannot be overloaded.
57 syn match hsDelimiter "(\|)\|\[\|\]\|,\|;\|_\|{\|}"
59 " Strings and constants
60 syn match hsSpecialChar contained "\\\([0-9]\+\|o[0-7]\+\|x[0-9a-fA-F]\+\|[\"\\'&\\abfnrtv]\|^[A-Z^_\[\\\]]\)"
61 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\)"
62 syn match hsSpecialCharError contained "\\&\|'''\+"
63 syn region hsString start=+"+ skip=+\\\\\|\\"+ end=+"+ contains=hsSpecialChar
64 syn match hsCharacter "[^a-zA-Z0-9_']'\([^\\]\|\\[^']\+\|\\'\)'"lc=1 contains=hsSpecialChar,hsSpecialCharError
65 syn match hsCharacter "^'\([^\\]\|\\[^']\+\|\\'\)'" contains=hsSpecialChar,hsSpecialCharError
66 syn match hsNumber "\<[0-9]\+\>\|\<0[xX][0-9a-fA-F]\+\>\|\<0[oO][0-7]\+\>"
67 syn match hsFloat "\<[0-9]\+\.[0-9]\+\([eE][-+]\=[0-9]\+\)\=\>"
69 " Keyword definitions. These must be patters instead of keywords
70 " because otherwise they would match as keywords at the start of a
71 " "literate" comment (see lhs.vim).
72 syn match hsModule "\<module\>"
73 syn match hsImport "\<import\>.*"he=s+6 contains=hsImportMod,hsLineComment,hsBlockComment
74 syn match hsImportMod contained "\<\(as\|qualified\|hiding\)\>"
75 syn match hsInfix "\<\(infix\|infixl\|infixr\)\>"
76 syn match hsStructure "\<\(class\|data\|deriving\|instance\|default\|where\)\>"
77 syn match hsTypedef "\<\(type\|newtype\)\>"
78 syn match hsStatement "\<\(do\|case\|of\|let\|in\)\>"
79 syn match hsConditional "\<\(if\|then\|else\)\>"
81 " Not real keywords, but close.
82 if exists("hs_highlight_boolean")
83 " Boolean constants from the standard prelude.
84 syn match hsBoolean "\<\(True\|False\)\>"
86 if exists("hs_highlight_types")
87 " Primitive types from the standard prelude and libraries.
88 syn match hsType "\<\(Int\|Integer\|Char\|Bool\|Float\|Double\|IO\|Void\|Addr\|Array\|String\)\>"
90 if exists("hs_highlight_more_types")
91 " Types from the standard prelude libraries.
92 syn match hsType "\<\(Maybe\|Either\|Ratio\|Complex\|Ordering\|IOError\|IOResult\|ExitCode\)\>"
93 syn match hsMaybe "\<Nothing\>"
94 syn match hsExitCode "\<\(ExitSuccess\)\>"
95 syn match hsOrdering "\<\(GT\|LT\|EQ\)\>"
97 if exists("hs_highlight_debug")
98 " Debugging functions from the standard prelude.
99 syn match hsDebug "\<\(undefined\|error\|trace\)\>"
104 syn match hsLineComment "---*\([^-!#$%&\*\+./<=>\?@\\^|~].*\)\?$"
105 syn region hsBlockComment start="{-" end="-}" contains=hsBlockComment
106 syn region hsPragma start="{-#" end="#-}"
108 " C Preprocessor directives. Shamelessly ripped from c.vim and trimmed
109 " First, see whether to flag directive-like lines or not
110 if (!exists("hs_allow_hash_operator"))
111 syn match cError display "^\s*\(%:\|#\).*$"
113 " Accept %: for # (C99)
114 syn region cPreCondit start="^\s*\(%:\|#\)\s*\(if\|ifdef\|ifndef\|elif\)\>" skip="\\$" end="$" end="//"me=s-1 contains=cComment,cCppString,cCommentError
115 syn match cPreCondit display "^\s*\(%:\|#\)\s*\(else\|endif\)\>"
116 syn region cCppOut start="^\s*\(%:\|#\)\s*if\s\+0\+\>" end=".\@=\|$" contains=cCppOut2
117 syn region cCppOut2 contained start="0" end="^\s*\(%:\|#\)\s*\(endif\>\|else\>\|elif\>\)" contains=cCppSkip
118 syn region cCppSkip contained start="^\s*\(%:\|#\)\s*\(if\>\|ifdef\>\|ifndef\>\)" skip="\\$" end="^\s*\(%:\|#\)\s*endif\>" contains=cCppSkip
119 syn region cIncluded display contained start=+"+ skip=+\\\\\|\\"+ end=+"+
120 syn match cIncluded display contained "<[^>]*>"
121 syn match cInclude display "^\s*\(%:\|#\)\s*include\>\s*["<]" contains=cIncluded
122 syn cluster cPreProcGroup contains=cPreCondit,cIncluded,cInclude,cDefine,cCppOut,cCppOut2,cCppSkip,cCommentStartError
123 syn region cDefine matchgroup=cPreCondit start="^\s*\(%:\|#\)\s*\(define\|undef\)\>" skip="\\$" end="$"
124 syn region cPreProc matchgroup=cPreCondit start="^\s*\(%:\|#\)\s*\(pragma\>\|line\>\|warning\>\|warn\>\|error\>\)" skip="\\$" end="$" keepend
126 syn region cComment matchgroup=cCommentStart start="/\*" end="\*/" contains=cCommentStartError,cSpaceError contained
127 syntax match cCommentError display "\*/" contained
128 syntax match cCommentStartError display "/\*"me=e-1 contained
129 syn region cCppString start=+L\="+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end='$' contains=cSpecial contained
131 " Define the default highlighting.
132 " For version 5.7 and earlier: only when not done already
133 " For version 5.8 and later: only when an item doesn't have highlighting yet
134 if version >= 508 || !exists("did_hs_syntax_inits")
136 let did_hs_syntax_inits = 1
137 command -nargs=+ HiLink hi link <args>
139 command -nargs=+ HiLink hi def link <args>
142 HiLink hsModule hsStructure
143 HiLink hsImport Include
144 HiLink hsImportMod hsImport
145 HiLink hsInfix PreProc
146 HiLink hsStructure Keyword
147 HiLink hsStatement Statement
148 HiLink hsConditional Conditional
149 HiLink hsSpecialChar SpecialChar
150 HiLink hsTypedef Keyword "Typedef
151 HiLink hsVarSym hsOperator
152 HiLink hsConSym hsOperator
153 HiLink hsOperator Operator
154 if exists("hs_highlight_delimiters")
155 " Some people find this highlighting distracting.
156 HiLink hsDelimiter Delimiter
158 HiLink hsSpecialCharError Error
159 HiLink hsString String
160 HiLink hsCharacter Character
161 HiLink hsNumber Number
163 HiLink hsConditional Conditional
164 HiLink hsLiterateComment hsComment
165 HiLink hsBlockComment hsComment
166 HiLink hsLineComment hsComment
167 HiLink hsComment Comment
168 HiLink hsPragma SpecialComment
169 HiLink hsBoolean Boolean
171 HiLink hsMaybe hsEnumConst
172 HiLink hsOrdering hsEnumConst
173 HiLink hsEnumConst Constant
177 HiLink hsTopDecl Identifier
179 HiLink cCppString hsString
180 HiLink cCommentStart hsComment
181 HiLink cCommentError hsError
182 HiLink cCommentStartError hsError
183 HiLink cInclude Include
184 HiLink cPreProc PreProc
186 HiLink cIncluded hsString
188 HiLink cPreCondit PreCondit
189 HiLink cComment Comment
190 HiLink cCppSkip cCppOut
191 HiLink cCppOut2 cCppOut
192 HiLink cCppOut Comment
197 let b:current_syntax = "haskell"
199 " Options for vi: ts=8 sw=2 sts=2 nowrap noexpandtab ft=vim