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

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

[nongnu] elpa/d-mode e42c1c1 340/346: Implement r"..." string literal sy


From: ELPA Syncer
Subject: [nongnu] elpa/d-mode e42c1c1 340/346: Implement r"..." string literal syntax
Date: Sun, 29 Aug 2021 11:00:56 -0400 (EDT)

branch: elpa/d-mode
commit e42c1c1f967cfe1b916d0a0f05cea2f8b7f29f09
Author: Vladimir Panteleev <git@thecybershadow.net>
Commit: Vladimir Panteleev <git@thecybershadow.net>

    Implement r"..." string literal syntax
    
    Use the existing `...` syntax logic for this syntax as well.
---
 d-mode.el | 49 ++++++++++++++++++++++++++++++-------------------
 1 file changed, 30 insertions(+), 19 deletions(-)

diff --git a/d-mode.el b/d-mode.el
index 404552a..9c5bf23 100644
--- a/d-mode.el
+++ b/d-mode.el
@@ -854,28 +854,39 @@ CONTEXT is as in `c-forward-decl-or-cast-1'."
 
 ;;----------------------------------------------------------------------------
 ;; Borrowed from 
https://github.com/josteink/csharp-mode/blob/master/csharp-mode.el
+
+(defmacro d--syntax-propertize-string (open close)
+  (unless (eq (length close) 1)
+    (error "`close' should be a single character"))
+  (let ((syntax-punctuation (string-to-syntax "."))
+       (skip-chars-pattern (concat "^" close "\\\\"))
+       (close-char (elt close 0)))
+    `(progn
+       (goto-char beg)
+       (while (search-forward ,open 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 ',skip-chars-pattern end)
+                (cond
+                 ((eq (following-char) ?\\)
+                   (put-text-property (point) (1+ (point))
+                                      'syntax-table ',syntax-punctuation)
+                   (forward-char 1))
+                 ((eq (following-char) ',close-char)
+                   (forward-char 1)
+                  (setq done t)))))))))))
+
 (defun d--syntax-propertize-function (beg end)
   "Apply syntax table properties to special constructs in region BEG to END.
-Currently handles `-delimited string literals."
+Handles `...` and r\"...\" WYSIWYG 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))))))))))
+    (d--syntax-propertize-string "`" "`")
+    (d--syntax-propertize-string "r\"" "\"")))
 
 ;;----------------------------------------------------------------------------
 



reply via email to

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