emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/haskell-tng-mode 111396f 004/385: converted many font-face


From: ELPA Syncer
Subject: [nongnu] elpa/haskell-tng-mode 111396f 004/385: converted many font-face rules to the rx DSL
Date: Tue, 5 Oct 2021 23:58:50 -0400 (EDT)

branch: elpa/haskell-tng-mode
commit 111396f105a7505e17b5d13b4aa9ea3e846b394d
Author: Tseen She <ts33n.sh3@gmail.com>
Commit: Tseen She <ts33n.sh3@gmail.com>

    converted many font-face rules to the rx DSL
---
 haskell-tng-font-lock.el | 78 ++++++++++++++++++++++++++++--------------------
 1 file changed, 46 insertions(+), 32 deletions(-)

diff --git a/haskell-tng-font-lock.el b/haskell-tng-font-lock.el
index f20e571..a357192 100644
--- a/haskell-tng-font-lock.el
+++ b/haskell-tng-font-lock.el
@@ -27,9 +27,9 @@
   "Haskell reserved names and operators."
   :group 'haskell-tng:faces)
 
-(defface haskell-tng:package
+(defface haskell-tng:module
   '((t :inherit font-lock-variable-name-face :weight bold))
-  "Haskell packages."
+  "Haskell modules (packages)."
   :group 'haskell-tng:faces)
 
 (defface haskell-tng:type
@@ -53,36 +53,50 @@
 
 (setq
  haskell-tng:keywords
- `((,(regexp-opt '("case" "class" "data" "default" "deriving" "do" "else"
-                   "foreign" "if" "import" "in" "infix" "infixl"
-                   "infixr" "instance" "let" "module" "newtype" "of"
-                   "then" "type" "where" "_")
-                 'words)
-    . 'haskell-tng:keyword) ;; reservedid
-   (,(regexp-opt '(".." ":" "::" "=" "|" "<-" ">" "->" "@" "~" "=>")
-                 'symbols)
-    . 'haskell-tng:keyword) ;; reservedop
-   ;; lambda syntax may be followed by a trailing symbol
-   ("\\_<\\(\\\\\\)" . 'haskell-tng:keyword)
-
-   ;; TODO: contextual / multiline support for the import region.
-   ;; qualified/hiding/as are keywords when used in imports
-   ("\\_<import\\_>[[:space:]]+\\_<\\(qualified\\)\\_>" 1 'haskell-tng:keyword)
-   ("\\_<import\\_>[^(]+?\\_<\\(hiding\\|as\\)\\_>" 1 'haskell-tng:keyword)
-   
("\\_<import\\_>\\(?:[[:space:]]\\|qualified\\)+\\_<\\([[:upper:]]\\(?:\\.\\|\\w\\)*\\)\\_>"
-    1 'haskell-tng:package)
-   ("\\_<import\\_>[^(]+?\\_<as[[:space:]]+\\([[:upper:]]\\w+\\)"
-    1 'haskell-tng:package)
-
-   ("\\_<module\\_>[[:space:]]+\\_<\\([[:upper:]]\\w*\\)\\_>"
-    1 'haskell-tng:package) ;; introducing modules
-
-   ("\\_<\\(\\(?:[[:upper:]]\\w*\\.\\)+\\)"
-    . 'haskell-tng:package) ;; uses of F.Q.N.s
-
-   ("\\_<\\([[:upper:]]\\w*\\)\\_>" 0 'haskell-tng:constructor) ;; conid
-   ("\\_<\\(:\\s_+\\)\\_>" 0 'haskell-tng:constructor) ;; consym
-   ))
+ ;; These regexps use the `rx' library so we can reuse common subpatterns. It
+ ;; also increases the readability of the code and, in many cases, allows us to
+ ;; do more work in a single regexp instead of multiple passes.
+ (let ((conid '(: upper (* wordchar)))
+       (consym '(: ":" (+ (syntax symbol)))))
+   `(;; reservedid / reservedop
+     (,(rx-to-string
+        '(|
+          (: word-start
+             (| "case" "class" "data" "default" "deriving" "do" "else"
+                "foreign" "if" "import" "in" "infix" "infixl"
+                "infixr" "instance" "let" "module" "newtype" "of"
+                "then" "type" "where" "_")
+             word-end)
+          (: symbol-start
+             (| ".." ":" "::" "=" "|" "<-" ">" "->" "@" "~" "=>")
+             symbol-end)
+          (: symbol-start (char ?\\))))
+      . 'haskell-tng:keyword)
+
+     ;; TODO: anchored matchers
+     ;; TODO: contextual / multiline support for the import region.
+     ;; qualified/hiding/as are keywords when used in imports
+     ("\\_<import\\_>[[:space:]]+\\_<\\(qualified\\)\\_>" 1 
'haskell-tng:keyword)
+     ("\\_<import\\_>[^(]+?\\_<\\(hiding\\|as\\)\\_>" 1 'haskell-tng:keyword)
+     
("\\_<import\\_>\\(?:[[:space:]]\\|qualified\\)+\\_<\\([[:upper:]]\\(?:\\.\\|\\w\\)*\\)\\_>"
+      1 'haskell-tng:module)
+     ("\\_<import\\_>[^(]+?\\_<as[[:space:]]+\\([[:upper:]]\\w+\\)"
+      1 'haskell-tng:module)
+
+     ;; introducing modules
+     (,(rx-to-string '(: symbol-start "module" symbol-end (+ space)
+                         symbol-start (group upper (* wordchar)) symbol-end))
+      1 'haskell-tng:module)
+
+     ;; uses of F.Q.N.s
+     (,(rx-to-string `(: symbol-start (+ (: ,conid "."))))
+      . 'haskell-tng:module)
+
+     ;; constructors
+     (,(rx-to-string `(: symbol-start (| ,conid ,consym) symbol-end))
+      . 'haskell-tng:constructor)
+
+     )))
 
 (provide 'haskell-tng-font-lock)
 ;;; haskell-tng-font-lock.el ends here



reply via email to

[Prev in Thread] Current Thread [Next in Thread]