[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/julia-mode 796ddfd 338/352: Apply proper syntax to triple-
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/julia-mode 796ddfd 338/352: Apply proper syntax to triple-quoted cmds |
Date: |
Sun, 29 Aug 2021 11:23:14 -0400 (EDT) |
branch: elpa/julia-mode
commit 796ddfd03454fbe5e8fb8abe1ffce2b5d29c9b8e
Author: Adam Beckmeyer <adam_gpg@thebeckmeyers.xyz>
Commit: Adam Beckmeyer <adam_gpg@thebeckmeyers.xyz>
Apply proper syntax to triple-quoted cmds
Previously they were being syntax-propertized as 3 single-quoted
cmds.
---
julia-mode-tests.el | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
julia-mode.el | 37 +++++++++++++++++++++++++++++--------
2 files changed, 78 insertions(+), 8 deletions(-)
diff --git a/julia-mode-tests.el b/julia-mode-tests.el
index bafff50..89d1b26 100644
--- a/julia-mode-tests.el
+++ b/julia-mode-tests.el
@@ -532,6 +532,47 @@ end")
(julia--should-font-lock string 74 font-lock-type-face) ; B
))
+(ert-deftest julia--test-triple-quote-string-font-lock ()
+ "Test that triple quoted strings are font-locked correctly even with
escapes."
+ (let ((s1 "\"\"\"a\\\"\\\"\"b\"\"\"d")
+ (s2 "\"\"\"a\\\"\"\"b\"\"\"d")
+ (s3 "\"\"\"a```b\"\"\"d")
+ (s4 "\\\"\"\"a\\\"\"\"b\"\"\"d")
+ (s5 "\"\"\"a\\\"\"\"\"b"))
+ (julia--should-font-lock s1 4 font-lock-string-face)
+ (julia--should-font-lock s1 10 font-lock-string-face)
+ (julia--should-font-lock s1 14 nil)
+ (julia--should-font-lock s2 4 font-lock-string-face)
+ (julia--should-font-lock s2 9 font-lock-string-face)
+ (julia--should-font-lock s2 13 nil)
+ (julia--should-font-lock s3 4 font-lock-string-face)
+ (julia--should-font-lock s3 8 font-lock-string-face)
+ (julia--should-font-lock s3 12 nil)
+ (julia--should-font-lock s4 5 font-lock-string-face)
+ (julia--should-font-lock s4 10 font-lock-string-face)
+ (julia--should-font-lock s4 14 nil)
+ (julia--should-font-lock s5 4 font-lock-string-face)
+ (julia--should-font-lock s5 10 nil)))
+
+(ert-deftest julia--test-triple-quote-cmd-font-lock ()
+ "Test that triple-quoted cmds are font-locked correctly even with escapes."
+ (let ((s1 "```a\\`\\``b```d")
+ (s2 "```a\\```b```d")
+ (s3 "```a\"\"\"b```d")
+ (s4 "\\```a\\```b```d"))
+ (julia--should-font-lock s1 4 font-lock-string-face)
+ (julia--should-font-lock s1 10 font-lock-string-face)
+ (julia--should-font-lock s1 14 nil)
+ (julia--should-font-lock s2 4 font-lock-string-face)
+ (julia--should-font-lock s2 9 font-lock-string-face)
+ (julia--should-font-lock s2 13 nil)
+ (julia--should-font-lock s3 4 font-lock-string-face)
+ (julia--should-font-lock s3 8 font-lock-string-face)
+ (julia--should-font-lock s3 12 nil)
+ (julia--should-font-lock s4 5 font-lock-string-face)
+ (julia--should-font-lock s4 10 font-lock-string-face)
+ (julia--should-font-lock s4 14 nil)))
+
;;; Movement
(ert-deftest julia--test-beginning-of-defun-assn-1 ()
"Point moves to beginning of single-line assignment function."
@@ -697,6 +738,14 @@ hello world
;; instead of 1.
(should (= 1 (nth 8 (syntax-ppss 5))))))
+(ert-deftest julia--test-triple-quoted-cmd-syntax ()
+ (with-temp-buffer
+ (julia-mode)
+ (insert "```
+hello world
+```")
+ (should (= 1 (nth 8 (syntax-ppss 5))))))
+
(ert-deftest julia--test-backslash-syntax ()
(with-temp-buffer
(julia-mode)
diff --git a/julia-mode.el b/julia-mode.el
index 84fb115..3cdc217 100644
--- a/julia-mode.el
+++ b/julia-mode.el
@@ -303,14 +303,11 @@
(defconst julia-syntax-propertize-function
(syntax-propertize-rules
;; triple-quoted strings are a single string rather than 3
- ((rx (group ?\") ?\" (group ?\"))
- ;; First " starts a string if not already inside a string (or comment)
- (1 (let ((ppss (save-excursion (syntax-ppss (match-beginning 0)))))
- (unless (or (nth 3 ppss) (nth 4 ppss))
- (string-to-syntax "|"))))
- ;; Last " ends a string if already inside a string
- (2 (and (nth 3 (save-excursion (syntax-ppss (match-beginning 0))))
- (string-to-syntax "|"))))
+ ("\"\"\""
+ (0 (ignore (julia-syntax-stringify))))
+ ;; same with triple-quoted backticks
+ ("```"
+ (0 (ignore (julia-syntax-stringify))))
;; backslash acts as an operator if it's not inside a string
("\\\\"
(0 (unless (nth 3 (save-excursion (syntax-ppss (match-beginning 0))))
@@ -320,6 +317,30 @@
(1 "\"")
(2 "\""))))
+(defun julia-syntax-stringify ()
+ "Put `syntax-table' property correctly on triple-quoted strings and cmds."
+ (let* ((ppss (save-excursion (syntax-ppss (match-beginning 0))))
+ (string-open (and (not (nth 4 ppss)) (nth 8 ppss))))
+ (cond
+ ;; this set of quotes delimit the start of string/cmd
+ ((not string-open)
+ (put-text-property (match-beginning 0) (1+ (match-beginning 0))
+ 'syntax-table (string-to-syntax "|")))
+ ;; this set of quotes closes the current string/cmd
+ ((and
+ ;; check that """ closes """ and ``` closes ```
+ (eq (char-before) (char-after string-open))
+ ;; check that triple quote isn't escaped by odd number of backslashes
+ (let ((i 0))
+ (while (and (< (point-min) (- (match-beginning 0) i))
+ (eq (char-before (- (match-beginning 0) i)) ?\\))
+ (setq i (1+ i)))
+ (cl-evenp i)))
+ (put-text-property (1- (match-end 0)) (match-end 0)
+ 'syntax-table (string-to-syntax "|")))
+ ;; Put point after (match-beginning 0) to account for possibility
+ ;; of overlapping triple-quotes with first escaped
+ ((backward-char 2)))))
(defun julia-in-comment (&optional syntax-ppss)
"Return non-nil if point is inside a comment using SYNTAX-PPSS.
- [nongnu] elpa/julia-mode 2ef6992 278/352: Fixed import export etc indentation at start of buffer. (#47), (continued)
- [nongnu] elpa/julia-mode 2ef6992 278/352: Fixed import export etc indentation at start of buffer. (#47), ELPA Syncer, 2021/08/29
- [nongnu] elpa/julia-mode 117b791 294/352: Replace `Associative` by `AbstractDict` (thanks to @tpapp), ELPA Syncer, 2021/08/29
- [nongnu] elpa/julia-mode dc21978 289/352: Merge pull request #63 from nverno/movement-functions, ELPA Syncer, 2021/08/29
- [nongnu] elpa/julia-mode 61e22f6 312/352: Merge pull request #90 from tpapp/tp/add-melpa-badge, ELPA Syncer, 2021/08/29
- [nongnu] elpa/julia-mode a174d0e 315/352: Fix indentation of generated elisp, ELPA Syncer, 2021/08/29
- [nongnu] elpa/julia-mode 97325c4 318/352: Merge pull request #87 from tpapp/tp/drop-emacs-23, ELPA Syncer, 2021/08/29
- [nongnu] elpa/julia-mode 0eec10a 333/352: Do not consider `:end` as block ending, ELPA Syncer, 2021/08/29
- [nongnu] elpa/julia-mode c9d8230 329/352: Give \ punctuation syntax outside of strings (#113), ELPA Syncer, 2021/08/29
- [nongnu] elpa/julia-mode 6b7e956 321/352: Fix for derived parent mode (#66), ELPA Syncer, 2021/08/29
- [nongnu] elpa/julia-mode 9dcabbc 334/352: Simplify the logic to find the end of last block, ELPA Syncer, 2021/08/29
- [nongnu] elpa/julia-mode 796ddfd 338/352: Apply proper syntax to triple-quoted cmds,
ELPA Syncer <=
- [nongnu] elpa/julia-mode 505d71b 339/352: Add all problemmatic strings from issue #15 to tests, ELPA Syncer, 2021/08/29
- [nongnu] elpa/julia-mode b800403 326/352: Font lock tweaks (#102), ELPA Syncer, 2021/08/29
- [nongnu] elpa/julia-mode 8bfc709 325/352: bump version for release, ELPA Syncer, 2021/08/29
- [nongnu] elpa/julia-mode a31868d 340/352: font-lock ccall as a builtin, ELPA Syncer, 2021/08/29
- [nongnu] elpa/julia-mode a4eeb6c 343/352: Merge pull request #134 from non-Jedi/font-lock-builtin-face, ELPA Syncer, 2021/08/29
- [nongnu] elpa/julia-mode a1ba9a0 352/352: add logo, README tweaks, add section on testing (#163), ELPA Syncer, 2021/08/29
- [nongnu] elpa/julia-mode dc17943 351/352: Indent imports from submodule correctly (#154), ELPA Syncer, 2021/08/29
- [nongnu] elpa/julia-mode af5eb63 273/352: short function syntax: support return type declaration, ELPA Syncer, 2021/08/29
- [nongnu] elpa/julia-mode 1eacdc6 298/352: Create FUNDING.yml, ELPA Syncer, 2021/08/29
- [nongnu] elpa/julia-mode 023df24 322/352: add latest PR to changelog, ELPA Syncer, 2021/08/29