[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/julia-mode c9d8230 329/352: Give \ punctuation syntax outs
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/julia-mode c9d8230 329/352: Give \ punctuation syntax outside of strings (#113) |
Date: |
Sun, 29 Aug 2021 11:23:12 -0400 (EDT) |
branch: elpa/julia-mode
commit c9d8230b1ff73f663d975e83a5cf5acdcc3b6255
Author: Adam B <adam_gpg@thebeckmeyers.xyz>
Commit: GitHub <noreply@github.com>
Give \ punctuation syntax outside of strings (#113)
Give `\` punctuation syntax outside of strings
Fixes #58
Fixes #59
This commit also fixes a broken test for backslash indentation by
properly escaping backslashes in elisp strings and cleans up the code
for syntax-propertizing triple-quoted strings as a single string
rather than 3 strings.
Add comments to explain triple-quoted-string logic, tests for syntax-table
property.
---
julia-mode-tests.el | 43 ++++++++++++++++++++++++++++++++++++++-----
julia-mode.el | 53 ++++++++++++++++-------------------------------------
2 files changed, 54 insertions(+), 42 deletions(-)
diff --git a/julia-mode-tests.el b/julia-mode-tests.el
index 53a5f4f..8ca4299 100644
--- a/julia-mode-tests.el
+++ b/julia-mode-tests.el
@@ -262,7 +262,14 @@ qux"
foo() |>
bar |>
baz
-qux"))
+qux")
+ (julia--should-indent
+ "x \\
+y \\
+z"
+ "x \\
+ y \\
+ z"))
(ert-deftest julia--test-indent-ignores-blank-lines ()
"Blank lines should not affect indentation of non-blank lines."
@@ -396,13 +403,13 @@ end"))
(ert-deftest julia--test-backslash-indent ()
"indentation for function(args...)"
(julia--should-indent
- "(\)
+ "(\\)
1
- (:\)
+ (:\\)
1"
- "(\)
+ "(\\)
1
-(:\)
+(:\\)
1"))
(ert-deftest julia--test-indent-keyword-paren ()
@@ -658,6 +665,32 @@ end" 'end-of-defun "n == 0" "return fact(x)[ \n]+end" 'end
2))
; (should (equal (julia--substitute "\\alpha" 6) "α")) ; BROKEN
)
+;;; syntax-propertize-function tests
+
+(ert-deftest julia--test-triple-quoted-string-syntax ()
+ (with-temp-buffer
+ (julia-mode)
+ (insert "\"\"\"
+hello world
+\"\"\"")
+ ;; If triple-quoted strings improperly syntax-propertized as 3
+ ;; single-quoted strings, this will show string starting at pos 3
+ ;; instead of 1.
+ (should (= 1 (nth 8 (syntax-ppss 5))))))
+
+(ert-deftest julia--test-backslash-syntax ()
+ (with-temp-buffer
+ (julia-mode)
+ (insert "1 \\ 2
+\"hello\\nthere\"")
+ (syntax-propertize 20)
+ (should (equal
+ (string-to-syntax ".")
+ (syntax-after 3)))
+ (should (equal
+ (string-to-syntax "\\")
+ (syntax-after 13)))))
+
;;;
;;; run all tests
;;;
diff --git a/julia-mode.el b/julia-mode.el
index fb030ee..c14f341 100644
--- a/julia-mode.el
+++ b/julia-mode.el
@@ -85,6 +85,9 @@
(modify-syntax-entry ?' "." table)
(modify-syntax-entry ?\" "\"" table)
(modify-syntax-entry ?` "\"" table)
+ ;; Backslash has escape syntax for use in strings but
+ ;; julia-syntax-propertize-function sets punctuation syntax on it
+ ;; outside strings.
(modify-syntax-entry ?\\ "\\" table)
(modify-syntax-entry ?. "." table)
@@ -180,18 +183,6 @@
"::" "."))
(regexp-opt '(" #" " \n" "#" "\n"))))
-(defconst julia-triple-quoted-string-regex
- ;; We deliberately put a group on the first and last delimiter, so
- ;; we can mark these as string delimiters for font-lock.
- (rx (group "\"")
- (group "\"\""
- ;; After the delimiter, we're a sequence of
- ;; non-backslashes or blackslashes paired with something.
- (*? (or (not (any "\\"))
- (seq "\\" anything)))
- "\"\"")
- (group "\"")))
-
(defconst julia-unquote-regex
"\\(\\s(\\|\\s-\\|-\\|[,%=<>\\+*/?&|!\\^~\\\\;:]\\|^\\)\\($[a-zA-Z0-9_]+\\)")
@@ -313,33 +304,21 @@
(defconst julia-block-end-keywords
(list "end" "else" "elseif" "catch" "finally"))
-(defun julia-stringify-triple-quote ()
- "Put `syntax-table' property on triple-quoted string delimiters.
-
-Based on `python-syntax-stringify'."
- (let* ((string-start-pos (- (point) 3))
- (string-end-pos (point))
- (ppss (prog2
- (backward-char 3)
- (syntax-ppss)
- (forward-char 3)))
- (in-comment (nth 4 ppss))
- (in-string (nth 8 ppss)))
- (unless in-comment
- (if in-string
- ;; We're in a string, so this must be the closing triple-quote.
- ;; Put | on the last " character.
- (put-text-property (1- string-end-pos) string-end-pos
- 'syntax-table (string-to-syntax "|"))
- ;; We're not in a string, so this is the opening triple-quote.
- ;; Put | on the first " character.
- (put-text-property string-start-pos (1+ string-start-pos)
- 'syntax-table (string-to-syntax "|"))))))
-
(defconst julia-syntax-propertize-function
(syntax-propertize-rules
- ("\"\"\""
- (0 (ignore (julia-stringify-triple-quote))))
+ ;; 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 "|"))))
+ ;; 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.
- [nongnu] elpa/julia-mode b99710c 251/352: `python-mode`-like paren-indent, (continued)
- [nongnu] elpa/julia-mode b99710c 251/352: `python-mode`-like paren-indent, ELPA Syncer, 2021/08/29
- [nongnu] elpa/julia-mode 483805b 257/352: Merge pull request #29 from nverno/master, ELPA Syncer, 2021/08/29
- [nongnu] elpa/julia-mode 9f990bb 281/352: Handle string escapes, ELPA Syncer, 2021/08/29
- [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 <=
- [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, 2021/08/29
- [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