28
28
(list 'set (list 'make-local-variable (list 'quote var)) val))))
29
29
30
30
(defconst rust-re-ident " [[:word:][:multibyte:]_][[:word:][:multibyte:]_[:digit:]]*" )
31
+ (defconst rust-re-lc-ident " [[:lower:][:multibyte:]_][[:word:][:multibyte:]_[:digit:]]*" )
32
+ (defconst rust-re-uc-ident " [[:upper:]][[:word:][:multibyte:]_[:digit:]]*" )
31
33
32
34
(defconst rust-re-non-standard-string
33
35
(rx
@@ -536,19 +538,21 @@ function or trait. When nil, where will be aligned with fn or trait."
536
538
(defconst rust-re-special-types (regexp-opt-symbols rust-special-types))
537
539
538
540
539
- (defun rust-module-font-lock-matcher (limit )
540
- " Matches module names \" foo::\" but does not match type annotations \" foo::<\" ."
541
- (block nil
542
- (while t
543
- (let* ((symbol-then-colons (rx-to-string `(seq (group (regexp , rust-re-ident )) " ::" )))
544
- (match (re-search-forward symbol-then-colons limit t )))
545
- (cond
546
- ; ; If we didn't find a match, there are no more occurrences
547
- ; ; of foo::, so return.
548
- ((null match ) (return nil ))
549
- ; ; If this isn't a type annotation foo::<, we've found a
550
- ; ; match, so a return it!
551
- ((not (looking-at (rx (0+ space) " <" ))) (return match )))))))
541
+ (defun rust-path-font-lock-matcher (re-ident )
542
+ " Matches names like \" foo::\" or \" Foo::\" (depending on RE-IDENT, which should match
543
+ the desired identifiers), but does not match type annotations \" foo::<\" ."
544
+ `(lambda (limit)
545
+ (block nil
546
+ (while t
547
+ (let* ((symbol-then-colons (rx-to-string '(seq (group (regexp , re-ident )) " ::" )))
548
+ (match (re-search-forward symbol-then-colons limit t )))
549
+ (cond
550
+ ; ; If we didn't find a match, there are no more occurrences
551
+ ; ; of foo::, so return.
552
+ ((null match ) (return nil ))
553
+ ; ; If this isn't a type annotation foo::<, we've found a
554
+ ; ; match, so a return it!
555
+ ((not (looking-at (rx (0+ space) " <" ))) (return match ))))))))
552
556
553
557
(defvar rust-mode-font-lock-keywords
554
558
(append
@@ -573,8 +577,11 @@ function or trait. When nil, where will be aligned with fn or trait."
573
577
; ; Field names like `foo:`, highlight excluding the :
574
578
(,(concat (rust-re-grab rust-re-ident) " :[^:]" ) 1 font-lock-variable-name-face )
575
579
580
+ ; ; Type names like `Foo::`, highlight excluding the ::
581
+ (,(rust-path-font-lock-matcher rust-re-uc-ident) 1 font-lock-type-face )
582
+
576
583
; ; Module names like `foo::`, highlight excluding the ::
577
- (rust-module -font-lock-matcher 1 font-lock-type -face )
584
+ (,( rust-path -font-lock-matcher rust-re-lc-ident) 1 font-lock-constant -face )
578
585
579
586
; ; Lifetimes like `'foo`
580
587
(,(concat " '" (rust-re-grab rust-re-ident) " [^']" ) 1 font-lock-variable-name-face )
@@ -590,10 +597,9 @@ function or trait. When nil, where will be aligned with fn or trait."
590
597
'((" enum" . font-lock-type-face )
591
598
(" struct" . font-lock-type-face )
592
599
(" type" . font-lock-type-face )
593
- (" mod" . font-lock-type-face )
594
- (" use" . font-lock-type-face )
595
- (" fn" . font-lock-function-name-face )
596
- (" static" . font-lock-constant-face )))))
600
+ (" mod" . font-lock-constant-face )
601
+ (" use" . font-lock-constant-face )
602
+ (" fn" . font-lock-function-name-face )))))
597
603
598
604
(defvar font-lock-beg )
599
605
(defvar font-lock-end )
0 commit comments