[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/d-mode b90a717 342/346: Merge pull request #106 from Cyber
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/d-mode b90a717 342/346: Merge pull request #106 from CyberShadow/pull-20210119-160250 |
Date: |
Sun, 29 Aug 2021 11:00:56 -0400 (EDT) |
branch: elpa/d-mode
commit b90a717868aef00beb51dca01b382b5faf0f9a9f
Merge: 32446a7 505022e
Author: Vladimir Panteleev <CyberShadow@users.noreply.github.com>
Commit: GitHub <noreply@github.com>
Merge pull request #106 from CyberShadow/pull-20210119-160250
Implement r"..." string literal syntax
---
d-mode.el | 65 ++++++++++++++++++++++++++++++++----------------------
tests/I0105.d | 14 ++++++++++++
tests/I0105.d.html | 14 ++++++++++++
3 files changed, 67 insertions(+), 26 deletions(-)
diff --git a/d-mode.el b/d-mode.el
index e97ff69..9c5bf23 100644
--- a/d-mode.el
+++ b/d-mode.el
@@ -836,13 +836,15 @@ CONTEXT is as in `c-forward-decl-or-cast-1'."
((looking-at (d-make-keywords-re t '("catch")))
(setq type 'decl)
t))))
- (progn
- (c-forward-sexp)
- (c-forward-syntactic-ws)
- (while (d-forward-attribute-or-storage-class 'top))
- (or
- (eq (char-after) ?\{)
- (looking-at "=>"))))))))
+ (condition-case nil
+ (progn
+ (c-forward-sexp)
+ (c-forward-syntactic-ws)
+ (while (d-forward-attribute-or-storage-class 'top))
+ (or
+ (eq (char-after) ?\{)
+ (looking-at "=>")))
+ (error nil)))))))
(setq res (cons type t))
;; (message " patching -> %S" res)
@@ -852,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\"" "\"")))
;;----------------------------------------------------------------------------
diff --git a/tests/I0105.d b/tests/I0105.d
new file mode 100644
index 0000000..4309d91
--- /dev/null
+++ b/tests/I0105.d
@@ -0,0 +1,14 @@
+// #run: (d-test-fontification)
+
+unittest
+{
+ assert(absolute("/"[]) == true);
+ assert(absolute(""[]) == false);
+
+ version (Windows)
+ {
+ assert(absolute(r"\"[]) == true);
+ assert(absolute(r"\\"[]) == true);
+ assert(absolute(r"c:"[]) == true);
+ }
+}
diff --git a/tests/I0105.d.html b/tests/I0105.d.html
new file mode 100644
index 0000000..79baaa7
--- /dev/null
+++ b/tests/I0105.d.html
@@ -0,0 +1,14 @@
+<span class="comment-delimiter">// </span><span class="comment">#run:
(d-test-fontification)
+</span>
+<span class="keyword">unittest</span>
+{
+ <span class="keyword">assert</span>(absolute(<span
class="string">"/"</span>[]) == <span class="constant">true</span>);
+ <span class="keyword">assert</span>(absolute(<span
class="string">""</span>[]) == <span class="constant">false</span>);
+
+ <span class="keyword">version</span> (<span
class="constant">Windows</span>)
+ {
+ <span class="keyword">assert</span>(absolute(r<span
class="string">"\"</span>[]) == <span class="constant">true</span>);
+ <span class="keyword">assert</span>(absolute(r<span
class="string">"\\"</span>[]) == <span class="constant">true</span>);
+ <span class="keyword">assert</span>(absolute(r<span
class="string">"c:"</span>[]) == <span class="constant">true</span>);
+ }
+}
- [nongnu] elpa/d-mode 5190c1d 323/346: Fix fontification of parameters of lambdas inside expressions, (continued)
- [nongnu] elpa/d-mode 5190c1d 323/346: Fix fontification of parameters of lambdas inside expressions, ELPA Syncer, 2021/08/29
- [nongnu] elpa/d-mode bc4864d 325/346: d-mode.el: Remove c-font-lock-declarations advice, ELPA Syncer, 2021/08/29
- [nongnu] elpa/d-mode a233437 329/346: Add "version" to c-block-stmt-2-kwds, ELPA Syncer, 2021/08/29
- [nongnu] elpa/d-mode 5da089b 332/346: tests: Replace #min-version with a more generic #condition, ELPA Syncer, 2021/08/29
- [nongnu] elpa/d-mode 9f6a2b6 339/346: Handle c-forward-sexp error in d-around--c-get-fontification-context, ELPA Syncer, 2021/08/29
- [nongnu] elpa/d-mode 54aca49 333/346: tests/I0021: Disable on Emacs >=27 for now, ELPA Syncer, 2021/08/29
- [nongnu] elpa/d-mode 84bf8ab 262/346: Fix fontification of single-character package names, ELPA Syncer, 2021/08/29
- [nongnu] elpa/d-mode 546cc28 230/346: Fix parsing of block-less conditional declarations, ELPA Syncer, 2021/08/29
- [nongnu] elpa/d-mode 447515f 327/346: Merge pull request #93 from CyberShadow/next, ELPA Syncer, 2021/08/29
- [nongnu] elpa/d-mode 75cc636 334/346: tests/fonts_auto: Remove final */, ELPA Syncer, 2021/08/29
- [nongnu] elpa/d-mode b90a717 342/346: Merge pull request #106 from CyberShadow/pull-20210119-160250,
ELPA Syncer <=