Skip to content

Commit bf7e345

Browse files
committed
repl: allow """ strings to span lines
1 parent e1bc5aa commit bf7e345

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

repl/repl.go

+7-3
Original file line numberDiff line numberDiff line change
@@ -163,14 +163,18 @@ func Run() {
163163

164164
}
165165
// need +"\n" because "single" expects \n terminated input
166-
obj, err := compile.Compile(previous+string(line)+"\n", prog, "single", 0, true)
166+
toCompile := previous + string(line)
167+
if toCompile == "" {
168+
continue
169+
}
170+
obj, err := compile.Compile(toCompile+"\n", prog, "single", 0, true)
167171
if err != nil {
168172
// Detect that we should start a continuation line
169173
// FIXME detect EOF properly!
170174
errText := err.Error()
171-
if strings.Contains(errText, "unexpected EOF while parsing") {
175+
if strings.Contains(errText, "unexpected EOF while parsing") || strings.Contains(errText, "EOF while scanning triple-quoted string literal") {
172176
continuation = true
173-
previous = string(line) + "\n"
177+
previous += string(line) + "\n"
174178
continue
175179
}
176180
}

0 commit comments

Comments
 (0)