repl: fix for single lines ending with // comment

pull/4693/head
Delyan Angelov 2020-05-03 20:48:46 +03:00
parent 845ffb59a6
commit 0b750a234f
1 changed files with 4 additions and 2 deletions

View File

@ -76,12 +76,14 @@ pub fn new_scanner(text string, comments_mode CommentsMode) &Scanner {
} }
pub fn (s &Scanner) add_fn_main_and_rescan(pos int) { pub fn (s &Scanner) add_fn_main_and_rescan(pos int) {
// NB: the text may have ended in // comment, which would hide the ending }
// To avoid that, we need a \n right before it.
if pos > 0 { if pos > 0 {
s.text = s.text[..pos] + 'fn main() {' + s.text[pos..] + '}' s.text = s.text[..pos] + 'fn main() {' + s.text[pos..] + '\n}'
s.pos = pos s.pos = pos
s.is_started = false s.is_started = false
} else { } else {
s.text = 'fn main() {' + s.text + '}' s.text = 'fn main() {' + s.text + '\n}'
s.pos = 0 s.pos = 0
s.line_nr = 0 s.line_nr = 0
s.is_started = false s.is_started = false