blob: b48b278084698fe890a3cb3d6b59a17ca2f78868 [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 Moolenaar4f4d51a2020-10-11 13:57:40 +02004" Last Change: 2020 Oct 4 by Marcin Szamotulski <profunctor@pm.me>
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)
Bram Moolenaar4f4d51a2020-10-11 13:57:40 +020041syn match ConId "\(\<[A-Z][a-zA-Z0-9_']*\.\)*\<[A-Z][a-zA-Z0-9_']*\>" contains=@NoSpell
42syn match VarId "\(\<[A-Z][a-zA-Z0-9_']*\.\)*\<[a-z][a-zA-Z0-9_']*\>" contains=@NoSpell
Bram Moolenaar071d4272004-06-13 20:20:40 +000043
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
Bram Moolenaar4f4d51a2020-10-11 13:57:40 +020052" (Non-qualified) identifiers which start with # are labels
53syn match hsLabel "#[a-z][a-zA-Z0-9_']*\>"
54
Bram Moolenaar071d4272004-06-13 20:20:40 +000055" Reserved symbols--cannot be overloaded.
Bram Moolenaar4f4d51a2020-10-11 13:57:40 +020056syn match hsDelimiter "(\|)\|\[\|\]\|,\|;\|{\|}"
Bram Moolenaar071d4272004-06-13 20:20:40 +000057
58" Strings and constants
59syn match hsSpecialChar contained "\\\([0-9]\+\|o[0-7]\+\|x[0-9a-fA-F]\+\|[\"\\'&\\abfnrtv]\|^[A-Z^_\[\\\]]\)"
60syn 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\)"
61syn match hsSpecialCharError contained "\\&\|'''\+"
Bram Moolenaar25a6e8a2018-03-30 12:27:32 +020062syn region hsString start=+"+ skip=+\\\\\|\\"+ end=+"+ contains=hsSpecialChar,@NoSpell
Bram Moolenaar071d4272004-06-13 20:20:40 +000063syn match hsCharacter "[^a-zA-Z0-9_']'\([^\\]\|\\[^']\+\|\\'\)'"lc=1 contains=hsSpecialChar,hsSpecialCharError
64syn match hsCharacter "^'\([^\\]\|\\[^']\+\|\\'\)'" contains=hsSpecialChar,hsSpecialCharError
Bram Moolenaarf0b03c42017-12-17 17:17:07 +010065syn match hsNumber "\v<[0-9]%(_*[0-9])*>|<0[xX]_*[0-9a-fA-F]%(_*[0-9a-fA-F])*>|<0[oO]_*%(_*[0-7])*>|<0[bB]_*[01]%(_*[01])*>"
66syn match hsFloat "\v<[0-9]%(_*[0-9])*\.[0-9]%(_*[0-9])*%(_*[eE][-+]?[0-9]%(_*[0-9])*)?>|<[0-9]%(_*[0-9])*_*[eE][-+]?[0-9]%(_*[0-9])*>|<0[xX]_*[0-9a-fA-F]%(_*[0-9a-fA-F])*\.[0-9a-fA-F]%(_*[0-9a-fA-F])*%(_*[pP][-+]?[0-9]%(_*[0-9])*)?>|<0[xX]_*[0-9a-fA-F]%(_*[0-9a-fA-F])*_*[pP][-+]?[0-9]%(_*[0-9])*>"
Bram Moolenaar071d4272004-06-13 20:20:40 +000067
Bram Moolenaar4f4d51a2020-10-11 13:57:40 +020068" Keyword definitions.
69syn keyword hsModule module
70syn match hsImportGroup "\<import\>.*" contains=hsImport,hsImportModuleName,hsImportMod,hsLineComment,hsBlockComment,hsImportList,@NoSpell nextgroup=hsImport
71syn keyword hsImport import contained nextgroup=hsImportModuleName
72syn match hsImportModuleName '\<[A-Z][A-Za-z.]*' contained
73syn region hsImportList start='(' skip='([^)]\{-})' end=')' keepend contained contains=ConId,VarId,hsDelimiter,hsBlockComment,hsTypedef,@NoSpell
74
75syn keyword hsImportMod contained as qualified hiding
76syn keyword hsInfix infix infixl infixr
77syn keyword hsStructure class data deriving instance default where
78syn keyword hsTypedef type
79syn keyword hsNewtypedef newtype
80syn keyword hsTypeFam family
81syn keyword hsStatement mdo do case of let in
82syn keyword hsConditional if then else
Bram Moolenaar071d4272004-06-13 20:20:40 +000083
84" Not real keywords, but close.
85if exists("hs_highlight_boolean")
86 " Boolean constants from the standard prelude.
Bram Moolenaar4f4d51a2020-10-11 13:57:40 +020087 syn keyword hsBoolean True False
Bram Moolenaar071d4272004-06-13 20:20:40 +000088endif
89if exists("hs_highlight_types")
90 " Primitive types from the standard prelude and libraries.
Bram Moolenaar4f4d51a2020-10-11 13:57:40 +020091 syn keyword hsType Int Integer Char Bool Float Double IO Void Addr Array String
Bram Moolenaar071d4272004-06-13 20:20:40 +000092endif
93if exists("hs_highlight_more_types")
94 " Types from the standard prelude libraries.
Bram Moolenaar4f4d51a2020-10-11 13:57:40 +020095 syn keyword hsType Maybe Either Ratio Complex Ordering IOError IOResult ExitCode
96 syn keyword hsMaybe Nothing
97 syn keyword hsExitCode ExitSuccess
98 syn keyword hsOrdering GT LT EQ
Bram Moolenaar071d4272004-06-13 20:20:40 +000099endif
100if exists("hs_highlight_debug")
101 " Debugging functions from the standard prelude.
Bram Moolenaar4f4d51a2020-10-11 13:57:40 +0200102 syn keyword hsDebug undefined error trace
Bram Moolenaar071d4272004-06-13 20:20:40 +0000103endif
104
105
106" Comments
Bram Moolenaar25a6e8a2018-03-30 12:27:32 +0200107syn match hsLineComment "---*\([^-!#$%&\*\+./<=>\?@\\^|~].*\)\?$" contains=@Spell
108syn region hsBlockComment start="{-" end="-}" contains=hsBlockComment,@Spell
Bram Moolenaar071d4272004-06-13 20:20:40 +0000109syn region hsPragma start="{-#" end="#-}"
110
Bruno-366817db402023-08-18 00:04:54 +0200111syn keyword hsTodo contained FIXME TODO XXX NOTE
112
Bram Moolenaar071d4272004-06-13 20:20:40 +0000113" C Preprocessor directives. Shamelessly ripped from c.vim and trimmed
114" First, see whether to flag directive-like lines or not
115if (!exists("hs_allow_hash_operator"))
116 syn match cError display "^\s*\(%:\|#\).*$"
117endif
118" Accept %: for # (C99)
119syn region cPreCondit start="^\s*\(%:\|#\)\s*\(if\|ifdef\|ifndef\|elif\)\>" skip="\\$" end="$" end="//"me=s-1 contains=cComment,cCppString,cCommentError
120syn match cPreCondit display "^\s*\(%:\|#\)\s*\(else\|endif\)\>"
121syn region cCppOut start="^\s*\(%:\|#\)\s*if\s\+0\+\>" end=".\@=\|$" contains=cCppOut2
122syn region cCppOut2 contained start="0" end="^\s*\(%:\|#\)\s*\(endif\>\|else\>\|elif\>\)" contains=cCppSkip
123syn region cCppSkip contained start="^\s*\(%:\|#\)\s*\(if\>\|ifdef\>\|ifndef\>\)" skip="\\$" end="^\s*\(%:\|#\)\s*endif\>" contains=cCppSkip
124syn region cIncluded display contained start=+"+ skip=+\\\\\|\\"+ end=+"+
125syn match cIncluded display contained "<[^>]*>"
126syn match cInclude display "^\s*\(%:\|#\)\s*include\>\s*["<]" contains=cIncluded
127syn cluster cPreProcGroup contains=cPreCondit,cIncluded,cInclude,cDefine,cCppOut,cCppOut2,cCppSkip,cCommentStartError
128syn region cDefine matchgroup=cPreCondit start="^\s*\(%:\|#\)\s*\(define\|undef\)\>" skip="\\$" end="$"
129syn region cPreProc matchgroup=cPreCondit start="^\s*\(%:\|#\)\s*\(pragma\>\|line\>\|warning\>\|warn\>\|error\>\)" skip="\\$" end="$" keepend
130
131syn region cComment matchgroup=cCommentStart start="/\*" end="\*/" contains=cCommentStartError,cSpaceError contained
132syntax match cCommentError display "\*/" contained
133syntax match cCommentStartError display "/\*"me=e-1 contained
134syn region cCppString start=+L\="+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end='$' contains=cSpecial contained
135
136" Define the default highlighting.
Bram Moolenaar89bcfda2016-08-30 23:26:57 +0200137" Only when an item doesn't have highlighting yet
Bram Moolenaar071d4272004-06-13 20:20:40 +0000138
Bram Moolenaarf37506f2016-08-31 22:22:10 +0200139hi def link hsModule hsStructure
140hi def link hsImport Include
141hi def link hsImportMod hsImport
142hi def link hsInfix PreProc
143hi def link hsStructure Structure
144hi def link hsStatement Statement
Bram Moolenaar4f4d51a2020-10-11 13:57:40 +0200145hi def link hsConditional Conditional
146hi def link hsSpecialChar SpecialChar
Bram Moolenaarf37506f2016-08-31 22:22:10 +0200147hi def link hsTypedef Typedef
Bram Moolenaar4f4d51a2020-10-11 13:57:40 +0200148hi def link hsNewtypedef Typedef
Bram Moolenaarf37506f2016-08-31 22:22:10 +0200149hi def link hsVarSym hsOperator
150hi def link hsConSym hsOperator
151hi def link hsOperator Operator
Bram Moolenaar4f4d51a2020-10-11 13:57:40 +0200152hi def link hsTypeFam Structure
Bram Moolenaar89bcfda2016-08-30 23:26:57 +0200153if exists("hs_highlight_delimiters")
154" Some people find this highlighting distracting.
Bram Moolenaarf37506f2016-08-31 22:22:10 +0200155hi def link hsDelimiter Delimiter
Bram Moolenaar071d4272004-06-13 20:20:40 +0000156endif
Bram Moolenaarf37506f2016-08-31 22:22:10 +0200157hi def link hsSpecialCharError Error
158hi def link hsString String
159hi def link hsCharacter Character
160hi def link hsNumber Number
161hi def link hsFloat Float
162hi def link hsConditional Conditional
163hi def link hsLiterateComment hsComment
164hi def link hsBlockComment hsComment
165hi def link hsLineComment hsComment
166hi def link hsComment Comment
167hi def link hsPragma SpecialComment
168hi def link hsBoolean Boolean
169hi def link hsType Type
170hi def link hsMaybe hsEnumConst
171hi def link hsOrdering hsEnumConst
172hi def link hsEnumConst Constant
173hi def link hsDebug Debug
Bram Moolenaar4f4d51a2020-10-11 13:57:40 +0200174hi def link hsLabel Special
Bram Moolenaar89bcfda2016-08-30 23:26:57 +0200175
Bram Moolenaar4f4d51a2020-10-11 13:57:40 +0200176hi def link cCppString hsString
177hi def link cCommentStart hsComment
178hi def link cCommentError hsError
179hi def link cCommentStartError hsError
180hi def link cInclude Include
181hi def link cPreProc PreProc
182hi def link cDefine Macro
183hi def link cIncluded hsString
184hi def link cError Error
185hi def link cPreCondit PreCondit
186hi def link cComment Comment
187hi def link cCppSkip cCppOut
188hi def link cCppOut2 cCppOut
189hi def link cCppOut Comment
Bram Moolenaar071d4272004-06-13 20:20:40 +0000190
191let b:current_syntax = "haskell"
192
193" Options for vi: ts=8 sw=2 sts=2 nowrap noexpandtab ft=vim