@@ -134,34 +134,12 @@ or if NODEFAULT is non-nil, then fall back to returning nil."
134
134
135
135
; ;; Syntax
136
136
137
- (defun rust-re-word (inner ) (concat " \\ <" inner " \\ >" ))
138
- (defun rust-re-grab (inner ) (concat " \\ (" inner " \\ )" ))
139
- (defun rust-re-shy (inner ) (concat " \\ (?:" inner " \\ )" ))
140
-
141
137
(defconst rust-re-ident " [[:word:][:multibyte:]_][[:word:][:multibyte:]_[:digit:]]*" )
142
138
(defconst rust-re-lc-ident " [[:lower:][:multibyte:]_][[:word:][:multibyte:]_[:digit:]]*" )
143
139
(defconst rust-re-uc-ident " [[:upper:]][[:word:][:multibyte:]_[:digit:]]*" )
144
- (defvar rust-re-vis
145
- ; ; pub | pub ( crate ) | pub ( self ) | pub ( super ) | pub ( in SimplePath )
146
- (concat
147
- " pub"
148
- (rust-re-shy
149
- (concat
150
- " [[:space:]]*([[:space:]]*"
151
- (rust-re-shy
152
- (concat " crate" " \\ |"
153
- " \\ (?:s\\ (?:elf\\ |uper\\ )\\ )" " \\ |"
154
- ; ; in SimplePath
155
- (rust-re-shy
156
- (concat
157
- " in[[:space:]]+"
158
- rust-re-ident
159
- (rust-re-shy (concat " ::" rust-re-ident)) " *" ))))
160
- " [[:space:]]*)" ))
161
- " ?" ))
140
+ (defconst rust-re-vis " pub" )
162
141
(defconst rust-re-unsafe " unsafe" )
163
142
(defconst rust-re-extern " extern" )
164
- (defconst rust-re-async-or-const " async\\ |const" )
165
143
(defconst rust-re-generic
166
144
(concat " <[[:space:]]*'" rust-re-ident " [[:space:]]*>" ))
167
145
(defconst rust-re-union
@@ -171,27 +149,27 @@ or if NODEFAULT is non-nil, then fall back to returning nil."
171
149
(group symbol-start " union" symbol-end)
172
150
(+ space) (regexp , rust-re-ident ))))
173
151
152
+ (defun rust-re-shy (inner ) (concat " \\ (?:" inner " \\ )" ))
153
+ (defun rust-re-grab (inner ) (concat " \\ (" inner " \\ )" ))
174
154
(defun rust-re-item-def (itype )
175
155
(concat (rust-re-word itype)
176
156
(rust-re-shy rust-re-generic) " ?"
177
157
" [[:space:]]+" (rust-re-grab rust-re-ident)))
158
+ (defun rust-re-word (inner ) (concat " \\ <" inner " \\ >" ))
178
159
179
- ; ; TODO some of this does only make sense for `fn' (unsafe, extern...)
180
- ; ; and not other items
181
160
(defun rust-re-item-def-imenu (itype )
182
161
(concat " ^[[:space:]]*"
183
- (rust-re-shy (concat rust-re-vis " [[:space:]]+" )) " ?"
162
+ (rust-re-shy (concat ( rust-re-word rust-re- vis) " [[:space:]]+" )) " ?"
184
163
(rust-re-shy (concat (rust-re-word " default" ) " [[:space:]]+" )) " ?"
185
- (rust-re-shy (concat (rust-re-shy rust-re-async-or-const) " [[:space:]]+" )) " ?"
186
164
(rust-re-shy (concat (rust-re-word rust-re-unsafe) " [[:space:]]+" )) " ?"
187
165
(rust-re-shy (concat (rust-re-word rust-re-extern) " [[:space:]]+"
188
- (rust-re-shy " \" [^\" ]+\" [[:space:]]+" ) " ?" )) " ?"
189
- (rust-re-item-def itype)))
166
+ (rust-re-shy " \" [^\" ]+\" [[:space:]]+" ) " ?" )) " ?"
167
+ (rust-re-item-def itype)))
190
168
191
169
(defvar rust-imenu-generic-expression
192
170
(append (mapcar #' (lambda (x )
193
171
(list (capitalize x) (rust-re-item-def-imenu x) 1 ))
194
- '(" enum" " struct" " union" " type" " mod" " fn" " trait" " impl" ))
172
+ '(" async fn " " enum" " struct" " union" " type" " mod" " fn" " trait" " impl" ))
195
173
`((" Macro" ,(rust-re-item-def-imenu " macro_rules!" ) 1 )))
196
174
" Value for `imenu-generic-expression' in Rust mode.
197
175
@@ -315,15 +293,10 @@ Use idomenu (imenu with `ido-mode') for best mileage.")
315
293
(setq auto-mode-alist (remove mode auto-mode-alist))))
316
294
317
295
(defvar rust-top-item-beg-re
318
- (concat " \\ s-*"
319
- ; ; TODO some of this does only make sense for `fn' (unsafe, extern...)
320
- ; ; and not other items
321
- (rust-re-shy (concat (rust-re-shy rust-re-vis) " [[:space:]]+" )) " ?"
322
- (rust-re-shy (concat (rust-re-shy rust-re-async-or-const) " [[:space:]]+" )) " ?"
323
- (rust-re-shy (concat (rust-re-shy rust-re-unsafe) " [[:space:]]+" )) " ?"
296
+ (concat " \\ s-*\\ (?:priv\\ |pub\\ )?\\ s-*"
324
297
(regexp-opt
325
298
'(" enum" " struct" " union" " type" " mod" " use" " fn" " static" " impl"
326
- " extern" " trait" ))
299
+ " extern" " trait" " async " ))
327
300
" \\ _>" )
328
301
" Start of a Rust item." )
329
302
@@ -337,7 +310,7 @@ Use idomenu (imenu with `ido-mode') for best mileage.")
337
310
" box" " break"
338
311
" const" " continue" " crate"
339
312
" do" " dyn"
340
- " else" " enum" " extern"
313
+ " else" " enum" " extern" " existential "
341
314
" false" " fn" " for"
342
315
" if" " impl" " in"
343
316
" let" " loop"
@@ -375,7 +348,7 @@ This is used by `rust-font-lock-keywords'.
375
348
\( `write!' is handled separately)." )
376
349
377
350
(defvar rust-formatting-macro-opening-re
378
- " [[:space:]\n ]*[({[][[:space:]\n ]*"
351
+ " [[:space:]]*[({[][[:space:]]*"
379
352
" Regular expression to match the opening delimiter of a Rust formatting macro." )
380
353
381
354
(defvar rust-start-of-string-re
@@ -421,19 +394,17 @@ Does not match type annotations of the form \"foo::<\"."
421
394
1 font-lock-preprocessor-face keep)
422
395
423
396
; ; Builtin formatting macros
424
- (,(concat (rust-re-grab
425
- (concat (rust-re-word (regexp-opt rust-builtin-formatting-macros))
426
- " !" ))
397
+ (,(concat (rust-re-grab (concat (regexp-opt rust-builtin-formatting-macros) " !" ))
427
398
rust-formatting-macro-opening-re
428
- " \\ (?: " rust-start-of-string-re " \\ )? " )
399
+ rust-start-of-string-re)
429
400
(1 'rust-builtin-formatting-macro )
430
401
(rust-string-interpolation-matcher
431
402
(rust-end-of-string)
432
403
nil
433
404
(0 'rust-string-interpolation t nil )))
434
405
435
406
; ; write! macro
436
- (,(concat (rust-re-grab ( concat (rust-re-word " write\\ (ln\\ )?" ) " ! " ) )
407
+ (,(concat (rust-re-grab " write\\ (ln\\ )?! " )
437
408
rust-formatting-macro-opening-re
438
409
" [[:space:]]*[^\" ]+,[[:space:]]*"
439
410
rust-start-of-string-re)
@@ -448,14 +419,13 @@ Does not match type annotations of the form \"foo::<\"."
448
419
1 font-lock-preprocessor-face )
449
420
450
421
; ; Field names like `foo:`, highlight excluding the :
451
- (,(concat (rust-re-grab rust-re-ident) " [[:space:]]*:[^:]" )
452
- 1 font-lock-variable-name-face )
422
+ (,(concat (rust-re-grab rust-re-ident) " :[^:]" ) 1 font-lock-variable-name-face )
453
423
454
424
; ; CamelCase Means Type Or Constructor
455
425
(, rust-re-type-or-constructor 1 font-lock-type-face )
456
426
457
427
; ; Type-inferred binding
458
- (,(concat " \\ _<\\ (?:let\\ s-+ref\\ |let\\ |ref\\ |for \\ )\\ s-+\\ (?:mut\\ s-+\\ )?"
428
+ (,(concat " \\ _<\\ (?:let\\ s-+ref\\ |let\\ |ref\\ )\\ s-+\\ (?:mut\\ s-+\\ )?"
459
429
(rust-re-grab rust-re-ident)
460
430
" \\ _>" )
461
431
1 font-lock-variable-name-face )
@@ -1033,21 +1003,23 @@ should be considered a paired angle bracket."
1033
1003
; ; as angle brackets it won't mess up any paren balancing.
1034
1004
((rust-in-macro) t )
1035
1005
1036
- ((= ( following-char ) ?< )
1006
+ ((looking-at " < " )
1037
1007
(rust-is-lt-char-operator))
1038
1008
1039
- ; ; Since rust-ordinary-lt-gt-p is called only when either < or > are at the point,
1040
- ; ; we know that the following char must be > in the clauses below.
1009
+ ((looking-at " >" )
1010
+ (cond
1011
+ ; ; Don't treat the > in -> or => as an angle bracket
1012
+ ((member (char-before (point )) '(?- ?= )) t )
1041
1013
1042
- ; ; If we are at top level and not in any list, it can't be a closing
1043
- ; ; angle bracket
1044
- ((>= 0 (rust-paren-level)) t )
1014
+ ; ; If we are at top level and not in any list, it can't be a closing
1015
+ ; ; angle bracket
1016
+ ((>= 0 (rust-paren-level)) t )
1045
1017
1046
- ; ; Otherwise, treat the > as a closing angle bracket if it would
1047
- ; ; match an opening one
1048
- ((save-excursion
1049
- (backward-up-list )
1050
- ( /= ( following-char ) ?< )))))
1018
+ ; ; Otherwise, treat the > as a closing angle bracket if it would
1019
+ ; ; match an opening one
1020
+ ((save-excursion
1021
+ (backward-up-list )
1022
+ ( not ( looking-at " < " ))) )))))
1051
1023
1052
1024
(defun rust-syntactic-face-function (state )
1053
1025
" Return face that distinguishes doc and normal comments in given syntax STATE."
0 commit comments