fmt: allow parsing files without `fn main()` (#5681)

pull/5687/head
spaceface777 2020-07-05 20:53:01 +02:00 committed by GitHub
parent 8d035a446a
commit d0e321c8a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 4 additions and 0 deletions

View File

@ -0,0 +1 @@
println('hello world')

View File

@ -0,0 +1 @@
println( "hello world" )

View File

@ -452,6 +452,8 @@ pub fn (mut p Parser) top_stmt() ast.Stmt {
file: p.file_name file: p.file_name
return_type: table.void_type return_type: table.void_type
} }
} else if p.pref.is_fmt {
return p.stmt(false)
} else { } else {
p.error('bad top level statement ' + p.tok.str()) p.error('bad top level statement ' + p.tok.str())
return ast.Stmt{} return ast.Stmt{}