Skip to content

Improve multiple issues with font lock #579

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 17, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 5 additions & 50 deletions haskell-font-lock.el
Original file line number Diff line number Diff line change
Expand Up @@ -183,36 +183,14 @@ Returns keywords suitable for `font-lock-keywords'."
;; "^>", otherwise a line of code starts with "^".
(line-prefix (if (eq literate 'bird) "^> ?" "^"))

;; Most names are borrowed from the lexical syntax of the Haskell
;; report.
;; Some of these definitions have been superseded by using the
;; syntax table instead.

;; (ASCsymbol "-!#$%&*+./<=>?@\\\\^|~")
;; Put the minus first to make it work in ranges.

;; We allow _ as the first char to fit GHC
(varid "\\b[[:lower:]_][[:alnum:]'_]*\\b")
;; We allow ' preceding conids because of DataKinds/PolyKinds
(conid "\\b'?[[:upper:]][[:alnum:]'_]*\\b")
(modid (concat "\\b" conid "\\(\\." conid "\\)*\\b"))
(qvarid (concat modid "\\." varid))
(qconid (concat modid "\\." conid))
(sym
;; We used to use the below for non-Emacs21, but I think the
;; regexp based on syntax works for other emacsen as well. -- Stef
;; (concat "[" symbol ":]+")
;; Add backslash to the symbol-syntax chars. This seems to
;; be thrown for some reason by backslash's escape syntax.
"\\(\\s.\\|\\\\\\)+")

;; Reserved operations
(reservedsym
(concat "\\S."
;; (regexp-opt '(".." "::" "=" "\\" "|" "<-" "->"
;; "@" "~" "=>") t)
"\\(->\\|→\\|\\.\\.\\|::\\|∷\\|<-\\|←\\|=>\\|[=@\\|~]\\)"
"\\S."))
(sym "\\s.+")

;; Reserved identifiers
(reservedid
(concat "\\<"
Expand All @@ -227,15 +205,6 @@ Returns keywords suitable for `font-lock-keywords'."
"\\(_\\|c\\(ase\\|lass\\)\\|d\\(ata\\|e\\(fault\\|riving\\)\\|o\\)\\|else\\|i\\(mport\\|n\\(fix[lr]?\\|stance\\)\\|[fn]\\)\\|let\\|module\\|mdo\\|newtype\\|of\\|rec\\|proc\\|t\\(hen\\|ype\\)\\|where\\)"
"\\>"))

;; This unreadable regexp matches strings and character
;; constants. We need to do this with one regexp to handle
;; stuff like '"':"'". The regexp is the composition of
;; "([^"\\]|\\.)*" for strings and '([^\\]|\\.[^']*)' for
;; characters, allowing for string continuations.
;; Could probably be improved...
(string-and-char
(concat "\\(\\(\"\\|" line-prefix "[ \t]*\\\\\\)\\([^\"\\\\\n]\\|\\\\.\\)*\\(\"\\|\\\\[ \t]*$\\)\\|'\\([^'\\\\\n]\\|\\\\.[^'\n]*\\)'\\)"))

;; Top-level declarations
(topdecl-var
(concat line-prefix "\\(" varid "\\(?:\\s-*,\\s-*" varid "\\)*" "\\)\\s-*"
Expand Down Expand Up @@ -265,7 +234,7 @@ Returns keywords suitable for `font-lock-keywords'."
,@(haskell-font-lock-symbols-keywords)

(,reservedid 1 haskell-keyword-face)
(,reservedsym 1 haskell-operator-face)

;; Special case for `as', `hiding', `safe' and `qualified', which are
;; keywords in import statements but are not otherwise reserved.
("\\<import[ \t]+\\(?:\\(safe\\>\\)[ \t]*\\)?\\(?:\\(qualified\\>\\)[ \t]*\\)?\\(?:\"[^\"]*\"[\t ]*\\)?[^ \t\n()]+[ \t]*\\(?:\\(\\<as\\>\\)[ \t]*[^ \t\n()]+[ \t]*\\)?\\(\\<hiding\\>\\)?"
Expand All @@ -274,7 +243,6 @@ Returns keywords suitable for `font-lock-keywords'."
(3 haskell-keyword-face nil lax)
(4 haskell-keyword-face nil lax))

(,reservedsym 1 haskell-operator-face)
;; Special case for `foreign import'
;; keywords in foreign import statements but are not otherwise reserved.
("\\<\\(foreign\\)[ \t]+\\(import\\)[ \t]+\\(?:\\(ccall\\|stdcall\\|cplusplus\\|jvm\\|dotnet\\)[ \t]+\\)?\\(?:\\(safe\\|unsafe\\|interruptible\\)[ \t]+\\)?"
Expand All @@ -283,7 +251,6 @@ Returns keywords suitable for `font-lock-keywords'."
(3 haskell-keyword-face nil lax)
(4 haskell-keyword-face nil lax))

(,reservedsym 1 haskell-operator-face)
;; Special case for `foreign export'
;; keywords in foreign export statements but are not otherwise reserved.
("\\<\\(foreign\\)[ \t]+\\(export\\)[ \t]+\\(?:\\(ccall\\|stdcall\\|cplusplus\\|jvm\\|dotnet\\)[ \t]+\\)?"
Expand All @@ -302,31 +269,19 @@ Returns keywords suitable for `font-lock-keywords'."
;; These four are debatable...
("(\\(,*\\|->\\))" 0 haskell-constructor-face)
("\\[\\]" 0 haskell-constructor-face)
;; Expensive.

(,(concat "`" varid "`") 0 haskell-operator-face)
(,(concat "`" conid "`") 0 haskell-operator-face)
(,(concat "`" qvarid "`") 0 haskell-operator-face)
(,(concat "`" qconid "`") 0 haskell-operator-face)
(,qvarid 0 haskell-default-face)
(,qconid 0 haskell-constructor-face)
;; Expensive.

(,conid 0 haskell-constructor-face)

;; Very expensive.
(,sym 0 (if (eq (char-after (match-beginning 0)) ?:)
haskell-constructor-face
haskell-operator-face))))
(unless (boundp 'font-lock-syntactic-keywords)
(cl-case literate
(bird
(setq keywords
`(("^[^>\n].*$" 0 haskell-comment-face t)
,@keywords
("^>" 0 haskell-default-face t))))
((latex tex)
(setq keywords
`((haskell-font-lock-latex-comments 0 'font-lock-comment-face t)
,@keywords)))))
keywords))

(defvar haskell-font-lock-latex-cache-pos nil
Expand Down