Skip to content

Commit cfae3b8

Browse files
committed
Fix handling of single-line strings starts with #"""
Multiline strings are valid only if a line break follows the opening delimiter. #200
1 parent 8ca699d commit cfae3b8

File tree

4 files changed

+15
-10
lines changed

4 files changed

+15
-10
lines changed

swift-mode-beginning-of-defun.el

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1225,7 +1225,7 @@ of lines. Empty lines split blocks. Example:
12251225
(progn
12261226
(goto-char string-beginning-position)
12271227
(cond
1228-
((and (looking-at "\"\"\"")
1228+
((and (looking-at "\"\"\"$")
12291229
(save-excursion
12301230
(skip-chars-forward "\"")
12311231
(skip-syntax-forward " >")

swift-mode-fill.el

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ comment particularly well)."
206206
(save-match-data
207207
(skip-syntax-backward " ")
208208
(let ((chunk (or (swift-mode:chunk-after)
209-
(and (looking-at "\\s *\\(/[/*]\\|#*\"\"\"\\)")
209+
(and (looking-at "\\s *\\(/[/*]\\|#*\"\"\"$\\)")
210210
(swift-mode:chunk-after (match-end 0)))
211211
(save-excursion
212212
(skip-chars-backward "#")
@@ -292,7 +292,7 @@ Fix up multiline comments.
292292
(save-match-data
293293
(goto-char from)
294294
(or (swift-mode:chunk-after)
295-
(and (looking-at "\\s *\\(/[/*]\\|#*\"\"\"\\)")
295+
(and (looking-at "\\s *\\(/[/*]\\|#*\"\"\"$\\)")
296296
(swift-mode:chunk-after (match-end 0)))))))
297297
comment-start-pos
298298
comment-end-pos
@@ -408,7 +408,7 @@ Use `comment-fill-column' as `fill-column' when filling inside a comment."
408408
(let* ((chunk (save-excursion
409409
(save-match-data
410410
(or (swift-mode:chunk-after)
411-
(and (looking-at "\\s *\\(/[/*]\\|#*\"\"\"\\)")
411+
(and (looking-at "\\s *\\(/[/*]\\|#*\"\"\"$\\)")
412412
(swift-mode:chunk-after (match-end 0)))))))
413413
(fill-column
414414
(if (swift-mode:chunk:comment-p chunk)
@@ -461,7 +461,7 @@ Return non-nil if skipped a paragraph. Return nil otherwise."
461461
(skip-syntax-backward " >")
462462
(skip-syntax-forward " >"))
463463
(let ((chunk (or (swift-mode:chunk-after)
464-
(and (looking-at "/[/*]\\|#*\"\"\"")
464+
(and (looking-at "/[/*]\\|#*\"\"\"$")
465465
(swift-mode:chunk-after (match-end 0))))))
466466
(cond
467467
((swift-mode:chunk:single-line-comment-p chunk)
@@ -637,7 +637,7 @@ Return non-nil if skipped a paragraph. Return nil otherwise."
637637
(when (eq direction 'backward)
638638
(goto-char pos)))
639639
(back-to-indentation)
640-
(when (or (looking-at "/[/*]\\|#*\"\"\"")
640+
(when (or (looking-at "/[/*]\\|#*\"\"\"$")
641641
(swift-mode:chunk-after))
642642
(setq done t)
643643
(when (eq direction 'backward)

swift-mode-lexer.el

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -305,9 +305,11 @@ stops where the level becomes zero.
305305
306306
Return non-nil if the matching parenthesis found, or return nil otherwise."
307307
(let ((found-matching-parenthesis nil)
308-
(pattern (mapconcat #'regexp-quote
309-
'("\"\"\"" "\"" "`" "/" "(" ")")
310-
"\\|")))
308+
(pattern (concat
309+
"\"\"\"$\\|"
310+
(mapconcat #'regexp-quote
311+
'("\"" "`" "/" "(" ")")
312+
"\\|"))))
311313
(while (and (not found-matching-parenthesis)
312314
(< (point) end)
313315
(search-forward-regexp pattern end t))
@@ -579,6 +581,7 @@ pound signs."
579581
(setq chunk-start (1- (point))))
580582
;; Incomplete interpolated expression.
581583
(setq done t)
584+
(swift-mode:put-syntax-multiline-property start end)
582585
(goto-char end))))
583586

584587
;; Other escape sequences
@@ -1912,7 +1915,7 @@ If PARSER-STATE is given, it is used instead of (syntax-ppss)."
19121915
;; single-line string delimiters.
19131916
(cond
19141917
((save-excursion (goto-char (nth 8 parser-state))
1915-
(looking-at "#*\"\"\""))
1918+
(looking-at "#*\"\"\"$"))
19161919
(swift-mode:chunk 'multiline-string (nth 8 parser-state)))
19171920
((save-excursion (goto-char (nth 8 parser-state))
19181921
(looking-at "#*/"))

test/swift-files/indent/strings.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,8 @@ func f() {
160160
let x = "abc\( 1 + (2 + 3) ) \" a "
161161
let x = #"abc\( 1 + (2 + 3) ) \#( 1 + (2 + 3) ) \" \#"# " a \"#
162162
let x = ##"abc\( 1 + (2 + 3) ) \#( 1 + (2 + 3) ) \" \#"# " a \"##
163+
let x = ##"""##
164+
let x = ##"""abc"##
163165
let x = 1
164166

165167

0 commit comments

Comments
 (0)