branch: elpa/forth-mode
commit 867922d61e362b7f46cc3380d862ede346073469
Author: Helmut Eller <[email protected]>
Commit: Helmut Eller <[email protected]>
Handle string literals more correctly
* test/tests.el (forth-string-font-lock): Add tests.
* forth-syntax.el (forth-syntax--state-string): Use "generic string
delimitier" "|" so that we can match \" with \n.
(forth-syntax--state-s\\\"): Escape \\ and \" sequence.
---
forth-syntax.el | 10 +++++-----
test/tests.el | 9 ++++++++-
2 files changed, 13 insertions(+), 6 deletions(-)
diff --git a/forth-syntax.el b/forth-syntax.el
index 4c6e02a25b..1aee67f6f0 100644
--- a/forth-syntax.el
+++ b/forth-syntax.el
@@ -58,10 +58,10 @@ SYNTAX must be a valid argument for `string-to-syntax'."
;; One line strings
(defun forth-syntax--state-string ()
(re-search-backward "\"\\=")
- (forth-syntax--set-syntax (point) (1+ (point)) "\"")
+ (forth-syntax--set-syntax (point) (1+ (point)) "|")
(forward-char)
(cond ((re-search-forward "[\"\n]" nil t)
- (forth-syntax--set-syntax (1- (point)) (point) "\"")
+ (forth-syntax--set-syntax (1- (point)) (point) "|")
#'forth-syntax--state-normal)
(t
(goto-char (point-max))
@@ -69,16 +69,16 @@ SYNTAX must be a valid argument for `string-to-syntax'."
(defun forth-syntax--state-s\\\" ()
(re-search-backward "\"\\=")
- (forth-syntax--set-syntax (point) (1+ (point)) "\"")
+ (forth-syntax--set-syntax (point) (1+ (point)) "|")
(forward-char)
- (while (and (re-search-forward "\\([\"\n]\\|\\\\\"\\)" nil t)
+ (while (and (re-search-forward "\\([\"\n]\\|\\\\\\\\\\|\\\\\"\\)" nil t)
(cond ((= (char-after (match-beginning 0)) ?\\)
(forth-syntax--set-syntax (match-beginning 0)
(1+ (match-beginning 0))
"\\")
t))))
(cond ((looking-back "[\"\n]" 1)
- (forth-syntax--set-syntax (1- (point)) (point) "\"")
+ (forth-syntax--set-syntax (1- (point)) (point) "|")
#'forth-syntax--state-normal)
(t
(goto-char (point-max))
diff --git a/test/tests.el b/test/tests.el
index 3822334861..75ab802ec1 100644
--- a/test/tests.el
+++ b/test/tests.el
@@ -104,11 +104,18 @@ The whitespace before and including \"|\" on each line is
removed."
(forth-assert-face "c\" ab\"" 2 font-lock-string-face)
(forth-assert-face "[char] \" of" 10 nil)
(forth-assert-face "frob\" ab\" " 6 nil)
+ (forth-assert-face "s\" 4 \n 8 " 4 font-lock-string-face)
+ (forth-assert-face "s\" 4 \n 8 " 8 nil)
(forth-assert-face "s\\\" ab\"" 1 nil)
(forth-assert-face "s\\\" ab\"" 3 font-lock-string-face)
(forth-assert-face "s\\\" ab\"" 6 font-lock-string-face)
(forth-assert-face "s\\\" a\\\"c\"" 7 font-lock-string-face)
- (forth-assert-face "s\\\" a\\\"c\" x" 10 nil))
+ (forth-assert-face "s\\\" \\\\ 7 \" 12" 7 font-lock-string-face)
+ (forth-assert-face "s\\\" \\\\ 7 \" 12" 12 nil)
+ (forth-assert-face "s\\\" \\\" 7 \" 12" 7 font-lock-string-face)
+ (forth-assert-face "s\\\" \\\" 7 \" 12" 12 nil)
+ (forth-assert-face "s\\\" 5 \n 9 " 4 font-lock-string-face)
+ (forth-assert-face "s\\\" 5 \n 9 " 9 nil))
(ert-deftest forth-parsing-words-font-lock ()
(forth-assert-face "postpone ( x " 11 nil)