Skip to content

Commit ba3e997

Browse files
committed
Don't highlight top-level-only keywords at different levels
The keywords being modified here only represented keywords when they are at the beginning of a line with optional indentation. At different levels these would represent valid record fields or other identifiers. This was tested by adding the following code to a PureScript file: type Foo = { type :: Int , module :: Int , import :: Int , data :: Int , class :: Int , newtype :: Int } …and checking that compilation succeeds.
1 parent d187b3d commit ba3e997

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

purescript-font-lock.el

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,16 +172,22 @@ Returns keywords suitable for `font-lock-keywords'."
172172
;; "@" "~" "=>") t)
173173
"\\(->\\|\\.\\.\\|::\\|∷\\|<-\\|=>\\|[=@\\|~]\\)"
174174
"\\S_"))
175+
;; These are only keywords when appear at top-level, optionally with
176+
;; indentation. They are not reserved and in other levels would represent
177+
;; record fields or other identifiers.
178+
(toplevel-keywords
179+
(rx line-start (zero-or-more whitespace)
180+
(group (or "type" "module" "import" "data" "class" "newtype"
181+
"instance")
182+
word-end)))
175183
;; Reserved identifiers
176184
(reservedid
177185
;; `as', `hiding', and `qualified' are part of the import
178186
;; spec syntax, but they are not reserved.
179187
;; `_' can go in here since it has temporary word syntax.
180188
(regexp-opt
181-
'("ado" "case" "class" "data" "default" "deriving"
182-
"do" "else" "if" "import" "in" "infix" "infixl"
183-
"infixr" "instance" "let" "module" "newtype" "of"
184-
"then" "type" "where" "_") 'words))
189+
'("ado" "case" "default" "deriving" "do" "else" "if" "in" "infix"
190+
"infixl" "infixr" "let" "of" "then" "where" "_") 'words))
185191

186192
;; Top-level declarations
187193
(topdecl-var
@@ -210,6 +216,7 @@ Returns keywords suitable for `font-lock-keywords'."
210216
("^>>>>>>> .*$" 0 'font-lock-warning-face t)
211217
("^#.*$" 0 'font-lock-preprocessor-face t)
212218

219+
(,toplevel-keywords 1 (symbol-value 'purescript-keyword-face))
213220
(,reservedid 1 (symbol-value 'purescript-keyword-face))
214221
(,reservedsym 1 (symbol-value 'purescript-operator-face))
215222
;; Special case for `as', `hiding', `safe' and `qualified', which are

0 commit comments

Comments
 (0)