From ba3e997b1b6e57b9f19aeea783ae8b2fc499c4dd Mon Sep 17 00:00:00 2001 From: Konstantin Kharlamov Date: Tue, 8 Oct 2024 13:16:51 +0300 Subject: [PATCH 1/2] Don't highlight top-level-only keywords at different levels MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- purescript-font-lock.el | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/purescript-font-lock.el b/purescript-font-lock.el index 85d4b7d..f13840b 100644 --- a/purescript-font-lock.el +++ b/purescript-font-lock.el @@ -172,16 +172,22 @@ Returns keywords suitable for `font-lock-keywords'." ;; "@" "~" "=>") t) "\\(->\\|\\.\\.\\|::\\|∷\\|<-\\|=>\\|[=@\\|~]\\)" "\\S_")) + ;; These are only keywords when appear at top-level, optionally with + ;; indentation. They are not reserved and in other levels would represent + ;; record fields or other identifiers. + (toplevel-keywords + (rx line-start (zero-or-more whitespace) + (group (or "type" "module" "import" "data" "class" "newtype" + "instance") + word-end))) ;; Reserved identifiers (reservedid ;; `as', `hiding', and `qualified' are part of the import ;; spec syntax, but they are not reserved. ;; `_' can go in here since it has temporary word syntax. (regexp-opt - '("ado" "case" "class" "data" "default" "deriving" - "do" "else" "if" "import" "in" "infix" "infixl" - "infixr" "instance" "let" "module" "newtype" "of" - "then" "type" "where" "_") 'words)) + '("ado" "case" "default" "deriving" "do" "else" "if" "in" "infix" + "infixl" "infixr" "let" "of" "then" "where" "_") 'words)) ;; Top-level declarations (topdecl-var @@ -210,6 +216,7 @@ Returns keywords suitable for `font-lock-keywords'." ("^>>>>>>> .*$" 0 'font-lock-warning-face t) ("^#.*$" 0 'font-lock-preprocessor-face t) + (,toplevel-keywords 1 (symbol-value 'purescript-keyword-face)) (,reservedid 1 (symbol-value 'purescript-keyword-face)) (,reservedsym 1 (symbol-value 'purescript-operator-face)) ;; Special case for `as', `hiding', `safe' and `qualified', which are From 0a8aebba3b5aa3ae991991ce5392e481d0056efc Mon Sep 17 00:00:00 2001 From: Konstantin Kharlamov Date: Mon, 9 Dec 2024 21:20:14 +0300 Subject: [PATCH 2/2] Rename keyword "deriving" to "derive" PureScript, as opposed to Haskell, doesn't seem to have `deriving` as a keyword. I grepped over `purescript` compiler `tests/` directory to be sure. Instead it has `derive` keyword, which is a top level one that serves similar purpose to "deriving". So rename `deriving` to `derive`. --- purescript-font-lock.el | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/purescript-font-lock.el b/purescript-font-lock.el index f13840b..25ebc9a 100644 --- a/purescript-font-lock.el +++ b/purescript-font-lock.el @@ -178,7 +178,7 @@ Returns keywords suitable for `font-lock-keywords'." (toplevel-keywords (rx line-start (zero-or-more whitespace) (group (or "type" "module" "import" "data" "class" "newtype" - "instance") + "instance" "derive") word-end))) ;; Reserved identifiers (reservedid @@ -186,7 +186,7 @@ Returns keywords suitable for `font-lock-keywords'." ;; spec syntax, but they are not reserved. ;; `_' can go in here since it has temporary word syntax. (regexp-opt - '("ado" "case" "default" "deriving" "do" "else" "if" "in" "infix" + '("ado" "case" "default" "do" "else" "if" "in" "infix" "infixl" "infixr" "let" "of" "then" "where" "_") 'words)) ;; Top-level declarations