From aedd1d17b8a280646a6223b8a9f4e4747504ae8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20D=C3=A4schle?= Date: Thu, 10 Dec 2020 18:32:15 +0100 Subject: [PATCH] parser: fix `v test-parser examples/cli.v` (#7243) --- .github/workflows/ci.yml | 1 + cmd/tools/vtest-parser.v | 9 +-------- vlib/v/parser/if_match.v | 2 +- vlib/v/parser/parser.v | 6 +----- vlib/v/parser/struct.v | 2 +- 5 files changed, 5 insertions(+), 15 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 52da24e39e..37ccd5c5cc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 diff --git a/cmd/tools/vtest-parser.v b/cmd/tools/vtest-parser.v index 233a16c78d..4cd4f2c242 100644 --- a/cmd/tools/vtest-parser.v +++ b/cmd/tools/vtest-parser.v @@ -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('') diff --git a/vlib/v/parser/if_match.v b/vlib/v/parser/if_match.v index 4d6bac25b6..eeed18da41 100644 --- a/vlib/v/parser/if_match.v +++ b/vlib/v/parser/if_match.v @@ -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{} diff --git a/vlib/v/parser/parser.v b/vlib/v/parser/parser.v index f2ff629167..524b554a58 100644 --- a/vlib/v/parser/parser.v +++ b/vlib/v/parser/parser.v @@ -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 ...') diff --git a/vlib/v/parser/struct.v b/vlib/v/parser/struct.v index 0663c12bed..3caf58b8c4 100644 --- a/vlib/v/parser/struct.v +++ b/vlib/v/parser/struct.v @@ -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{}