blob: 8afca048ccaab75d94b0aa5335297f7d90c16a80 [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001" Vim syntax file
2" Language: Haskell
3" Maintainer: Haskell Cafe mailinglist <haskell-cafe@haskell.org>
Bram Moolenaar5c736222010-01-06 20:54:52 +01004" Last Change: 2008 Dec 15
Bram Moolenaar071d4272004-06-13 20:20:40 +00005" Original Author: John Williams <jrw@pobox.com>
6"
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.
12"
13" Options-assign a value to these variables to turn the option on:
14"
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
24" operators
25"
26" 2004 Feb 19: Added C preprocessor directive handling, corrected eol comments
27" cleaned away literate haskell support (should be entirely in
28" lhaskell.vim)
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.
Bram Moolenaar5c736222010-01-06 20:54:52 +010033" 2008 Dec 15: Added comments as contained element in import statements
Bram Moolenaar071d4272004-06-13 20:20:40 +000034
35" Remove any old syntax stuff hanging around
36if version < 600
37 syn clear
38elseif exists("b:current_syntax")
39 finish
40endif
41
42" (Qualified) identifiers (no default highlighting)
43syn match ConId "\(\<[A-Z][a-zA-Z0-9_']*\.\)\=\<[A-Z][a-zA-Z0-9_']*\>"
44syn match VarId "\(\<[A-Z][a-zA-Z0-9_']*\.\)\=\<[a-z][a-zA-Z0-9_']*\>"
45
46" Infix operators--most punctuation characters and any (qualified) identifier
47" enclosed in `backquotes`. An operator starting with : is a constructor,
48" others are variables (e.g. functions).
49syn match hsVarSym "\(\<[A-Z][a-zA-Z0-9_']*\.\)\=[-!#$%&\*\+/<=>\?@\\^|~.][-!#$%&\*\+/<=>\?@\\^|~:.]*"
50syn match hsConSym "\(\<[A-Z][a-zA-Z0-9_']*\.\)\=:[-!#$%&\*\+./<=>\?@\\^|~:]*"
51syn match hsVarSym "`\(\<[A-Z][a-zA-Z0-9_']*\.\)\=[a-z][a-zA-Z0-9_']*`"
52syn match hsConSym "`\(\<[A-Z][a-zA-Z0-9_']*\.\)\=[A-Z][a-zA-Z0-9_']*`"
53
54" Reserved symbols--cannot be overloaded.
55syn match hsDelimiter "(\|)\|\[\|\]\|,\|;\|_\|{\|}"
56
57" Strings and constants
58syn match hsSpecialChar contained "\\\([0-9]\+\|o[0-7]\+\|x[0-9a-fA-F]\+\|[\"\\'&\\abfnrtv]\|^[A-Z^_\[\\\]]\)"
59syn 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\)"
60syn match hsSpecialCharError contained "\\&\|'''\+"
61syn region hsString start=+"+ skip=+\\\\\|\\"+ end=+"+ contains=hsSpecialChar
62syn match hsCharacter "[^a-zA-Z0-9_']'\([^\\]\|\\[^']\+\|\\'\)'"lc=1 contains=hsSpecialChar,hsSpecialCharError
63syn match hsCharacter "^'\([^\\]\|\\[^']\+\|\\'\)'" contains=hsSpecialChar,hsSpecialCharError
64syn match hsNumber "\<[0-9]\+\>\|\<0[xX][0-9a-fA-F]\+\>\|\<0[oO][0-7]\+\>"
65syn match hsFloat "\<[0-9]\+\.[0-9]\+\([eE][-+]\=[0-9]\+\)\=\>"
66
67" Keyword definitions. These must be patters instead of keywords
68" because otherwise they would match as keywords at the start of a
69" "literate" comment (see lhs.vim).
70syn match hsModule "\<module\>"
Bram Moolenaar5c736222010-01-06 20:54:52 +010071syn match hsImport "\<import\>.*"he=s+6 contains=hsImportMod,hsLineComment,hsBlockComment
Bram Moolenaar071d4272004-06-13 20:20:40 +000072syn match hsImportMod contained "\<\(as\|qualified\|hiding\)\>"
73syn match hsInfix "\<\(infix\|infixl\|infixr\)\>"
74syn match hsStructure "\<\(class\|data\|deriving\|instance\|default\|where\)\>"
75syn match hsTypedef "\<\(type\|newtype\)\>"
76syn match hsStatement "\<\(do\|case\|of\|let\|in\)\>"
77syn match hsConditional "\<\(if\|then\|else\)\>"
78
79" Not real keywords, but close.
80if exists("hs_highlight_boolean")
81 " Boolean constants from the standard prelude.
82 syn match hsBoolean "\<\(True\|False\)\>"
83endif
84if exists("hs_highlight_types")
85 " Primitive types from the standard prelude and libraries.
86 syn match hsType "\<\(Int\|Integer\|Char\|Bool\|Float\|Double\|IO\|Void\|Addr\|Array\|String\)\>"
87endif
88if exists("hs_highlight_more_types")
89 " Types from the standard prelude libraries.
90 syn match hsType "\<\(Maybe\|Either\|Ratio\|Complex\|Ordering\|IOError\|IOResult\|ExitCode\)\>"
91 syn match hsMaybe "\<Nothing\>"
92 syn match hsExitCode "\<\(ExitSuccess\)\>"
93 syn match hsOrdering "\<\(GT\|LT\|EQ\)\>"
94endif
95if exists("hs_highlight_debug")
96 " Debugging functions from the standard prelude.
97 syn match hsDebug "\<\(undefined\|error\|trace\)\>"
98endif
99
100
101" Comments
102syn match hsLineComment "---*\([^-!#$%&\*\+./<=>\?@\\^|~].*\)\?$"
103syn region hsBlockComment start="{-" end="-}" contains=hsBlockComment
104syn region hsPragma start="{-#" end="#-}"
105
106" C Preprocessor directives. Shamelessly ripped from c.vim and trimmed
107" First, see whether to flag directive-like lines or not
108if (!exists("hs_allow_hash_operator"))
109 syn match cError display "^\s*\(%:\|#\).*$"
110endif
111" Accept %: for # (C99)
112syn region cPreCondit start="^\s*\(%:\|#\)\s*\(if\|ifdef\|ifndef\|elif\)\>" skip="\\$" end="$" end="//"me=s-1 contains=cComment,cCppString,cCommentError
113syn match cPreCondit display "^\s*\(%:\|#\)\s*\(else\|endif\)\>"
114syn region cCppOut start="^\s*\(%:\|#\)\s*if\s\+0\+\>" end=".\@=\|$" contains=cCppOut2
115syn region cCppOut2 contained start="0" end="^\s*\(%:\|#\)\s*\(endif\>\|else\>\|elif\>\)" contains=cCppSkip
116syn region cCppSkip contained start="^\s*\(%:\|#\)\s*\(if\>\|ifdef\>\|ifndef\>\)" skip="\\$" end="^\s*\(%:\|#\)\s*endif\>" contains=cCppSkip
117syn region cIncluded display contained start=+"+ skip=+\\\\\|\\"+ end=+"+
118syn match cIncluded display contained "<[^>]*>"
119syn match cInclude display "^\s*\(%:\|#\)\s*include\>\s*["<]" contains=cIncluded
120syn cluster cPreProcGroup contains=cPreCondit,cIncluded,cInclude,cDefine,cCppOut,cCppOut2,cCppSkip,cCommentStartError
121syn region cDefine matchgroup=cPreCondit start="^\s*\(%:\|#\)\s*\(define\|undef\)\>" skip="\\$" end="$"
122syn region cPreProc matchgroup=cPreCondit start="^\s*\(%:\|#\)\s*\(pragma\>\|line\>\|warning\>\|warn\>\|error\>\)" skip="\\$" end="$" keepend
123
124syn region cComment matchgroup=cCommentStart start="/\*" end="\*/" contains=cCommentStartError,cSpaceError contained
125syntax match cCommentError display "\*/" contained
126syntax match cCommentStartError display "/\*"me=e-1 contained
127syn region cCppString start=+L\="+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end='$' contains=cSpecial contained
128
129" Define the default highlighting.
130" For version 5.7 and earlier: only when not done already
131" For version 5.8 and later: only when an item doesn't have highlighting yet
132if version >= 508 || !exists("did_hs_syntax_inits")
133 if version < 508
134 let did_hs_syntax_inits = 1
135 command -nargs=+ HiLink hi link <args>
136 else
137 command -nargs=+ HiLink hi def link <args>
138 endif
139
140 HiLink hsModule hsStructure
141 HiLink hsImport Include
142 HiLink hsImportMod hsImport
143 HiLink hsInfix PreProc
144 HiLink hsStructure Structure
145 HiLink hsStatement Statement
146 HiLink hsConditional Conditional
147 HiLink hsSpecialChar SpecialChar
148 HiLink hsTypedef Typedef
149 HiLink hsVarSym hsOperator
150 HiLink hsConSym hsOperator
151 HiLink hsOperator Operator
152 if exists("hs_highlight_delimiters")
153 " Some people find this highlighting distracting.
154 HiLink hsDelimiter Delimiter
155 endif
156 HiLink hsSpecialCharError Error
157 HiLink hsString String
158 HiLink hsCharacter Character
159 HiLink hsNumber Number
160 HiLink hsFloat Float
161 HiLink hsConditional Conditional
162 HiLink hsLiterateComment hsComment
163 HiLink hsBlockComment hsComment
164 HiLink hsLineComment hsComment
165 HiLink hsComment Comment
166 HiLink hsPragma SpecialComment
167 HiLink hsBoolean Boolean
168 HiLink hsType Type
169 HiLink hsMaybe hsEnumConst
170 HiLink hsOrdering hsEnumConst
171 HiLink hsEnumConst Constant
172 HiLink hsDebug Debug
173
174 HiLink cCppString hsString
175 HiLink cCommentStart hsComment
176 HiLink cCommentError hsError
177 HiLink cCommentStartError hsError
178 HiLink cInclude Include
179 HiLink cPreProc PreProc
180 HiLink cDefine Macro
181 HiLink cIncluded hsString
182 HiLink cError Error
183 HiLink cPreCondit PreCondit
184 HiLink cComment Comment
185 HiLink cCppSkip cCppOut
186 HiLink cCppOut2 cCppOut
187 HiLink cCppOut Comment
188
189 delcommand HiLink
190endif
191
192let b:current_syntax = "haskell"
193
194" Options for vi: ts=8 sw=2 sts=2 nowrap noexpandtab ft=vim