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