From 0e046128c94c37d433c4cc0fd3552326b43381aa Mon Sep 17 00:00:00 2001 From: Sergey Vinokurov Date: Tue, 15 Mar 2016 09:51:39 +0200 Subject: [PATCH 1/2] add haskell- prefix to all c2hs-mode symbols --- haskell-c2hs.el | 32 +++--- tests/haskell-c2hs-tests.el | 222 ++++++++++++++++++------------------ 2 files changed, 127 insertions(+), 127 deletions(-) diff --git a/haskell-c2hs.el b/haskell-c2hs.el index ef9d651ea..7bc6a7753 100644 --- a/haskell-c2hs.el +++ b/haskell-c2hs.el @@ -22,8 +22,8 @@ ;; This mode is mostly intended for highlighting {#...#} hooks. ;; ;; Quick setup: -;; (autoload 'c2hs-mode "c2hs-mode" nil t) -;; (add-to-list 'auto-mode-alist '("\\.chs\\'" . c2hs-mode)) +;; (autoload 'haskell-c2hs-mode "haskell-c2hs-mode" nil t) +;; (add-to-list 'auto-mode-alist '("\\.chs\\'" . haskell-c2hs-mode)) ;; (require 'haskell-mode) @@ -31,19 +31,19 @@ (require 'haskell-utils) ;;;###autoload -(add-to-list 'auto-mode-alist '("\\.chs\\'" . c2hs-mode)) +(add-to-list 'auto-mode-alist '("\\.chs\\'" . haskell-c2hs-mode)) -(defface c2hs-hook-pair-face +(defface haskell-c2hs-hook-pair-face '((t (:inherit 'font-lock-preprocessor-face))) "Face for highlighting {#...#} pairs." :group 'haskell) -(defface c2hs-hook-name-face +(defface haskell-c2hs-hook-name-face '((t (:inherit 'font-lock-keyword-face))) "Face for highlighting c2hs hook names." :group 'haskell) -(defvar c2hs-font-lock-keywords +(defvar haskell-c2hs-font-lock-keywords `((,(haskell--rx-let ((ws (any ?\s ?\t ?\n ?\r)) (anychar (or (not (any ?#)) (seq "#" @@ -176,25 +176,25 @@ (* anychar) (group-n 9 "#}")) ;; Override highlighting for pairs in order to always distinguish them. - (1 'c2hs-hook-pair-face t) - (2 'c2hs-hook-name-face) + (1 'haskell-c2hs-hook-pair-face t) + (2 'haskell-c2hs-hook-name-face) ;; Make matches lax, i.e. do not signal error if nothing ;; matched. - (3 'c2hs-hook-name-face nil t) - (4 'c2hs-hook-name-face nil t) - (5 'c2hs-hook-name-face nil t) - (6 'c2hs-hook-name-face nil t) - (7 'c2hs-hook-name-face nil t) + (3 'haskell-c2hs-hook-name-face nil t) + (4 'haskell-c2hs-hook-name-face nil t) + (5 'haskell-c2hs-hook-name-face nil t) + (6 'haskell-c2hs-hook-name-face nil t) + (7 'haskell-c2hs-hook-name-face nil t) (8 'font-lock-negation-char-face nil t) ;; Override highlighting for pairs in order to always distinguish them. - (9 'c2hs-hook-pair-face t)) + (9 'haskell-c2hs-hook-pair-face t)) ,@(haskell-font-lock-keywords))) ;;;###autoload -(define-derived-mode c2hs-mode haskell-mode "C2HS" +(define-derived-mode haskell-c2hs-mode haskell-mode "C2HS" "Mode for editing *.chs files of the c2hs haskell tool." (setq-local font-lock-defaults - (cons 'c2hs-font-lock-keywords + (cons 'haskell-c2hs-font-lock-keywords (cdr font-lock-defaults)))) diff --git a/tests/haskell-c2hs-tests.el b/tests/haskell-c2hs-tests.el index 78e604e6d..90f280e8e 100644 --- a/tests/haskell-c2hs-tests.el +++ b/tests/haskell-c2hs-tests.el @@ -8,51 +8,51 @@ "C2HS import hook" (check-properties '("{# import Foo #}") - '(("{#" t c2hs-hook-pair-face) - ("import" "w" c2hs-hook-name-face) - ("#}" t c2hs-hook-pair-face)) - 'c2hs-mode)) + '(("{#" t haskell-c2hs-hook-pair-face) + ("import" "w" haskell-c2hs-hook-name-face) + ("#}" t haskell-c2hs-hook-pair-face)) + 'haskell-c2hs-mode)) (ert-deftest haskell-c2hs-qualified-import-hook () "C2HS qualified import hook" (check-properties '("{#import qualified Foo#}") - '(("{#" t c2hs-hook-pair-face) - ("import" "w" c2hs-hook-name-face) - ("qualified" "w" c2hs-hook-name-face) - ("#}" t c2hs-hook-pair-face)) - 'c2hs-mode)) + '(("{#" t haskell-c2hs-hook-pair-face) + ("import" "w" haskell-c2hs-hook-name-face) + ("qualified" "w" haskell-c2hs-hook-name-face) + ("#}" t haskell-c2hs-hook-pair-face)) + 'haskell-c2hs-mode)) (ert-deftest haskell-c2hs-full-context-hook () "C2HS full context hook" (check-properties '("{# context lib = \"libgtk.so\" prefix = \"gtk\" add prefix = \"CGtk\" #}") - '(("{#" t c2hs-hook-pair-face) - ("context" "w" c2hs-hook-name-face) - ("lib" "w" c2hs-hook-name-face) - ("prefix" "w" c2hs-hook-name-face) - ("add" "w" c2hs-hook-name-face) - ("prefix" "w" c2hs-hook-name-face) - ("#}" t c2hs-hook-pair-face)) - 'c2hs-mode)) + '(("{#" t haskell-c2hs-hook-pair-face) + ("context" "w" haskell-c2hs-hook-name-face) + ("lib" "w" haskell-c2hs-hook-name-face) + ("prefix" "w" haskell-c2hs-hook-name-face) + ("add" "w" haskell-c2hs-hook-name-face) + ("prefix" "w" haskell-c2hs-hook-name-face) + ("#}" t haskell-c2hs-hook-pair-face)) + 'haskell-c2hs-mode)) (ert-deftest haskell-c2hs-type-hook () "C2HS type hook" (check-properties '("{# type gint #}") - '(("{#" t c2hs-hook-pair-face) - ("type" "w" c2hs-hook-name-face) - ("#}" t c2hs-hook-pair-face)) - 'c2hs-mode)) + '(("{#" t haskell-c2hs-hook-pair-face) + ("type" "w" haskell-c2hs-hook-name-face) + ("#}" t haskell-c2hs-hook-pair-face)) + 'haskell-c2hs-mode)) (ert-deftest haskell-c2hs-sizeof-hook () "C2HS sizeof hook" (check-properties '("{# sizeof double #}") - '(("{#" t c2hs-hook-pair-face) - ("sizeof" "w" c2hs-hook-name-face) - ("#}" t c2hs-hook-pair-face)) - 'c2hs-mode)) + '(("{#" t haskell-c2hs-hook-pair-face) + ("sizeof" "w" haskell-c2hs-hook-name-face) + ("#}" t haskell-c2hs-hook-pair-face)) + 'haskell-c2hs-mode)) (ert-deftest haskell-c2hs-enum-hook () "C2HS enum hook" @@ -64,9 +64,9 @@ " }" " deriving (Show, Eq, Ord)" " #}") - '(("{#" t c2hs-hook-pair-face) - ("enum" "w" c2hs-hook-name-face) - ("as" "w" c2hs-hook-name-face) + '(("{#" t haskell-c2hs-hook-pair-face) + ("enum" "w" haskell-c2hs-hook-name-face) + ("as" "w" haskell-c2hs-hook-name-face) ("Quantization" "w" haskell-constructor-face) ("V4L2_QUANTIZATION_DEFAULT" "w" haskell-constructor-face) ("Default" "w" haskell-constructor-face) @@ -78,8 +78,8 @@ ("Show" "w" haskell-constructor-face) ("Eq" "w" haskell-constructor-face) ("Ord" "w" haskell-constructor-face) - ("#}" t c2hs-hook-pair-face)) - 'c2hs-mode)) + ("#}" t haskell-c2hs-hook-pair-face)) + 'haskell-c2hs-mode)) (ert-deftest haskell-c2hs-enum-define-hook () "C2HS enum define hook" @@ -93,9 +93,9 @@ " deriving (Show, Eq, Ord)" " #}" ) - '(("{#" t c2hs-hook-pair-face) - ("enum" "w" c2hs-hook-name-face) - ("define" "w" c2hs-hook-name-face) + '(("{#" t haskell-c2hs-hook-pair-face) + ("enum" "w" haskell-c2hs-hook-name-face) + ("define" "w" haskell-c2hs-hook-name-face) ("MMapProtectionFlag" "w" haskell-constructor-face) ("PROT_READ" "w" haskell-constructor-face) ("ProtRead" "w" haskell-constructor-face) @@ -109,8 +109,8 @@ ("Show" "w" haskell-constructor-face) ("Eq" "w" haskell-constructor-face) ("Ord" "w" haskell-constructor-face) - ("#}" t c2hs-hook-pair-face)) - 'c2hs-mode)) + ("#}" t haskell-c2hs-hook-pair-face)) + 'haskell-c2hs-mode)) (ert-deftest haskell-c2hs-pure-call-hook () "C2HS pure call hook" @@ -124,47 +124,47 @@ ("Float" "w" haskell-constructor-face) ("sin" "w" haskell-definition-face) ("=" t haskell-operator-face) - ("{#" t c2hs-hook-pair-face) - ("call" "w" c2hs-hook-name-face) - ("pure" "w" c2hs-hook-name-face) - ("as" "w" c2hs-hook-name-face) - ("#}" t c2hs-hook-pair-face)) - 'c2hs-mode)) + ("{#" t haskell-c2hs-hook-pair-face) + ("call" "w" haskell-c2hs-hook-name-face) + ("pure" "w" haskell-c2hs-hook-name-face) + ("as" "w" haskell-c2hs-hook-name-face) + ("#}" t haskell-c2hs-hook-pair-face)) + 'haskell-c2hs-mode)) (ert-deftest haskell-c2hs-unsafe-call-hook () "C2HS unsafe fun hook" (check-properties '("{#fun unsafe sin as ^#}") - '(("{#" t c2hs-hook-pair-face) - ("fun" "w" c2hs-hook-name-face) - ("unsafe" "w" c2hs-hook-name-face) - ("as" "w" c2hs-hook-name-face) + '(("{#" t haskell-c2hs-hook-pair-face) + ("fun" "w" haskell-c2hs-hook-name-face) + ("unsafe" "w" haskell-c2hs-hook-name-face) + ("as" "w" haskell-c2hs-hook-name-face) ("^" t font-lock-negation-char-face) - ("#}" t c2hs-hook-pair-face)) - 'c2hs-mode)) + ("#}" t haskell-c2hs-hook-pair-face)) + 'haskell-c2hs-mode)) (ert-deftest haskell-c2hs-pure-fun-hook () "C2HS pure call hook" (check-properties '("{#fun pure sin as \"_sin\"#}") - '(("{#" t c2hs-hook-pair-face) - ("fun" "w" c2hs-hook-name-face) - ("pure" "w" c2hs-hook-name-face) - ("as" "w" c2hs-hook-name-face) - ("#}" t c2hs-hook-pair-face)) - 'c2hs-mode)) + '(("{#" t haskell-c2hs-hook-pair-face) + ("fun" "w" haskell-c2hs-hook-name-face) + ("pure" "w" haskell-c2hs-hook-name-face) + ("as" "w" haskell-c2hs-hook-name-face) + ("#}" t haskell-c2hs-hook-pair-face)) + 'haskell-c2hs-mode)) (ert-deftest haskell-c2hs-unsafe-fun-hook () "C2HS unsafe fun hook" (check-properties '("{#fun unsafe sin as ^#}") - '(("{#" t c2hs-hook-pair-face) - ("fun" "w" c2hs-hook-name-face) - ("unsafe" "w" c2hs-hook-name-face) - ("as" "w" c2hs-hook-name-face) + '(("{#" t haskell-c2hs-hook-pair-face) + ("fun" "w" haskell-c2hs-hook-name-face) + ("unsafe" "w" haskell-c2hs-hook-name-face) + ("as" "w" haskell-c2hs-hook-name-face) ("^" t font-lock-negation-char-face) - ("#}" t c2hs-hook-pair-face)) - 'c2hs-mode)) + ("#}" t haskell-c2hs-hook-pair-face)) + 'haskell-c2hs-mode)) (ert-deftest haskell-c2hs-get-hook () "C2HS get hook" @@ -181,77 +181,77 @@ ("Visual" "w" haskell-constructor-face) ("=" t haskell-operator-face) ("$" t haskell-operator-face) - ("{#" t c2hs-hook-pair-face) - ("get" "w" c2hs-hook-name-face) + ("{#" t haskell-c2hs-hook-pair-face) + ("get" "w" haskell-c2hs-hook-name-face) ("Visual" "w" haskell-constructor-face) ("->" t haskell-operator-face) - ("#}" t c2hs-hook-pair-face)) - 'c2hs-mode)) + ("#}" t haskell-c2hs-hook-pair-face)) + 'haskell-c2hs-mode)) (ert-deftest haskell-c2hs-set-hook () "C2HS set hook" (check-properties '("{#set sockaddr_in.sin_family#} addr_in (cFromEnum AF_NET)") - '(("{#" t c2hs-hook-pair-face) - ("set" "w" c2hs-hook-name-face) - ("#}" t c2hs-hook-pair-face) + '(("{#" t haskell-c2hs-hook-pair-face) + ("set" "w" haskell-c2hs-hook-name-face) + ("#}" t haskell-c2hs-hook-pair-face) ("AF_NET" "w" haskell-constructor-face)) - 'c2hs-mode)) + 'haskell-c2hs-mode)) (ert-deftest haskell-c2hs-pointer-hook-1 () "C2HS pointer hook" (check-properties '("{#pointer *GtkObject as Object foreign newtype#}") - '(("{#" t c2hs-hook-pair-face) - ("pointer" "w" c2hs-hook-name-face) - ("*" t c2hs-hook-name-face) + '(("{#" t haskell-c2hs-hook-pair-face) + ("pointer" "w" haskell-c2hs-hook-name-face) + ("*" t haskell-c2hs-hook-name-face) ("GtkObject" "w" haskell-constructor-face) - ("as" "w" c2hs-hook-name-face) + ("as" "w" haskell-c2hs-hook-name-face) ("Object" "w" haskell-constructor-face) - ("foreign" "w" c2hs-hook-name-face) - ("newtype" "w" c2hs-hook-name-face) - ("#}" t c2hs-hook-pair-face)) - 'c2hs-mode)) + ("foreign" "w" haskell-c2hs-hook-name-face) + ("newtype" "w" haskell-c2hs-hook-name-face) + ("#}" t haskell-c2hs-hook-pair-face)) + 'haskell-c2hs-mode)) (ert-deftest haskell-c2hs-pointer-hook-2 () "C2HS pointer hook" (check-properties '("{# pointer point as PointPtr -> Point #}") - '(("{#" t c2hs-hook-pair-face) - ("pointer" "w" c2hs-hook-name-face) + '(("{#" t haskell-c2hs-hook-pair-face) + ("pointer" "w" haskell-c2hs-hook-name-face) ("PointPtr" "w" haskell-constructor-face) ("->" t haskell-operator-face) ("Point" "w" haskell-constructor-face) - ("#}" t c2hs-hook-pair-face)) - 'c2hs-mode)) + ("#}" t haskell-c2hs-hook-pair-face)) + 'haskell-c2hs-mode)) (ert-deftest haskell-c2hs-full-pointer-hook () "C2HS full pointer hook" (check-properties '("{#pointer * foo_t as FooPtr stable -> MkFooPtr nocode#}") - '(("{#" t c2hs-hook-pair-face) - ("pointer" "w" c2hs-hook-name-face) - ("*" t c2hs-hook-name-face) - ("as" "w" c2hs-hook-name-face) + '(("{#" t haskell-c2hs-hook-pair-face) + ("pointer" "w" haskell-c2hs-hook-name-face) + ("*" t haskell-c2hs-hook-name-face) + ("as" "w" haskell-c2hs-hook-name-face) ("FooPtr" "w" haskell-constructor-face) - ("stable" "w" c2hs-hook-name-face) + ("stable" "w" haskell-c2hs-hook-name-face) ("MkFooPtr" "w" haskell-constructor-face) - ("nocode" "w" c2hs-hook-name-face) - ("#}" t c2hs-hook-pair-face)) - 'c2hs-mode)) + ("nocode" "w" haskell-c2hs-hook-name-face) + ("#}" t haskell-c2hs-hook-pair-face)) + 'haskell-c2hs-mode)) (ert-deftest haskell-c2hs-class-hook () "C2HS class hook" (check-properties '("{# class GtkObjectClass => GtkWidgetClass GtkWidget #}") - '(("{#" t c2hs-hook-pair-face) - ("class" "w" c2hs-hook-name-face) + '(("{#" t haskell-c2hs-hook-pair-face) + ("class" "w" haskell-c2hs-hook-name-face) ("GtkObjectClass" "w" haskell-constructor-face) ("=>" t haskell-operator-face) ("GtkWidgetClass" "w" haskell-constructor-face) ("GtkWidget" "w" haskell-constructor-face) - ("#}" t c2hs-hook-pair-face)) - 'c2hs-mode)) + ("#}" t haskell-c2hs-hook-pair-face)) + 'haskell-c2hs-mode)) (ert-deftest haskell-c2hs-alignof-hook () "C2HS alignof hook" @@ -263,47 +263,47 @@ ("Int" "w" haskell-constructor-face) ("gIntAlign" "w" haskell-definition-face) ("=" t haskell-operator-face) - ("{#" t c2hs-hook-pair-face) - ("alignof" "w" c2hs-hook-name-face) - ("#}" t c2hs-hook-pair-face)) - 'c2hs-mode)) + ("{#" t haskell-c2hs-hook-pair-face) + ("alignof" "w" haskell-c2hs-hook-name-face) + ("#}" t haskell-c2hs-hook-pair-face)) + 'haskell-c2hs-mode)) (ert-deftest haskell-c2hs-offsetof-hook () "C2HS offsetof hook" (check-properties '("{#offsetof struct_t->somefield#}") - '(("{#" t c2hs-hook-pair-face) - ("offsetof" "w" c2hs-hook-name-face) - ("#}" t c2hs-hook-pair-face)) - 'c2hs-mode)) + '(("{#" t haskell-c2hs-hook-pair-face) + ("offsetof" "w" haskell-c2hs-hook-name-face) + ("#}" t haskell-c2hs-hook-pair-face)) + 'haskell-c2hs-mode)) (ert-deftest haskell-c2hs-const-hook () "C2HS const hook" (check-properties '("{#const FOO_BAR#}") - '(("{#" t c2hs-hook-pair-face) - ("const" "w" c2hs-hook-name-face) - ("#}" t c2hs-hook-pair-face)) - 'c2hs-mode)) + '(("{#" t haskell-c2hs-hook-pair-face) + ("const" "w" haskell-c2hs-hook-name-face) + ("#}" t haskell-c2hs-hook-pair-face)) + 'haskell-c2hs-mode)) (ert-deftest haskell-c2hs-typedef-hook () "C2HS typedef hook" (check-properties '("{# typedef size_t CSize #}") - '(("{#" t c2hs-hook-pair-face) - ("typedef" "w" c2hs-hook-name-face) + '(("{#" t haskell-c2hs-hook-pair-face) + ("typedef" "w" haskell-c2hs-hook-name-face) ("CSize" "w" haskell-constructor-face) - ("#}" t c2hs-hook-pair-face)) - 'c2hs-mode)) + ("#}" t haskell-c2hs-hook-pair-face)) + 'haskell-c2hs-mode)) (ert-deftest haskell-c2hs-nongnu-hook () "C2HS nonGNU hook" (check-properties '("{#nonGNU#}") - '(("{#" t c2hs-hook-pair-face) - ("nonGNU" "w" c2hs-hook-name-face) - ("#}" t c2hs-hook-pair-face)) - 'c2hs-mode)) + '(("{#" t haskell-c2hs-hook-pair-face) + ("nonGNU" "w" haskell-c2hs-hook-name-face) + ("#}" t haskell-c2hs-hook-pair-face)) + 'haskell-c2hs-mode)) ;; haskell-c2hs-tests.el ends here From 7d1235e287ca8bad4ef89a59e74b387aae299af0 Mon Sep 17 00:00:00 2001 From: Sergey Vinokurov Date: Tue, 15 Mar 2016 09:56:40 +0200 Subject: [PATCH 2/2] get rid of haskell--rx-let macro --- haskell-c2hs.el | 266 ++++++++++++++++++++++++----------------------- haskell-utils.el | 18 ---- 2 files changed, 135 insertions(+), 149 deletions(-) diff --git a/haskell-c2hs.el b/haskell-c2hs.el index 7bc6a7753..c4cb41ec3 100644 --- a/haskell-c2hs.el +++ b/haskell-c2hs.el @@ -44,137 +44,141 @@ :group 'haskell) (defvar haskell-c2hs-font-lock-keywords - `((,(haskell--rx-let ((ws (any ?\s ?\t ?\n ?\r)) - (anychar (or (not (any ?#)) - (seq "#" - (not (any ?\}))))) - (any-nonquote (or (not (any ?# ?\")) - (seq "#" - (not (any ?\} ?\"))))) - (cid (seq (any (?a . ?z) (?A . ?Z) ?_) - (* (any (?a . ?z) (?A . ?Z) (?0 . ?9) ?_)))) - (hsid-type (seq (? "'") - (any (?A . ?Z)) - (* (any (?a . ?z) (?A . ?Z) (?0 . ?9) ?_ ?')))) - (equals-str-val (seq (* ws) - "=" - (* ws) - "\"" - (* any-nonquote) - "\""))) - (group-n 1 "{#") - (* ws) - (or (seq (group-n 2 - "import" - (opt (+ ws) - "qualified")) - (+ ws)) - (seq (group-n 2 - "context") - (opt (+ ws) - (group-n 3 - "lib") - equals-str-val) - (opt (+ ws) - (group-n 4 - "prefix") - equals-str-val) - (opt (+ ws) - (group-n 5 - "add" - (+ ws) - "prefix") - equals-str-val)) - (seq (group-n 2 - "type") - (+ ws) - cid) - (seq (group-n 2 - "sizeof") - (+ ws) - cid) - (seq (group-n 2 - "enum" - (+ ws) - "define") - (+ ws) - cid) - ;; TODO: vanilla enum fontification is incomplete - (seq (group-n 2 - "enum") - (+ ws) - cid - (opt (+ ws) - (group-n 3 - "as"))) - ;; TODO: fun hook highlighting is incompelete - (seq (group-n 2 - (or "call" - "fun") - (opt (+ ws) - "pure") - (opt (+ ws) - "unsafe")) - (+ ws) - cid - (opt (+ ws) - (group-n 3 - "as") - (opt (+ ws) - (group-n 8 - "^")))) - (group-n 2 - "get") - (group-n 2 - "set") - (seq (group-n 2 - "pointer") - (or (seq (* ws) - (group-n 3 "*") - (* ws)) - (+ ws)) - cid - (opt (+ ws) - (group-n 4 "as") - (+ ws) - hsid-type) - (opt (+ ws) - (group-n 5 - (or "foreign" - "stable"))) - (opt - (or (seq (+ ws) - (group-n 6 - "newtype")) - (seq (* ws) - "->" - (* ws) - hsid-type))) - (opt (+ ws) - (group-n 7 - "nocode"))) - (group-n 2 - "class") - (group-n 2 - "alignof") - (group-n 2 - "offsetof") - (seq (group-n 2 - "const") - (+ ws) - cid) - (seq (group-n 2 - "typedef") - (+ ws) - cid - (+ ws) - hsid-type) - (group-n 2 - "nonGNU") - ;; TODO: default hook not implemented - ) - (* anychar) - (group-n 9 "#}")) + `((,(eval-when-compile + (let* ((ws '(any ?\s ?\t ?\n ?\r)) + (anychar '(or (not (any ?#)) + (seq "#" + (not (any ?\}))))) + (any-nonquote '(or (not (any ?# ?\")) + (seq "#" + (not (any ?\} ?\"))))) + (cid '(seq (any (?a . ?z) (?A . ?Z) ?_) + (* (any (?a . ?z) (?A . ?Z) (?0 . ?9) ?_)))) + (hsid-type '(seq (? "'") + (any (?A . ?Z)) + (* (any (?a . ?z) (?A . ?Z) (?0 . ?9) ?_ ?')))) + (equals-str-val `(seq (* ,ws) + "=" + (* ,ws) + "\"" + (* ,any-nonquote) + "\""))) + (eval + `(rx + (seq + (group-n 1 "{#") + (* ,ws) + (or (seq (group-n 2 + "import" + (opt (+ ,ws) + "qualified")) + (+ ,ws)) + (seq (group-n 2 + "context") + (opt (+ ,ws) + (group-n 3 + "lib") + ,equals-str-val) + (opt (+ ,ws) + (group-n 4 + "prefix") + ,equals-str-val) + (opt (+ ,ws) + (group-n 5 + "add" + (+ ,ws) + "prefix") + ,equals-str-val)) + (seq (group-n 2 + "type") + (+ ,ws) + ,cid) + (seq (group-n 2 + "sizeof") + (+ ,ws) + ,cid) + (seq (group-n 2 + "enum" + (+ ,ws) + "define") + (+ ,ws) + ,cid) + ;; TODO: vanilla enum fontification is incomplete + (seq (group-n 2 + "enum") + (+ ,ws) + ,cid + (opt (+ ,ws) + (group-n 3 + "as"))) + ;; TODO: fun hook highlighting is incompelete + (seq (group-n 2 + (or "call" + "fun") + (opt (+ ,ws) + "pure") + (opt (+ ,ws) + "unsafe")) + (+ ,ws) + ,cid + (opt (+ ,ws) + (group-n 3 + "as") + (opt (+ ,ws) + (group-n 8 + "^")))) + (group-n 2 + "get") + (group-n 2 + "set") + (seq (group-n 2 + "pointer") + (or (seq (* ,ws) + (group-n 3 "*") + (* ,ws)) + (+ ,ws)) + ,cid + (opt (+ ,ws) + (group-n 4 "as") + (+ ,ws) + ,hsid-type) + (opt (+ ,ws) + (group-n 5 + (or "foreign" + "stable"))) + (opt + (or (seq (+ ,ws) + (group-n 6 + "newtype")) + (seq (* ,ws) + "->" + (* ,ws) + ,hsid-type))) + (opt (+ ,ws) + (group-n 7 + "nocode"))) + (group-n 2 + "class") + (group-n 2 + "alignof") + (group-n 2 + "offsetof") + (seq (group-n 2 + "const") + (+ ,ws) + ,cid) + (seq (group-n 2 + "typedef") + (+ ,ws) + ,cid + (+ ,ws) + ,hsid-type) + (group-n 2 + "nonGNU") + ;; TODO: default hook not implemented + ) + (* ,anychar) + (group-n 9 "#}")))))) ;; Override highlighting for pairs in order to always distinguish them. (1 'haskell-c2hs-hook-pair-face t) (2 'haskell-c2hs-hook-name-face) diff --git a/haskell-utils.el b/haskell-utils.el index 394c8dcab..ba1cd2f40 100644 --- a/haskell-utils.el +++ b/haskell-utils.el @@ -180,23 +180,5 @@ expression bounds." end-c value))))) -(defmacro haskell--rx-let (definitions &rest main-expr) - "Return `rx' invokation of main-expr that has symbols defined in -DEFINITIONS substituted by definition body. DEFINITIONS is list -of let-bindig forms, ( ). No recursion is permitted - -no defined symbol should show up in body of its definition or in -body of any futher definition." - (declare (indent 1)) - (let ((invalid-def (cl-find-if (lambda (def) (not (= 2 (length def)))) definitions))) - (when invalid-def - (error "haskell--rx-let: every definition must consist of two elements: (name def), but this one doesn't: %s" - invalid-def))) - `(rx ,@(cl-reduce (lambda (def expr) - (cl-subst (cadr def) (car def) expr - :test #'eq)) - definitions - :initial-value main-expr - :from-end t))) - (provide 'haskell-utils) ;;; haskell-utils.el ends here