Skip to content

Commit bc28735

Browse files
author
Dave Abrahams
committed
[gyb] Fix line-directive mapping of multiline substitutions
fixes https://bugs.swift.org/browse/SR-4362
1 parent 7019b84 commit bc28735

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

utils/gyb.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -579,10 +579,8 @@ def append_text(self, text, file, line):
579579
elif '\n' in text:
580580
i = text.find('\n')
581581
self.result_text.append(text[:i + 1])
582-
self.last_file_line = (
583-
self.last_file_line[0], self.last_file_line[1] + 1)
584582
# and try again
585-
self.append_text(text[i + 1:], file, line)
583+
self.append_text(text[i + 1:], file, line + 1)
586584
return
587585

588586
self.result_text.append(text)
@@ -755,10 +753,16 @@ def expand(filename, line_directive=_default_line_directive, **local_bindings):
755753
>>> from tempfile import NamedTemporaryFile
756754
>>> f = NamedTemporaryFile()
757755
>>> f.write(
758-
... '''---
756+
... r'''---
759757
... % for i in range(int(x)):
760758
... a pox on ${i} for epoxy
761759
... % end
760+
... ${120 +
761+
...
762+
... 3}
763+
... abc
764+
... ${"w\nx\nX\ny"}
765+
... z
762766
... ''')
763767
>>> f.flush()
764768
>>> result = expand(
@@ -772,7 +776,16 @@ def expand(filename, line_directive=_default_line_directive, **local_bindings):
772776
a pox on 0 for epoxy
773777
//#sourceLocation(file: "dummy.file", line: 3)
774778
a pox on 1 for epoxy
775-
779+
//#sourceLocation(file: "dummy.file", line: 5)
780+
123
781+
//#sourceLocation(file: "dummy.file", line: 8)
782+
abc
783+
w
784+
x
785+
X
786+
y
787+
//#sourceLocation(file: "dummy.file", line: 10)
788+
z
776789
"""
777790
with open(filename) as f:
778791
t = parse_template(filename, f.read())

0 commit comments

Comments
 (0)