Skip to content

Commit 49e0fae

Browse files
committed
font-lock: cover more operators than just the builtins
For example, the tuple construction `1 /\ 2` was weirdly half-haighlighted before this commit, because it wasn't covered by the "operators regexp" and was getting caught by some other rule. Fix that. For inspiration, I looked at the regexp from the official Atom purescript highlight https://github.com/purescript-contrib/atom-language-purescript/blob/d17eee55b12c140e8a1a750cce7e5aa9b09653c2/src/purescript.coffee#L32 that one works a bit differently, it excludes chars from class. AFAIK Emacs can't do that, so instead I just enlisted the symbols. One thing I did differently though is including colon, because it is a valid operator in PureScript (for List), I think Atom has a bug in their regexp.
1 parent 949f827 commit 49e0fae

File tree

2 files changed

+28
-18
lines changed

2 files changed

+28
-18
lines changed

purescript-font-lock.el

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -165,12 +165,10 @@ Returns keywords suitable for `font-lock-keywords'."
165165
;; be thrown for some reason by backslash's escape syntax.
166166
"\\(\\s_\\|\\\\\\)+")
167167

168-
;; Reserved operations
169-
(reservedsym
168+
(operator
170169
(concat "\\S_"
171-
;; (regexp-opt '(".." "::" "=" "\\" "|" "<-" "->"
172-
;; "@" "~" "=>") t)
173-
"\\(->\\|\\.\\.\\|::\\|∷\\|<-\\|=>\\|[=@\\|~]\\)"
170+
;; All punctuation, excluding (),;[]{}_"'`
171+
"\\([!@#$%^&*+\\-./<=>?@|~:∷\\\\]+\\)"
174172
"\\S_"))
175173
;; These are only keywords when appear at top-level, optionally with
176174
;; indentation. They are not reserved and in other levels would represent
@@ -210,7 +208,7 @@ Returns keywords suitable for `font-lock-keywords'."
210208
;;
211209
(,toplevel-keywords 1 (symbol-value 'purescript-keyword-face))
212210
(,reservedid 1 (symbol-value 'purescript-keyword-face))
213-
(,reservedsym 1 (symbol-value 'purescript-operator-face))
211+
(,operator 1 (symbol-value 'purescript-operator-face))
214212
;; Special case for `as', `hiding', `safe' and `qualified', which are
215213
;; keywords in import statements but are not otherwise reserved.
216214
("\\<import[ \t]+\\(?:\\(safe\\>\\)[ \t]*\\)?\\(?:\\(qualified\\>\\)[ \t]*\\)?[^ \t\n()]+[ \t]*\\(?:\\(\\<as\\>\\)[ \t]*[^ \t\n()]+[ \t]*\\)?\\(\\<hiding\\>\\)?"

tests/purescript-font-lock-tests.el

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -271,33 +271,33 @@ derive newtype instance foldableNonEmptyList :: Foldable NonEmptyList
271271
(70 70 font-lock-builtin-face) (71 71 nil)
272272
(72 83 font-lock-type-face) (84 85 nil)
273273
(86 86 font-lock-keyword-face) (87 87 nil)
274-
(88 89 font-lock-type-face) (90 95 nil)
274+
(88 89 font-lock-builtin-face) (90 95 nil)
275275
(96 96 font-lock-builtin-face) (97 101 nil)
276276
(102 113 font-lock-type-face) (114 119 nil)
277-
(120 121 font-lock-type-face) (122 137 nil)
278-
(138 138 font-lock-type-face) (139 139 nil)
277+
(120 121 font-lock-builtin-face) (122 137 nil)
278+
(138 138 font-lock-builtin-face) (139 139 nil)
279279
(140 142 font-lock-type-face) (143 147 nil)
280-
(148 148 font-lock-type-face) (149 149 nil)
280+
(148 148 font-lock-builtin-face) (149 149 nil)
281281
(150 152 font-lock-type-face) (153 158 nil)
282282
(159 159 font-lock-builtin-face) (160 168 nil)
283283
(169 173 font-lock-keyword-face) (174 196 nil)
284284
(197 197 font-lock-builtin-face) (198 203 nil)
285-
(204 204 font-lock-type-face) (205 208 nil)
285+
(204 204 font-lock-builtin-face) (205 208 nil)
286286
(209 220 font-lock-type-face) (221 224 nil)
287-
(225 226 font-lock-type-face) (227 233 nil)
288-
(234 234 font-lock-type-face) (235 243 nil)
289-
(244 244 font-lock-type-face) (245 247 nil)
290-
(248 248 font-lock-type-face) (249 255 nil)
287+
(225 226 font-lock-builtin-face) (227 233 nil)
288+
(234 234 font-lock-builtin-face) (235 243 nil)
289+
(244 244 font-lock-builtin-face) (245 247 nil)
290+
(248 248 font-lock-builtin-face) (249 255 nil)
291291
(256 263 font-lock-keyword-face) (264 286 nil)
292292
(287 288 font-lock-builtin-face) (289 289 nil)
293293
(290 298 font-lock-type-face) (299 300 nil)
294294
(301 312 font-lock-type-face) (313 316 nil)
295295
(317 321 font-lock-keyword-face) (322 332 nil)
296296
(333 344 font-lock-type-face) (345 348 nil)
297-
(349 350 font-lock-type-face) (351 360 nil)
297+
(349 350 font-lock-builtin-face) (351 360 nil)
298298
(361 361 font-lock-builtin-face) (362 366 nil)
299299
(367 378 font-lock-type-face) (379 382 nil)
300-
(383 384 font-lock-type-face) (385 388 nil)
300+
(383 384 font-lock-builtin-face) (385 388 nil)
301301
(389 390 font-lock-builtin-face) (391 403 nil)
302302
(404 409 font-lock-keyword-face) (410 448 nil)
303303
(449 450 font-lock-builtin-face) (451 451 nil)
@@ -506,5 +506,17 @@ arr = 1 : [2,3]
506506
(402 402 nil)
507507
(403 403 font-lock-builtin-face)
508508
(404 406 nil)
509-
(407 407 font-lock-type-face)
509+
(407 407 font-lock-builtin-face)
510510
(408 414 nil))))
511+
512+
(ert-deftest tuple-and-cap-highlighted ()
513+
(purescript-test-ranges
514+
"myTuple = 1 /\\ (2 ^ 3)"
515+
'((1 7 font-lock-function-name-face)
516+
(8 8 nil)
517+
(9 9 font-lock-builtin-face)
518+
(10 12 nil)
519+
(13 14 font-lock-builtin-face)
520+
(15 18 nil)
521+
(19 19 font-lock-builtin-face)
522+
(20 23 nil))))

0 commit comments

Comments
 (0)