From 25764a629a6aa36371d5b909ecf44328e4cfab60 Mon Sep 17 00:00:00 2001 From: Gracjan Polak Date: Thu, 12 May 2016 10:55:32 +0200 Subject: [PATCH] Add LiquidHaskell annotation highlight --- haskell-font-lock.el | 19 +++++++++++++++++-- tests/haskell-font-lock-tests.el | 9 ++++++++- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/haskell-font-lock.el b/haskell-font-lock.el index e5eb0f0f4..a0d837427 100644 --- a/haskell-font-lock.el +++ b/haskell-font-lock.el @@ -155,7 +155,13 @@ font faces assigned as if respective mode was enabled." ;;;###autoload (defface haskell-pragma-face '((t :inherit font-lock-preprocessor-face)) - "Face used to highlight Haskell pragmas." + "Face used to highlight Haskell pragmas ({-# ... #-})." + :group 'haskell-appearance) + +;;;###autoload +(defface haskell-liquid-haskell-annotation-face + '((t :inherit haskell-pragma-face)) + "Face used to highlight LiquidHaskell annotations ({-@ ... @-})." :group 'haskell-appearance) ;;;###autoload @@ -512,7 +518,7 @@ like ::, class, instance, data, newtype, type." (equal (string-to-syntax "<") (syntax-after (point)))) 'haskell-literate-comment-face) ;; Detect pragmas. A pragma is enclosed in special comment - ;; delimeters {-# .. #-}. + ;; delimiters {-# .. #-}. ((save-excursion (goto-char (nth 8 state)) (and (looking-at-p "{-#") @@ -520,6 +526,15 @@ like ::, class, instance, data, newtype, type." (goto-char (- (point) 3)) (looking-at-p "#-}"))) 'haskell-pragma-face) + ;; Detect Liquid Haskell annotations enclosed in special comment + ;; delimiters {-@ .. @-}. + ((save-excursion + (goto-char (nth 8 state)) + (and (looking-at-p "{-@") + (forward-comment 1) + (goto-char (- (point) 3)) + (looking-at-p "@-}"))) + 'haskell-liquid-haskell-annotation-face) ;; Haddock comment start with either "-- [|^*$]" or "{- ?[|^*$]" ;; (note space optional for nested comments and mandatory for ;; double dash comments). diff --git a/tests/haskell-font-lock-tests.el b/tests/haskell-font-lock-tests.el index cbc9b8f09..398425923 100644 --- a/tests/haskell-font-lock-tests.el +++ b/tests/haskell-font-lock-tests.el @@ -155,6 +155,9 @@ "{-# pragma1 #-}" "{-# non_pragma2 -}" "{- non_pragma3 #-}" + "{-@ liquid_haskell @-}" + "{-@ non_liquid_haskell_2 -}" + "{- non_liquid_haskell_3 @-}" ) '(("Cons0" "w" haskell-constructor-face) ("Comm1" "w" font-lock-comment-face) @@ -168,7 +171,11 @@ ("pragma1" "w" haskell-pragma-face) ("non_pragma2" "w" font-lock-comment-face) - ("non_pragma3" "w" font-lock-comment-face)))) + ("non_pragma3" "w" font-lock-comment-face) + ("liquid_haskell" "w" haskell-liquid-haskell-annotation-face) + ("non_liquid_haskell_2" "w" font-lock-comment-face) + + ("non_liquid_haskell_3" "w" font-lock-comment-face)))) (ert-deftest haskell-syntactic-string-vs-comment-escape ()