branch: elpa/d-mode
commit 1ec588075f5c2b5181257591ebc7ce33fa875e8e
Author: Vladimir Panteleev <[email protected]>
Commit: Vladimir Panteleev <[email protected]>

    Fix another bug related to `-delimited strings
    
    Borrow the solution csharp-mode uses for verbatim string literals.
    
    Fixes #90.
---
 d-mode-test.el     |  1 +
 d-mode.el          | 41 ++++++++++++++++++++++++++---------------
 tests/I0090.d      |  6 ++++++
 tests/I0090.d.html |  6 ++++++
 4 files changed, 39 insertions(+), 15 deletions(-)

diff --git a/d-mode-test.el b/d-mode-test.el
index 6fddc64..a000689 100644
--- a/d-mode-test.el
+++ b/d-mode-test.el
@@ -312,6 +312,7 @@ is expected to succeed, and nil otherwise."
 (d-test-deftest i0064 "tests/I0064.d" t)
 (d-test-deftest i0069 "tests/I0069.txt" t)
 (d-test-deftest i0072 "tests/I0072.txt" t)
+(d-test-deftest i0090 "tests/I0090.d" t)
 
 ;;----------------------------------------------------------------------------
 
diff --git a/d-mode.el b/d-mode.el
index d439dd4..43d4356 100644
--- a/d-mode.el
+++ b/d-mode.el
@@ -7,7 +7,7 @@
 ;; Maintainer:  Russel Winder <[email protected]>
 ;;              Vladimir Panteleev <[email protected]>
 ;; Created:  March 2007
-;; Version:  201908262342
+;; Version:  201908270011
 ;; Keywords:  D programming language emacs cc-mode
 ;; Package-Requires: ((emacs "24.3"))
 
@@ -781,6 +781,30 @@ Each list item should be a regexp matching a single 
identifier."
 (when (version<= "24.4" emacs-version)
   (advice-add 'c-add-stmt-syntax :around #'d-around--c-add-stmt-syntax))
 
+;; Borrowed from 
https://github.com/josteink/csharp-mode/blob/master/csharp-mode.el
+(defun d--syntax-propertize-function (beg end)
+  "Apply syntax table properties to special constructs in region BEG to END.
+Currently handles `-delimited string literals."
+  (save-excursion
+    (goto-char beg)
+    (while (search-forward "`" end t)
+      (let ((in-comment-or-string-p (save-excursion
+                                      (goto-char (match-beginning 0))
+                                      (or (nth 3 (syntax-ppss))
+                                          (nth 4 (syntax-ppss))))))
+        (when (not in-comment-or-string-p)
+          (let (done)
+            (while (and (not done) (< (point) end))
+              (skip-chars-forward "^`\\\\" end)
+              (cond
+               ((= (following-char) ?\\)
+                (put-text-property (point) (1+ (point))
+                                   'syntax-table (string-to-syntax "."))
+                (forward-char 1))
+               ((= (following-char) ?\`)
+                (forward-char 1)
+               (setq done t))))))))))
+
 ;;----------------------------------------------------------------------------
 ;;;###autoload
 (add-to-list 'auto-mode-alist '("\\.d[i]?\\'" . d-mode))
@@ -818,20 +842,7 @@ Key bindings:
   (when (version<= "24.3" emacs-version)
     (setq-local
      syntax-propertize-function
-     (syntax-propertize-rules
-      ((rx
-       "`"
-       (minimal-match
-        (zero-or-more
-         (not (any "`\\"))))
-       (minimal-match
-        (zero-or-more
-         (submatch "\\")
-         (minimal-match
-          (zero-or-more
-           (not (any "`\\"))))))
-       "`")
-       (1 ".")))))
+     #'d--syntax-propertize-function))
 
   (c-common-init 'd-mode)
   (easy-menu-add d-menu)
diff --git a/tests/I0090.d b/tests/I0090.d
new file mode 100644
index 0000000..86fa9f6
--- /dev/null
+++ b/tests/I0090.d
@@ -0,0 +1,6 @@
+// #run: (d-test-fontification)
+
+void main()
+{
+       auto err = "`\"`"; // This is a comment
+}
diff --git a/tests/I0090.d.html b/tests/I0090.d.html
new file mode 100644
index 0000000..69382fa
--- /dev/null
+++ b/tests/I0090.d.html
@@ -0,0 +1,6 @@
+<span class="comment-delimiter">// </span><span class="comment">#run: 
(d-test-fontification)
+</span>
+<span class="type">void</span> <span class="function-name">main</span>()
+{
+       <span class="keyword">auto</span> <span 
class="variable-name">err</span> = <span 
class="string">&quot;`\&quot;`&quot;</span>; <span class="comment-delimiter">// 
</span><span class="comment">This is a comment
+</span>}

Reply via email to