@@ -152,6 +152,81 @@ END is the point after the token."
152152
153153 table))
154154
155+ (defun swift-mode:syntax-propertize (start end )
156+ " Update text properties for multiline strings.
157+ Mark the beginning of and the end of multiline strings as general string
158+ delimiters between position START and END.
159+ Intended for `syntax-propertize-function' "
160+ (remove-text-properties start end '(syntax-table nil ))
161+ (let* ((parser-state (syntax-ppss start))
162+ (inside-string (nth 3 parser-state))
163+ (comment-nesting (nth 4 parser-state))
164+ (comment-beginning-position (nth 8 parser-state)))
165+ (cond
166+ ((eq inside-string t )
167+ (swift-mode:syntax-propertize:end-of-multiline-string end))
168+
169+ (inside-string
170+ (swift-mode:syntax-propertize:end-of-single-line-string end))
171+
172+ (comment-nesting
173+ (goto-char comment-beginning-position)
174+ (forward-comment (point-max )))))
175+
176+ (while (search-forward-regexp
177+ (mapconcat #'regexp-quote '(" \"\"\" " " \" " " //" " /*" ) " \\ |" )
178+ end t )
179+ (cond
180+ ((equal " \"\"\" " (match-string-no-properties 0 ))
181+ (put-text-property (match-beginning 0 ) (1+ (match-beginning 0 ))
182+ 'syntax-table
183+ (string-to-syntax " |" ))
184+ (swift-mode:syntax-propertize:end-of-multiline-string end))
185+
186+ ((equal " \" " (match-string-no-properties 0 ))
187+ (swift-mode:syntax-propertize:end-of-single-line-string end))
188+
189+ ((equal " //" (match-string-no-properties 0 ))
190+ (goto-char (match-beginning 0 ))
191+ (forward-comment (point-max )))
192+
193+ ((equal " /*" (match-string-no-properties 0 ))
194+ (goto-char (match-beginning 0 ))
195+ (forward-comment (point-max ))))))
196+
197+ (defun swift-mode:syntax-propertize:end-of-multiline-string (end )
198+ " Move point to the end of multiline string.
199+ Assuming the cursor is on a multiline string.
200+ If the end of the string found, put a text property on it.
201+ If the multiline string go beyond END, stop there."
202+ ; ; FIXME string interpolation
203+ (if (search-forward " \"\"\" " end t )
204+ (if (swift-mode:escaped-p (match-beginning 0 ))
205+ (swift-mode:syntax-propertize:end-of-multiline-string end)
206+ (put-text-property (1- (point )) (point )
207+ 'syntax-table
208+ (string-to-syntax " |" )))
209+ (goto-char end)))
210+
211+ (defun swift-mode:syntax-propertize:end-of-single-line-string (end )
212+ " Move point to the end of string.
213+ Assuming the cursor is on a string.
214+ If the multiline string go beyond END, stop there."
215+ ; ; FIXME string interpolation
216+ (if (search-forward " \" " end t )
217+ (when (swift-mode:escaped-p (match-beginning 0 ))
218+ (swift-mode:syntax-propertize:end-of-single-line-string end))
219+ (goto-char end)))
220+
221+ (defun swift-mode:escaped-p (position )
222+ " Return t if the POSITION is proceeded by odd number of backslashes.
223+ Return nil otherwise."
224+ (let ((p position)
225+ (count 0 ))
226+ (while (eq (char-before p) ?\\ )
227+ (setq count (1+ count))
228+ (setq p (1- p)))
229+ (= (mod count 2 ) 1 )))
155230
156231; ;; Lexers
157232
0 commit comments