[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/rust-mode a653c6b 123/486: Highlight raw strings correctly
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/rust-mode a653c6b 123/486: Highlight raw strings correctly |
Date: |
Sat, 7 Aug 2021 09:25:02 -0400 (EDT) |
branch: elpa/rust-mode
commit a653c6b23138a264c6f263ae5ffc1b09888d3b88
Author: Micah Chalmer <micah@micahchalmer.net>
Commit: Micah Chalmer <micah@micahchalmer.net>
Highlight raw strings correctly
---
rust-mode-tests.el | 36 ++++++++++++++++++++++++++++++++++++
rust-mode.el | 24 ++++++++++++++++++------
2 files changed, 54 insertions(+), 6 deletions(-)
diff --git a/rust-mode-tests.el b/rust-mode-tests.el
index 36e59df..7cbfc3d 100644
--- a/rust-mode-tests.el
+++ b/rust-mode-tests.el
@@ -927,6 +927,42 @@ list of substrings of `STR' each followed by its face."
"let" font-lock-keyword-face
"'\\''" font-lock-string-face)))
+(ert-deftest font-lock-raw-strings-no-hashes ()
+ (rust-test-font-lock
+ "r\"No hashes\";"
+ '("r\"No hashes\"" font-lock-string-face)))
+
+(ert-deftest font-lock-raw-strings-double-quote ()
+ (rust-test-font-lock
+ "fn main() {
+ r#\"With a double quote (\")\"#;
+}
+"
+ '("fn" font-lock-keyword-face
+ "main" font-lock-function-name-face
+ "r#\"With a double quote (\")\"#" font-lock-string-face)))
+
+(ert-deftest font-lock-raw-strings-two-hashes ()
+ (rust-test-font-lock
+ "r##\"With two hashes\"##;"
+ '("r##\"With two hashes\"##" font-lock-string-face)))
+
+(ert-deftest font-lock-raw-strings-backslash-at-end ()
+ (rust-test-font-lock
+ "r\"With a backslash at the end\\\";"
+ '("r\"With a backslash at the end\\\"" font-lock-string-face)))
+
+(ert-deftest font-lock-two-raw-strings ()
+ (rust-test-font-lock
+ "fn main() {
+ r\"With a backslash at the end\\\";
+ r##\"With two hashes\"##;
+}"
+ '("fn" font-lock-keyword-face
+ "main" font-lock-function-name-face
+ "r\"With a backslash at the end\\\"" font-lock-string-face
+ "r##\"With two hashes\"##" font-lock-string-face)))
+
(ert-deftest indent-method-chains-no-align ()
(let ((rust-indent-method-chain nil)) (test-indent
"
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."
- [nongnu] elpa/rust-mode 76bcb8d 074/486: etc: attempts at fixing editor highlighting for new attribute syntax, (continued)
- [nongnu] elpa/rust-mode 76bcb8d 074/486: etc: attempts at fixing editor highlighting for new attribute syntax, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode a59ef8e 090/486: Fix spelling mistakes in comments., ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 9c0846a 101/486: Add test for '\'' single quote char literal, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 55080f6 100/486: Fix syntax and highlighting for char literals, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 8a69f69 104/486: Use old code style for emacs 23 compat, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 9e83b30 110/486: Merge pull request #21 from pnkfelix/tests-allow-override-of-which-emacs, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 55e7483 113/486: Add a hook so that we briefly highlight the matching `<` when `>` is typed., ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 439da40 115/486: disable emacs23 testing on travis., ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode d2c6d6c 116/486: Merge pull request #26 from pnkfelix/disable-emacs23-testing, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 8c9ea88 127/486: Fix raw string bugs, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode a653c6b 123/486: Highlight raw strings correctly,
ELPA Syncer <=
- [nongnu] elpa/rust-mode f3e8f20 119/486: Re-enable emacs23 in Travis, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 5b73df1 133/486: Fix typo/missing lines in comment in test, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 3a0a727 129/486: Merge pull request #35 from MicahChalmer/fix-raw-string-bugs, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode c7413e6 130/486: Don't set syntax-begin-function, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode b15b0eb 140/486: Merge pull request #45 from MicahChalmer/backslash-and-double-quote-char-literals, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 52febe9 137/486: Add a few more tests for indents inside strings, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 766bd82 139/486: Parse '\\' and '\"' as char literals, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode d6b1739 136/486: Fix spurious errors in emacs 23, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 3995d33 152/486: Add regression test for PR #52., ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode f2d709e 141/486: Make fill-region work correctly, ELPA Syncer, 2021/08/07