haskell.vim

orzo 2018-03-12 01:50:44.487948 UTC

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