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