Skip to content

Commit 1962346

Browse files
authored
Merge pull request #1413 from gracjan/pr-pattern-keyword
Support pattern as keyword
2 parents 3bab7f1 + 3655056 commit 1962346

File tree

2 files changed

+29
-33
lines changed

2 files changed

+29
-33
lines changed

haskell-font-lock.el

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,19 @@ be disabled at that position."
8686
:type '(alist string string)
8787
:group 'haskell-appearance)
8888

89+
(defcustom haskell-font-lock-keywords
90+
;; `as', `hiding', and `qualified' are part of the import
91+
;; spec syntax, but they are not reserved.
92+
;; `_' can go in here since it has temporary word syntax.
93+
'("case" "class" "data" "default" "deriving" "do"
94+
"else" "if" "import" "in" "infix" "infixl"
95+
"infixr" "instance" "let" "module" "mdo" "newtype" "of"
96+
"rec" "pattern" "proc" "then" "type" "where" "_")
97+
"Identifiers treated as reserved keywords in Haskell."
98+
:group 'haskell-appearance
99+
:type '(repeat string))
100+
101+
89102
(defun haskell-font-lock-dot-is-not-composition (start)
90103
"Return non-nil if the \".\" at START is not a composition operator.
91104
This is the case if the \".\" is part of a \"forall <tvar> . <type>\"."
@@ -229,16 +242,6 @@ Regexp match data 0 points to the chars."
229242
;; no face. So force evaluation by using `keep'.
230243
keep)))))
231244

232-
(defconst haskell-font-lock--reverved-ids
233-
;; `as', `hiding', and `qualified' are part of the import
234-
;; spec syntax, but they are not reserved.
235-
;; `_' can go in here since it has temporary word syntax.
236-
'("case" "class" "data" "default" "deriving" "do"
237-
"else" "if" "import" "in" "infix" "infixl"
238-
"infixr" "instance" "let" "module" "mdo" "newtype" "of"
239-
"rec" "proc" "then" "type" "where" "_")
240-
"Identifiers treated as reserved keywords in Haskell.")
241-
242245
(defun haskell-font-lock--forward-type (&optional ignore)
243246
"Find where does this type declaration end.
244247
@@ -283,7 +286,7 @@ like ::, class, instance, data, newtype, type."
283286
(setq last-token-was-newline nil))
284287
((and (or (member (match-string-no-properties 0)
285288
'("<-" "=" ""))
286-
(member (match-string-no-properties 0) haskell-font-lock--reverved-ids))
289+
(member (match-string-no-properties 0) haskell-font-lock-keywords))
287290
(not (member (match-string-no-properties 0) ignore)))
288291
(setq cont nil)
289292
(setq last-token-was-newline nil))
@@ -318,7 +321,7 @@ like ::, class, instance, data, newtype, type."
318321
"Private function used to select either type or constructor face
319322
on an uppercase identifier."
320323
(cl-case (haskell-lexeme-classify-by-first-char (char-after (match-beginning 1)))
321-
(varid (when (member (match-string 0) haskell-font-lock--reverved-ids)
324+
(varid (when (member (match-string 0) haskell-font-lock-keywords)
322325
;; Note: keywords parse as keywords only when not qualified.
323326
;; GHC parses Control.let as a single but illegal lexeme.
324327
(when (member (match-string 0) '("class" "instance" "type" "data" "newtype"))
@@ -440,11 +443,11 @@ on an uppercase identifier."
440443

441444
;; Toplevel Declarations.
442445
;; Place them *before* generic id-and-op highlighting.
443-
(,topdecl-var (1 (unless (member (match-string 1) haskell-font-lock--reverved-ids)
446+
(,topdecl-var (1 (unless (member (match-string 1) haskell-font-lock-keywords)
444447
'haskell-definition-face)))
445-
(,topdecl-var2 (2 (unless (member (match-string 2) haskell-font-lock--reverved-ids)
448+
(,topdecl-var2 (2 (unless (member (match-string 2) haskell-font-lock-keywords)
446449
'haskell-definition-face)))
447-
(,topdecl-bangpat (1 (unless (member (match-string 1) haskell-font-lock--reverved-ids)
450+
(,topdecl-bangpat (1 (unless (member (match-string 1) haskell-font-lock-keywords)
448451
'haskell-definition-face)))
449452
(,topdecl-sym (2 (unless (member (match-string 2) '("\\" "=" "->" "" "<-" "" "::" "" "," ";" "`"))
450453
'haskell-definition-face)))

tests/haskell-font-lock-tests.el

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -975,9 +975,8 @@
975975
("Cons2" t haskell-constructor-face)
976976
("Cons3" t haskell-constructor-face))))
977977

978-
(ert-deftest haskell-pattern ()
978+
(ert-deftest haskell-pattern-1 ()
979979
"Fontify the \"pattern\" keyword in contexts related to pattern synonyms."
980-
:expected-result :failed
981980
(check-properties
982981
'("pattern A = B"
983982
"pattern A <- B"
@@ -1006,27 +1005,21 @@
10061005
("pattern" t haskell-keyword-face)
10071006
("pattern" t haskell-keyword-face))))
10081007

1009-
(ert-deftest haskell-no-pattern-1 ()
1010-
"Don't fontify \"pattern\" in contexts unrelated to pattern synonyms."
1011-
;; This already works properly
1012-
;;:expected-result :failed
1008+
(ert-deftest haskell-pattern-2 ()
10131009
(check-properties
10141010
'("pattern :: Int"
10151011
"pattern = 3")
1016-
'(("pattern" t haskell-definition-face)
1017-
("pattern" t haskell-definition-face))))
1012+
'(("pattern" t haskell-keyword-face)
1013+
("pattern" t haskell-keyword-face))))
10181014

1019-
(ert-deftest haskell-no-pattern-2 ()
1020-
"Don't fontify \"pattern\" in contexts unrelated to pattern synonyms."
1021-
;; This already works properly
1022-
;;:expected-result :failed
1015+
(ert-deftest haskell-pattern-3 ()
10231016
(check-properties
10241017
'("foo :: (a -> pattern) -> a -> pattern"
10251018
"foo pattern x = pattern x"
10261019
"bar = pattern where pattern = 5")
1027-
'(("pattern" t nil)
1028-
("pattern" t nil)
1029-
("pattern" t nil)
1030-
("pattern" t nil)
1031-
("pattern" t nil)
1032-
("pattern" t nil))))
1020+
'(("pattern" t haskell-keyword-face)
1021+
("pattern" t haskell-keyword-face)
1022+
("pattern" t haskell-keyword-face)
1023+
("pattern" t haskell-keyword-face)
1024+
("pattern" t haskell-keyword-face)
1025+
("pattern" t haskell-keyword-face))))

0 commit comments

Comments
 (0)