emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/rust-mode ec3855f 188/486: Recognize runaway raw strings


From: ELPA Syncer
Subject: [nongnu] elpa/rust-mode ec3855f 188/486: Recognize runaway raw strings
Date: Sat, 7 Aug 2021 09:25:16 -0400 (EDT)

branch: elpa/rust-mode
commit ec3855f1c6895eb12f140a84f9dd98392c4566a8
Author: Micah Chalmer <micah@micahchalmer.net>
Commit: Micah Chalmer <micah@micahchalmer.net>

    Recognize runaway raw strings
    
    Recognize raw strings all the way to the end of the buffer if they are
    not closed.  This is not valid rust code, but the highlighting should
    show the mistake.
    
    This also eliminates glitchy behavior that can occur in this situation.
    Emacs assumes that edits can't change syntax at positions before the
    edit, and raw strings without this change violated this.
---
 rust-mode-tests.el | 35 +++++++++++++++++++++++++++++++++++
 rust-mode.el       |  5 ++++-
 2 files changed, 39 insertions(+), 1 deletion(-)

diff --git a/rust-mode-tests.el b/rust-mode-tests.el
index 5312f38..8f25f06 100644
--- a/rust-mode-tests.el
+++ b/rust-mode-tests.el
@@ -1110,6 +1110,41 @@ this_is_not_a_string();)"
     (should (equal nil (get-text-property 28 'face))) ;; Semicolon--should not 
be part of the string
     ))
 
+(ert-deftest font-lock-runaway-raw-string ()
+  (rust-test-font-lock
+   "const Z = r#\"my raw string\";\n// oops this is still in the string"
+   '("const" font-lock-keyword-face
+     "Z" font-lock-type-face
+     "r#\"my raw string\";\n// oops this is still in the string" 
font-lock-string-face))
+  )
+
+(ert-deftest font-lock-recognize-closing-raw-string ()
+  (with-temp-buffer
+    (rust-mode)
+    (insert "const foo = r##\"
+1...............................................50
+1...............................................50
+1...............................................50
+1...............195-->\"; let ...................50
+1...............................................50
+1...............................................50
+1...............................................50
+1...............................................50
+1...............................................50
+1......................500......................50
+\"#;
+")
+    (font-lock-fontify-buffer)
+    (goto-char 530)
+    (insert "#")
+    ;; We have now closed the raw string.  Check that the whole string is
+    ;; recognized after the change
+    (font-lock-after-change-function (1- (point)) (point) 0)
+    (should (equal 'font-lock-string-face (get-text-property 195 'face))) ;; 
The "let"
+    (should (equal 'font-lock-string-face (get-text-property 500 'face))) ;; 
The "500"
+    (should (equal nil (get-text-property 531 'face))) ;; The second ";"
+    ))
+
 ;;; Documentation comments
 
 (ert-deftest font-lock-doc-line-comment-parent ()
diff --git a/rust-mode.el b/rust-mode.el
index 9e20aa2..9899ad1 100644
--- a/rust-mode.el
+++ b/rust-mode.el
@@ -531,7 +531,10 @@
 
       ;; No "#"s - capture the ending quote (using a backref to group 3,
       ;; so that we can't match a quote if we had "#"s) as group 6
-      (group (backref 3))))
+      (group (backref 3))
+
+      ;; If the raw string wasn't actually closed, go all the way to the end
+      string-end))
 
     ;; Character literal: match the beginning ' of a character literal
     ;; as group 7, and the ending one as group 8



reply via email to

[Prev in Thread] Current Thread [Next in Thread]