[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
- [nongnu] elpa/haskell-tng-mode db064be 024/385: dank macro for font-lock extends/keyword, (continued)
- [nongnu] elpa/haskell-tng-mode db064be 024/385: dank macro for font-lock extends/keyword, ELPA Syncer, 2021/10/05
- [nongnu] elpa/haskell-tng-mode 639fc6c 018/385: multiline types and font-lock-multiline, ELPA Syncer, 2021/10/05
- [nongnu] elpa/haskell-tng-mode cc739ad 020/385: multiline topdecl type sections, ELPA Syncer, 2021/10/05
- [nongnu] elpa/haskell-tng-mode 595bd44 034/385: type families, ELPA Syncer, 2021/10/05
- [nongnu] elpa/haskell-tng-mode 77d6ec5 019/385: cleaned up multiline explicit types, ELPA Syncer, 2021/10/05
- [nongnu] elpa/haskell-tng-mode fa32b46 037/385: finally caught the bug in anchor pre/post resetting, ELPA Syncer, 2021/10/05
- [nongnu] elpa/haskell-tng-mode f2ce737 038/385: neutral, ELPA Syncer, 2021/10/05
- [nongnu] elpa/haskell-tng-mode 95ab59c 014/385: multiline type matching seems to work, ELPA Syncer, 2021/10/05
- [nongnu] elpa/haskell-tng-mode 85272cb 029/385: fixup! fixup! improve the multiline font macro, ELPA Syncer, 2021/10/05
- [nongnu] elpa/haskell-tng-mode 00f7d84 002/385: simplify names, ELPA Syncer, 2021/10/05
- [nongnu] elpa/haskell-tng-mode 111396f 004/385: converted many font-face rules to the rx DSL,
ELPA Syncer <=
- [nongnu] elpa/haskell-tng-mode 6f8258c 009/385: thinking about multiline, ELPA Syncer, 2021/10/05
- [nongnu] elpa/haskell-tng-mode 5536d23 025/385: all font locks use the new macro, ELPA Syncer, 2021/10/05
- [nongnu] elpa/haskell-tng-mode a7a90ea 028/385: fixup! improve the multiline font macro, ELPA Syncer, 2021/10/05
- [nongnu] elpa/haskell-tng-mode b9bc414 027/385: improve the multiline font macro, ELPA Syncer, 2021/10/05
- [nongnu] elpa/haskell-tng-mode ea77bb2 017/385: fixup! almost there, regions not being expanded, ELPA Syncer, 2021/10/05
- [nongnu] elpa/haskell-tng-mode 2b82b2f 022/385: fixup! fixup! multiline topdecl type sections, ELPA Syncer, 2021/10/05
- [nongnu] elpa/haskell-tng-mode 46abfc4 035/385: getting closer to good types in imports, ELPA Syncer, 2021/10/05
- [nongnu] elpa/haskell-tng-mode c3d4e70 031/385: don't reinvent standard tools, ELPA Syncer, 2021/10/05
- [nongnu] elpa/haskell-tng-mode 7c2dedb 043/385: use pyenv when running cask, ELPA Syncer, 2021/10/05
- [nongnu] elpa/haskell-tng-mode 2f04c01 051/385: starting work on semicolon inference, ELPA Syncer, 2021/10/05