Skip to content

Commit 514f077

Browse files
committed
Fixed broken character literal highlighting (neovimhaskell#132)
(See neovimhaskell#132) When a character literal contains a "region" start pattern ('(','[','{','"'), everything after the start pattern is interpreted as a contained region, and consequently breaks syntax highlighting. After further investigation, the regex used to match character literal is actually incorrect according to the Haskell 2010 language specification (https://www.haskell.org/onlinereport/haskell2010/haskellch2.html#x7-200002.6), which means most valid character literals aren't highlighted at all, and the \u<code> pattern while not being a legal character in Haskell, is correctly highlighted. This commit tries to remedy the above issues.
1 parent f35d022 commit 514f077

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

syntax/haskell.vim

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,30 @@ syn match haskellBacktick "`[A-Za-z_][A-Za-z0-9_\.']*#\?`"
9696
syn region haskellString start=+"+ skip=+\\\\\|\\"+ end=+"+
9797
\ contains=@Spell
9898
syn match haskellIdentifier "[_a-z][a-zA-Z0-9_']*" contained
99-
syn match haskellChar "\<'[^'\\]'\|'\\.'\|'\\u[0-9a-fA-F]\{4}'\>"
99+
100+
" Haskell character literal match
101+
" https://www.haskell.org/onlinereport/haskell2010/haskellch2.html#x7-200002.6
102+
" http://book.realworldhaskell.org/read/characters-strings-and-escaping-rules.html
103+
syn match haskellCharPrintable "[:print:]" contained
104+
syn match haskellCharSingleCharEsc "\\[0abfnrtv"&'\\]" contained
105+
syn match haskellCharAsciiControlCodeEsc "\\\(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\)" contained
106+
syn match haskellCharAsciiControlCharEsc "\\\^[@A-Z\[\]\\\^_]" contained
107+
syn match haskellCharDeciEsc "\\[0-9]\{1,7}" contained
108+
syn match haskellCharOctalEsc "\\o[0-7]\{1,7}" contained
109+
syn match haskellCharHexEsc "\\x[0-9a-fa-f]\{1,6}" contained
110+
111+
syn cluster haskellCharGroup
112+
\ contains=
113+
\ haskellCharPrintable,
114+
\ haskellCharSingleCharEsc,
115+
\ haskellCharAsciiControlCodeEsc,
116+
\ haskellCharAsciiControlCharEsc,
117+
\ haskellCharDeciEsc,
118+
\ haskellCharOctalEsc,
119+
\ haskellCharHexEsc
120+
syn region haskellChar start=+'+ end=+'+
121+
\ contains=@haskellCharGroup
122+
100123
syn match haskellType "\<[A-Z][a-zA-Z0-9_']*\>"
101124
syn region haskellBlockComment start="{-" end="-}"
102125
\ contains=
@@ -156,6 +179,13 @@ highlight def link haskellPragma SpecialComment
156179
highlight def link haskellLiquid SpecialComment
157180
highlight def link haskellString String
158181
highlight def link haskellChar String
182+
highlight def link haskellCharPrintable String
183+
highlight def link haskellCharSingleCharEsc SpecialChar
184+
highlight def link haskellCharAsciiControlCodeEsc SpecialChar
185+
highlight def link haskellCharAsciiControlCharEsc SpecialChar
186+
highlight def link haskellCharDeciEsc SpecialChar
187+
highlight def link haskellCharOctalEsc SpecialChar
188+
highlight def link haskellCharHexEsc SpecialChar
159189
highlight def link haskellBacktick Operator
160190
highlight def link haskellQuasiQuoted String
161191
highlight def link haskellTodo Todo

0 commit comments

Comments
 (0)