parser: fix `v test-parser examples/cli.v` (#7243)

pull/7253/head
Daniel Däschle 2020-12-10 18:32:15 +01:00 committed by GitHub
parent 1c56ff7faf
commit aedd1d17b8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 5 additions and 15 deletions

View File

@ -609,3 +609,4 @@ jobs:
./v test-parser examples/hello_world.v
./v test-parser examples/hanoi.v
./v test-parser examples/fibonacci.v
./v test-parser examples/cli.v

View File

@ -140,13 +140,6 @@ fn yellow(msg string) string {
return term.yellow(msg)
}
fn italic(msg string) string {
if !support_color {
return msg
}
return term.italic(msg)
}
fn (mut context Context) log(msg string) {
if context.is_verbose {
label := yellow('info')
@ -219,7 +212,7 @@ fn (mut context Context) process_whole_file_in_worker(path string) (int, int) {
col := last_line.len
err := if is_panic { red('parser failure: panic') } else { red('parser failure: crash, ${ecode_details[res.exit_code.str()]}') }
path_to_line := bold('$path:$line:$col:')
err_line := italic(last_line.trim_left('\t'))
err_line := last_line.trim_left('\t')
println('$path_to_line $err')
println('\t$line | $err_line')
println('')

View File

@ -162,7 +162,7 @@ fn (mut p Parser) match_expr() ast.MatchExpr {
p.check(.lcbr)
}
mut branches := []ast.MatchBranch{}
for {
for p.tok.kind != .eof {
branch_first_pos := p.tok.position()
comments := p.eat_comments() // comments before {}
mut exprs := []ast.Expr{}

View File

@ -352,12 +352,8 @@ pub fn (mut p Parser) parse_block_no_scope(is_top_level bool) []ast.Stmt {
mut stmts := []ast.Stmt{}
if p.tok.kind != .rcbr {
mut c := 0
for {
for p.tok.kind !in [.eof, .rcbr] {
stmts << p.stmt(is_top_level)
// p.warn('after stmt(): tok=$p.tok.str()')
if p.tok.kind in [.eof, .rcbr] {
break
}
c++
if c % 100000 == 0 {
eprintln('parsed $c statements so far from fn $p.cur_fn_name ...')

View File

@ -319,7 +319,7 @@ fn (mut p Parser) struct_init(short_syntax bool) ast.StructInit {
// p.warn(is_short_syntax.str())
saved_is_amp := p.is_amp
p.is_amp = false
for p.tok.kind != .rcbr && p.tok.kind != .rpar {
for p.tok.kind !in [.rcbr, .rpar, .eof] {
mut field_name := ''
mut expr := ast.Expr{}
mut field_pos := token.Position{}