1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

parser: fix script and repl error

This commit is contained in:
yuyi 2020-04-09 18:46:16 +08:00 committed by GitHub
parent 384d401af0
commit 87df587f5a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -320,9 +320,18 @@ pub fn (p mut Parser) top_stmt() ast.Stmt {
return p.comment()
}
else {
// #printf("");
p.error('bad top level statement ' + p.tok.str())
return ast.Stmt{}
if p.pref.is_script && !p.pref.is_test {
p.scanner.text = 'fn main() {' + p.scanner.text + '}'
p.scanner.is_started = false
p.scanner.pos = 0
p.next()
p.next()
return p.top_stmt()
}
else {
p.error('bad top level statement ' + p.tok.str())
return ast.Stmt{}
}
}
}
}