Skip to content

Commit fc47544

Browse files
committed
Teach AUTOs to process escaped backslashes at the end of quoted strings (veripool#1831)
"...\\..." is a string containing a backslash: \ "...\"..." is a string containing a double-quote: " When parsing double-quoted strings, we must detect embedded escaped backslashes and double-quotes. Detecting when a string terminates with one or more of these characters is tricky. Strings terminating in "...\"" are not uncommon, and have reasonably robust support, but strings terminating in "...\\" are quite rare, and were quite broken. This patch aims to improve the detection of "...\\" (or "...\\\\", or any even number of backslashes in a row immediately preceding a double-quote string terminator.
1 parent 0823759 commit fc47544

File tree

1 file changed

+40
-32
lines changed

1 file changed

+40
-32
lines changed

verilog-mode.el

Lines changed: 40 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3608,38 +3608,46 @@ This creates v-cmts properties where comments are in force."
36083608
(save-match-data
36093609
(verilog-save-buffer-state
36103610
(let (pt)
3611-
(goto-char beg)
3612-
(while (< (point) end)
3613-
(cond ((looking-at "//")
3614-
(setq pt (point))
3615-
(or (search-forward "\n" end t)
3616-
(goto-char end))
3617-
;; "1+": The leading // or /* itself isn't considered as
3618-
;; being "inside" the comment, so that a (search-backward)
3619-
;; that lands at the start of the // won't mis-indicate
3620-
;; it's inside a comment. Also otherwise it would be
3621-
;; hard to find a commented out /*AS*/ vs one that isn't
3622-
(put-text-property (1+ pt) (point) 'v-cmts t))
3623-
((looking-at "/\\*")
3624-
(setq pt (point))
3625-
(or (search-forward "*/" end t)
3626-
;; No error - let later code indicate it so we can
3627-
;; use inside functions on-the-fly
3628-
;;(error "%s: Unmatched /* */, at char %d"
3629-
;; (verilog-point-text) (point))
3630-
(goto-char end))
3631-
(put-text-property (1+ pt) (point) 'v-cmts t))
3632-
((looking-at "\"")
3633-
(setq pt (point))
3634-
(or (re-search-forward "[^\\]\"" end t) ; don't forward-char first, since we look for a non backslash first
3635-
;; No error - let later code indicate it so we can
3636-
(goto-char end))
3637-
(put-text-property (1+ pt) (point) 'v-cmts t))
3638-
(t
3639-
(forward-char 1)
3640-
(if (re-search-forward "[/\"]" end t)
3641-
(backward-char 1)
3642-
(goto-char end))))))))))
3611+
(goto-char beg)
3612+
(while (< (point) end)
3613+
(cond ((looking-at "//")
3614+
(setq pt (point))
3615+
(or (search-forward "\n" end t)
3616+
(goto-char end))
3617+
;; "1+": The leading // or /* itself isn't considered as
3618+
;; being "inside" the comment, so that a (search-backward)
3619+
;; that lands at the start of the // won't mis-indicate
3620+
;; it's inside a comment. Also otherwise it would be
3621+
;; hard to find a commented out /*AS*/ vs one that isn't
3622+
(put-text-property (1+ pt) (point) 'v-cmts t))
3623+
((looking-at "/\\*")
3624+
(setq pt (point))
3625+
(or (search-forward "*/" end t)
3626+
;; No error - let later code indicate it so we can
3627+
;; use inside functions on-the-fly
3628+
;;(error "%s: Unmatched /* */, at char %d"
3629+
;; (verilog-point-text) (point))
3630+
(goto-char end))
3631+
(put-text-property (1+ pt) (point) 'v-cmts t))
3632+
((looking-at "\"")
3633+
(setq pt (point))
3634+
(setq pt2 nil)
3635+
;; Move forward to the first non-escaped (backslashed) double-quote ("). That closes this string.
3636+
;; skip: \" (an escaped double-quote)
3637+
;; match: \\" (a backslash as the last character of a string)
3638+
(while (not pt2)
3639+
(or (re-search-forward "\\\\" end t)
3640+
(re-search-forward "[^\\]\"" end t)
3641+
(goto-char end))
3642+
(if (looking-at "\\\\")
3643+
(forward-char 2)
3644+
(setq pt2 (point))))
3645+
(put-text-property (1+ pt) (point) 'v-cmts t))
3646+
(t
3647+
(forward-char 1)
3648+
(if (re-search-forward "[/\"]" end t)
3649+
(backward-char 1)
3650+
(goto-char end))))))))))
36433651

36443652
(defun verilog-scan ()
36453653
"Parse the buffer, marking all comments with properties.

0 commit comments

Comments
 (0)