Skip to content

Commit ab85b8d

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 ab85b8d

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

purescript-font-lock.el

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,16 +172,21 @@ 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"))))
175182
;; Reserved identifiers
176183
(reservedid
177184
;; `as', `hiding', and `qualified' are part of the import
178185
;; spec syntax, but they are not reserved.
179186
;; `_' can go in here since it has temporary word syntax.
180187
(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))
188+
'("ado" "case" "default" "deriving" "do" "else" "if" "in" "infix"
189+
"infixl" "infixr" "let" "of" "then" "where" "_") 'words))
185190

186191
;; Top-level declarations
187192
(topdecl-var
@@ -210,6 +215,7 @@ Returns keywords suitable for `font-lock-keywords'."
210215
("^>>>>>>> .*$" 0 'font-lock-warning-face t)
211216
("^#.*$" 0 'font-lock-preprocessor-face t)
212217

218+
(,toplevel-keywords 1 (symbol-value 'purescript-keyword-face))
213219
(,reservedid 1 (symbol-value 'purescript-keyword-face))
214220
(,reservedsym 1 (symbol-value 'purescript-operator-face))
215221
;; Special case for `as', `hiding', `safe' and `qualified', which are

0 commit comments

Comments
 (0)