diff options
| author | Niko Matsakis <niko@alum.mit.edu> | 2013-02-11 16:33:44 -0800 |
|---|---|---|
| committer | Niko Matsakis <niko@alum.mit.edu> | 2013-02-16 08:01:10 -0500 |
| commit | e976207a27080fb86b1de5b905cf9f0771c3e2cb (patch) | |
| tree | cee318986aa1765b04c30b81be640a74a39b1249 | |
| parent | 9f9dec0f835120026ad91b0589a4237b55195e85 (diff) | |
| download | rust-mode-e976207a27080fb86b1de5b905cf9f0771c3e2cb.tar.gz | |
emacs mode: Highlight 'foo as a lifetime, not a character constant.
| -rw-r--r-- | rust-mode.el | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/rust-mode.el b/rust-mode.el index ef98fa6..92b1d80 100644 --- a/rust-mode.el +++ b/rust-mode.el @@ -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)) |
