emacs mode: Highlight 'foo as a lifetime, not a character constant.

This commit is contained in:
Niko Matsakis 2013-02-11 16:33:44 -08:00
parent c7f85003a3
commit 1ef8c48a20

View file

@ -101,14 +101,7 @@
(rust-push-context st 'string (current-column) t)
(setf (rust-state-tokenize st) 'rust-token-string)
(rust-token-string st))
(def ?\' (forward-char)
(setf rust-tcat 'atom)
(let ((is-escape (eq (char-after) ?\\))
(start (point)))
(if (not (rust-eat-until-unescaped ?\'))
'font-lock-warning-face
(if (or is-escape (= (point) (+ start 2)))
'font-lock-string-face 'font-lock-warning-face))))
(def ?\' (rust-single-quote))
(def ?/ (forward-char)
(case (char-after)
(?/ (end-of-line) 'font-lock-comment-face)
@ -150,6 +143,23 @@
(setf rust-tcat 'op) nil)
table)))
(defun rust-single-quote ()
(forward-char)
(setf rust-tcat 'atom)
; Is this a lifetime?
(if (or (looking-at "[a-zA-Z_]$")
(looking-at "[a-zA-Z_][^']"))
; If what we see is 'abc, use font-lock-type-face:
(progn (rust-eat-re "[a-zA-Z_][a-zA-Z_0-9]*")
'font-lock-type-face)
; Otherwise, handle as a character constant:
(let ((is-escape (eq (char-after) ?\\))
(start (point)))
(if (not (rust-eat-until-unescaped ?\'))
'font-lock-warning-face
(if (or is-escape (= (point) (+ start 2)))
'font-lock-string-face 'font-lock-warning-face)))))
(defun rust-token-base (st)
(funcall (char-table-range rust-char-table (char-after)) st))