summaryrefslogtreecommitdiff
path: root/rust-mode.el
diff options
context:
space:
mode:
authorNiko Matsakis <niko@alum.mit.edu>2016-01-06 09:42:28 -0500
committerNiko Matsakis <niko@alum.mit.edu>2016-01-06 09:42:28 -0500
commit2cd3cf93853fc8e46011f4d98bd95ffa695c6257 (patch)
treeb03e0b6d9fb33d7287c3867c6c77990e095705ca /rust-mode.el
parent061e6d8a3a9104570144f1eacb729e3211cb03cd (diff)
parentdd6d417c1404efcf2364a61fd7e855ec134a991f (diff)
downloadrust-mode-2cd3cf93853fc8e46011f4d98bd95ffa695c6257.tar.gz
Merge pull request #116 from Wilfred/type_annotation_highlighting
Fix type annotations incorrectly highlighted as modules.
Diffstat (limited to 'rust-mode.el')
-rw-r--r--rust-mode.el20
1 files changed, 18 insertions, 2 deletions
diff --git a/rust-mode.el b/rust-mode.el
index 8049273..4697c70 100644
--- a/rust-mode.el
+++ b/rust-mode.el
@@ -14,6 +14,7 @@
;;; Code:
(eval-when-compile (require 'rx)
+ (require 'cl)
(require 'compile)
(require 'url-vars))
@@ -525,6 +526,21 @@ function or trait. When nil, where will be aligned with fn or trait."
(concat "\\_<" (regexp-opt words t) "\\_>"))
(defconst rust-re-special-types (regexp-opt-symbols rust-special-types))
+
+(defun rust-module-font-lock-matcher (limit)
+ "Matches module names \"foo::\" but does not match type annotations \"foo::<\"."
+ (block nil
+ (while t
+ (let* ((symbol-then-colons (rx-to-string `(seq (group (regexp ,rust-re-ident)) "::")))
+ (match (re-search-forward symbol-then-colons limit t)))
+ (cond
+ ;; If we didn't find a match, there are no more occurrences
+ ;; of foo::, so return.
+ ((null match) (return nil))
+ ;; If this isn't a type annotation foo::<, we've found a
+ ;; match, so a return it!
+ ((not (looking-at (rx (0+ space) "<"))) (return match)))))))
+
(defvar rust-mode-font-lock-keywords
(append
`(
@@ -548,8 +564,8 @@ function or trait. When nil, where will be aligned with fn or trait."
;; Field names like `foo:`, highlight excluding the :
(,(concat (rust-re-grab rust-re-ident) ":[^:]") 1 font-lock-variable-name-face)
- ;; Module names like `foo::`, highlight including the ::
- (,(rust-re-grab (concat rust-re-ident "::")) 1 font-lock-type-face)
+ ;; Module names like `foo::`, highlight excluding the ::
+ (rust-module-font-lock-matcher 1 font-lock-type-face)
;; Lifetimes like `'foo`
(,(concat "'" (rust-re-grab rust-re-ident) "[^']") 1 font-lock-variable-name-face)