[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/julia-mode b295e36 345/352: Merge pull request #133 from n
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/julia-mode b295e36 345/352: Merge pull request #133 from non-Jedi/triple-quote-cmd |
Date: |
Sun, 29 Aug 2021 11:23:15 -0400 (EDT) |
branch: elpa/julia-mode
commit b295e36721718ceef309d9eaaf968925b31d7045
Merge: a4eeb6c 13a3c53
Author: Tamas K. Papp <tkpapp@gmail.com>
Commit: GitHub <noreply@github.com>
Merge pull request #133 from non-Jedi/triple-quote-cmd
Apply proper syntax to triple-quoted cmds
---
julia-mode-tests.el | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++
julia-mode.el | 49 +++++++++++++++++++++++++++++++-------------
2 files changed, 93 insertions(+), 14 deletions(-)
diff --git a/julia-mode-tests.el b/julia-mode-tests.el
index 8aa8355..94d46bb 100644
--- a/julia-mode-tests.el
+++ b/julia-mode-tests.el
@@ -532,6 +532,56 @@ end")
(julia--should-font-lock string 74 font-lock-type-face) ; B
))
+(ert-deftest julia--test-single-quote-string-font-lock ()
+ "Test that single quoted strings are font-locked correctly even with
escapes."
+ ;; Issue #15
+ (let ((s1 "\"a\\\"b\"c"))
+ (julia--should-font-lock s1 2 font-lock-string-face)
+ (julia--should-font-lock s1 5 font-lock-string-face)
+ (julia--should-font-lock s1 7 nil)))
+
+(ert-deftest julia--test-triple-quote-string-font-lock ()
+ "Test that triple quoted strings are font-locked correctly even with
escapes."
+ ;; Issue #15
+ (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)))
+
(ert-deftest julia--test-ccall-font-lock ()
(let ((s1 "t = ccall(:clock, Int32, ())"))
(julia--should-font-lock s1 5 font-lock-builtin-face)
@@ -703,6 +753,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 155df80..dedf966 100644
--- a/julia-mode.el
+++ b/julia-mode.el
@@ -113,9 +113,8 @@
(syntax whitespace)
bol)
(group "'")
- (group
- (or (repeat 0 8 (not (any "'"))) (not (any "\\"))
- "\\\\"))
+ (or (repeat 0 8 (not (any "'"))) (not (any "\\"))
+ "\\\\")
(group "'"))))
(defconst julia-hanging-operator-regexp
@@ -306,22 +305,44 @@
(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))))
(string-to-syntax "."))))
(julia-char-regex
- (1 "\"") ; Treat ' as a string delimiter.
- (2 ".") ; Don't highlight anything between.
- (3 "\"")))) ; Treat the last " in """ as a string delimiter.
+ ;; treat ' in 'c' as string-delimiter
+ (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 af5eb63 273/352: short function syntax: support return type declaration, (continued)
- [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
- [nongnu] elpa/julia-mode 140369e 337/352: Simplify char-regex, ELPA Syncer, 2021/08/29
- [nongnu] elpa/julia-mode 10b0eff 286/352: beginning/end of defun functions, ELPA Syncer, 2021/08/29
- [nongnu] elpa/julia-mode 6408b96 306/352: Transition to cl-lib, drop support for Emacs 23., ELPA Syncer, 2021/08/29
- [nongnu] elpa/julia-mode 4f024cb 313/352: make loading "julia-latexsubs" work when using `eval-buffer` (#83), ELPA Syncer, 2021/08/29
- [nongnu] elpa/julia-mode 10ce821 310/352: Add MELPA badge, clarify installation., ELPA Syncer, 2021/08/29
- [nongnu] elpa/julia-mode 088fb0b 314/352: Load latexsub table as a feature, ELPA Syncer, 2021/08/29
- [nongnu] elpa/julia-mode 66ef2db 317/352: Merge branch 'master' into tp/drop-emacs-23, ELPA Syncer, 2021/08/29
- [nongnu] elpa/julia-mode b295e36 345/352: Merge pull request #133 from non-Jedi/triple-quote-cmd,
ELPA Syncer <=
- [nongnu] elpa/julia-mode e10a730 056/352: FFT of real vectors as well, ELPA Syncer, 2021/08/29
- [nongnu] elpa/julia-mode 7065601 138/352: julia-mode symbol-table update from #7018, ELPA Syncer, 2021/08/29
- [nongnu] elpa/julia-mode 5d693ab 349/352: Fix CI using actions. (#160), ELPA Syncer, 2021/08/29
- [nongnu] elpa/julia-mode 307b42b 189/352: If the previous line has a trailing =, that should take precedence over blocks., ELPA Syncer, 2021/08/29
- [nongnu] elpa/julia-mode c4a75b4 271/352: update short function syntax w.r.t. spaces, ELPA Syncer, 2021/08/29
- [nongnu] elpa/julia-mode 9d08954 292/352: Update keywords and builtin types to Julia 1.0, ELPA Syncer, 2021/08/29
- [nongnu] elpa/julia-mode 9edff28 291/352: Merge pull request #68 from nverno/fix-compilation, ELPA Syncer, 2021/08/29
- [nongnu] elpa/julia-mode 999569b 297/352: Update substitutions to include emoji, ELPA Syncer, 2021/08/29
- [nongnu] elpa/julia-mode 3adce47 296/352: highlight ∈ in `for var ∈ …` ( fix #71 ), ELPA Syncer, 2021/08/29
- [nongnu] elpa/julia-mode 181c919 040/352: adding a full interface to select and FD sets, ELPA Syncer, 2021/08/29