From d0e321c8a3d66bd6d3f791ea90812d4a045ed8e5 Mon Sep 17 00:00:00 2001 From: spaceface777 Date: Sun, 5 Jul 2020 20:53:01 +0200 Subject: [PATCH] fmt: allow parsing files without `fn main()` (#5681) --- vlib/v/fmt/tests/no_main_expected.vv | 1 + vlib/v/fmt/tests/no_main_input.vv | 1 + vlib/v/parser/parser.v | 2 ++ 3 files changed, 4 insertions(+) create mode 100644 vlib/v/fmt/tests/no_main_expected.vv create mode 100644 vlib/v/fmt/tests/no_main_input.vv diff --git a/vlib/v/fmt/tests/no_main_expected.vv b/vlib/v/fmt/tests/no_main_expected.vv new file mode 100644 index 0000000000..2a082f98cb --- /dev/null +++ b/vlib/v/fmt/tests/no_main_expected.vv @@ -0,0 +1 @@ +println('hello world') diff --git a/vlib/v/fmt/tests/no_main_input.vv b/vlib/v/fmt/tests/no_main_input.vv new file mode 100644 index 0000000000..d77431408d --- /dev/null +++ b/vlib/v/fmt/tests/no_main_input.vv @@ -0,0 +1 @@ +println( "hello world" ) diff --git a/vlib/v/parser/parser.v b/vlib/v/parser/parser.v index 38c2861307..1a93c68cca 100644 --- a/vlib/v/parser/parser.v +++ b/vlib/v/parser/parser.v @@ -452,6 +452,8 @@ pub fn (mut p Parser) top_stmt() ast.Stmt { file: p.file_name return_type: table.void_type } + } else if p.pref.is_fmt { + return p.stmt(false) } else { p.error('bad top level statement ' + p.tok.str()) return ast.Stmt{}