summaryrefslogtreecommitdiff
path: root/rust-mode.el
diff options
context:
space:
mode:
authorNiko Matsakis <niko@alum.mit.edu>2015-02-08 06:59:00 -0500
committerNiko Matsakis <niko@alum.mit.edu>2015-02-08 06:59:00 -0500
commit4d633fc20de2560f26bcaca95b5458dfa2efb6eb (patch)
treef1dbc4216aa9773790464af56a8bcb3f600703dd /rust-mode.el
parent19bc0e9ef1dd72bfde10644037a13719a38777fc (diff)
parentbddc933d1eb56254c68618abc3e5ca462572beab (diff)
downloadrust-mode-4d633fc20de2560f26bcaca95b5458dfa2efb6eb.tar.gz
Merge pull request #32 from MicahChalmer/raw-string-handling
Parse and highlight raw strings correctly
Diffstat (limited to 'rust-mode.el')
-rw-r--r--rust-mode.el24
1 files changed, 18 insertions, 6 deletions
diff --git a/rust-mode.el b/rust-mode.el
index 43afd9a..fe9660b 100644
--- a/rust-mode.el
+++ b/rust-mode.el
@@ -51,6 +51,13 @@
table))
+(defvar rust-mode-inside-raw-string-syntax-table
+ (let ((table (make-syntax-table rust-mode-syntax-table)))
+ (modify-syntax-entry ?\" "_" table)
+ (modify-syntax-entry ?\\ "_" table)
+
+ table))
+
(defgroup rust-mode nil
"Support for Rust code."
:link '(url-link "http://www.rust-lang.org/")
@@ -312,12 +319,17 @@
("static" . font-lock-constant-face)))))
(defvar rust-mode-font-lock-syntactic-keywords
- (mapcar (lambda (re) (list re '(1 "\"") '(2 "\"")))
- '("\\('\\)[^']\\('\\)"
- "\\('\\)\\\\['nrt]\\('\\)"
- "\\('\\)\\\\x[[:xdigit:]]\\{2\\}\\('\\)"
- "\\('\\)\\\\u[[:xdigit:]]\\{4\\}\\('\\)"
- "\\('\\)\\\\U[[:xdigit:]]\\{8\\}\\('\\)")))
+ (append
+ ;; Handle single quoted character literals:
+ (mapcar (lambda (re) (list re '(1 "\"") '(2 "\"")))
+ '("\\('\\)[^']\\('\\)"
+ "\\('\\)\\\\['nrt]\\('\\)"
+ "\\('\\)\\\\x[[:xdigit:]]\\{2\\}\\('\\)"
+ "\\('\\)\\\\u[[:xdigit:]]\\{4\\}\\('\\)"
+ "\\('\\)\\\\U[[:xdigit:]]\\{8\\}\\('\\)"))
+ ;; Handle raw strings:
+ `(("\\(r\\)\"\\([^\"]*\\)\\(\"\\)" (1 "|") (2 ,rust-mode-inside-raw-string-syntax-table) (3 "|"))
+ ("\\(r\\)#\\(#*\\)\\(\"[^#]*\"\\2\\)\\(#\\)" (1 "|") (3 ,rust-mode-inside-raw-string-syntax-table) (4 "|")))))
(defun rust-fill-prefix-for-comment-start (line-start)
"Determine what to use for `fill-prefix' based on what is at the beginning of a line."