Skip to content

Commit 3e10bd0

Browse files
committed
Merge pull request #1346 from gracjan/pr-type-parens
Track parens ourselves in type highlight
2 parents f9dbbe5 + f9c8624 commit 3e10bd0

File tree

2 files changed

+34
-8
lines changed

2 files changed

+34
-8
lines changed

haskell-font-lock.el

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,8 @@ like ::, class, instance, data, newtype, type."
240240
(token nil)
241241
;; we are starting right after ::
242242
(last-token-was-operator t)
243-
(last-token-was-newline nil))
243+
(last-token-was-newline nil)
244+
(open-parens 0))
244245
(while cont
245246
(setq token (haskell-lexeme-looking-at-token 'newline))
246247

@@ -251,9 +252,26 @@ like ::, class, instance, data, newtype, type."
251252
(setq last-token-was-newline (not last-token-was-operator))
252253
(setq end (match-end 0))
253254
(goto-char (match-end 0)))
255+
((member (match-string-no-properties 0)
256+
'(")" "]" "}"))
257+
(setq open-parens (1- open-parens))
258+
(if (< open-parens 0)
259+
;; unmatched closing parenthesis closes type declaration
260+
(setq cont nil)
261+
(setq end (match-end 0))
262+
(goto-char end))
263+
(setq last-token-was-newline nil))
264+
((and (member (match-string-no-properties 0)
265+
'("," ";" "|"))
266+
(not (member (match-string-no-properties 0) ignore)))
267+
(if (equal 0 open-parens)
268+
(setq cont nil)
269+
(setq last-token-was-operator t)
270+
(setq end (match-end 0))
271+
(goto-char end))
272+
(setq last-token-was-newline nil))
254273
((and (or (member (match-string-no-properties 0)
255-
'("<-" "=" "<-" "" "," ";"
256-
")" "]" "}" "|"))
274+
'("<-" "=" ""))
257275
(member (match-string-no-properties 0) haskell-font-lock--reverved-ids))
258276
(not (member (match-string-no-properties 0) ignore)))
259277
(setq cont nil)
@@ -262,11 +280,9 @@ like ::, class, instance, data, newtype, type."
262280
'("(" "[" "{"))
263281
(if last-token-was-newline
264282
(setq cont nil)
265-
(goto-char (match-beginning 0))
266-
(condition-case err
267-
(forward-sexp)
268-
(scan-error (goto-char (nth 3 err))))
269-
(setq end (point))
283+
(setq open-parens (1+ open-parens))
284+
(setq end (match-end 0))
285+
(goto-char end)
270286
(setq last-token-was-newline nil)))
271287
((member token '(qsymid char string number template-haskell-quote template-haskell-quasi-quote))
272288
(setq last-token-was-operator (member (haskell-lexeme-classify-by-first-char (char-after (match-beginning 1)))

tests/haskell-font-lock-tests.el

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -878,6 +878,16 @@
878878
("Z" t haskell-type-face)
879879
("C" t haskell-constructor-face))))
880880

881+
(ert-deftest haskell-type-colors-31 ()
882+
(check-properties
883+
;; open parentheses do not keep type decl open because there might
884+
;; be an unclosed parenthesis stretching to the end of file and
885+
;; that is very costly to check
886+
'("x :: (OpenParen"
887+
" NotType)")
888+
'(("OpenParen" t haskell-type-face)
889+
("NotType" t haskell-constructor-face))))
890+
881891
(ert-deftest haskell-pattern ()
882892
"Fontify the \"pattern\" keyword in contexts related to pattern synonyms."
883893
:expected-result :failed

0 commit comments

Comments
 (0)