From 87df587f5a65f4ab2571119d3b86763e7c52e4ea Mon Sep 17 00:00:00 2001 From: yuyi Date: Thu, 9 Apr 2020 18:46:16 +0800 Subject: [PATCH] parser: fix script and repl error --- vlib/v/parser/parser.v | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/vlib/v/parser/parser.v b/vlib/v/parser/parser.v index 0293d17a28..f16538c595 100644 --- a/vlib/v/parser/parser.v +++ b/vlib/v/parser/parser.v @@ -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{} + } } } }