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
@@ -527,19 +529,21 @@ function or trait. When nil, where will be aligned with fn or trait."
527
529
(defconst rust-re-special-types (regexp-opt-symbols rust-special-types))
528
530
529
531
530
- (defun rust-module-font-lock-matcher (limit )
531
- " Matches module names \" foo::\" but does not match type annotations \" foo::<\" ."
532
- (block nil
533
- (while t
534
- (let* ((symbol-then-colons (rx-to-string `(seq (group (regexp , rust-re-ident )) " ::" )))
535
- (match (re-search-forward symbol-then-colons limit t )))
536
- (cond
537
- ; ; If we didn't find a match, there are no more occurrences
538
- ; ; of foo::, so return.
539
- ((null match ) (return nil ))
540
- ; ; If this isn't a type annotation foo::<, we've found a
541
- ; ; match, so a return it!
542
- ((not (looking-at (rx (0+ space) " <" ))) (return match )))))))
532
+ (defun rust-path-font-lock-matcher (re-ident )
533
+ " Matches names like \" foo::\" or \" Foo::\" (depending on RE-IDENT, which should match
534
+ the desired identifiers), but does not match type annotations \" foo::<\" ."
535
+ `(lambda (limit)
536
+ (block nil
537
+ (while t
538
+ (let* ((symbol-then-colons (rx-to-string '(seq (group (regexp , re-ident )) " ::" )))
539
+ (match (re-search-forward symbol-then-colons limit t )))
540
+ (cond
541
+ ; ; If we didn't find a match, there are no more occurrences
542
+ ; ; of foo::, so return.
543
+ ((null match ) (return nil ))
544
+ ; ; If this isn't a type annotation foo::<, we've found a
545
+ ; ; match, so a return it!
546
+ ((not (looking-at (rx (0+ space) " <" ))) (return match ))))))))
543
547
544
548
(defvar rust-mode-font-lock-keywords
545
549
(append
@@ -564,8 +568,11 @@ function or trait. When nil, where will be aligned with fn or trait."
564
568
; ; Field names like `foo:`, highlight excluding the :
565
569
(,(concat (rust-re-grab rust-re-ident) " :[^:]" ) 1 font-lock-variable-name-face )
566
570
571
+ ; ; Type names like `Foo::`, highlight excluding the ::
572
+ (,(rust-path-font-lock-matcher rust-re-uc-ident) 1 font-lock-type-face )
573
+
567
574
; ; Module names like `foo::`, highlight excluding the ::
568
- (rust-module -font-lock-matcher 1 font-lock-type -face )
575
+ (,( rust-path -font-lock-matcher rust-re-lc-ident) 1 font-lock-constant -face )
569
576
570
577
; ; Lifetimes like `'foo`
571
578
(,(concat " '" (rust-re-grab rust-re-ident) " [^']" ) 1 font-lock-variable-name-face )
@@ -581,10 +588,9 @@ function or trait. When nil, where will be aligned with fn or trait."
581
588
'((" enum" . font-lock-type-face )
582
589
(" struct" . font-lock-type-face )
583
590
(" type" . font-lock-type-face )
584
- (" mod" . font-lock-type-face )
585
- (" use" . font-lock-type-face )
586
- (" fn" . font-lock-function-name-face )
587
- (" static" . font-lock-constant-face )))))
591
+ (" mod" . font-lock-constant-face )
592
+ (" use" . font-lock-constant-face )
593
+ (" fn" . font-lock-function-name-face )))))
588
594
589
595
(defvar font-lock-beg )
590
596
(defvar font-lock-end )
0 commit comments