parser: fix silent errors (#7271)

pull/7272/head
Daniel Däschle 2020-12-12 04:06:09 +01:00 committed by GitHub
parent a26e1e6e13
commit 11808f9fa3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 16 additions and 8 deletions

View File

@ -612,3 +612,5 @@ jobs:
./v test-parser examples/cli.v
./v test-parser examples/json.v
./v test-parser examples/vmod.v
./v test-parser examples/regex_example.v
./v test-parser examples/2048/2048.v

View File

@ -38,7 +38,7 @@ fn (mut p Parser) array_init() ast.ArrayInit {
}
} else {
// [1,2,3] or [const]byte
for i := 0; p.tok.kind != .rsbr; i++ {
for i := 0; p.tok.kind !in [.rsbr, .eof]; i++ {
exprs << p.expr(0)
ecmnts << p.eat_comments()
if p.tok.kind == .comma {

View File

@ -14,6 +14,10 @@ pub fn (mut p Parser) parse_array_type() table.Type {
p.next()
p.check(.rsbr)
elem_type := p.parse_type()
if elem_type.idx() == 0 {
// error is handled by parse_type
return 0
}
// sym := p.table.get_type_symbol(elem_type)
idx := p.table.find_or_register_array_fixed(elem_type, size, 1)
return table.new_type(idx)
@ -72,7 +76,7 @@ pub fn (mut p Parser) parse_chan_type() table.Type {
pub fn (mut p Parser) parse_multi_return_type() table.Type {
p.check(.lpar)
mut mr_types := []table.Type{}
for {
for p.tok.kind != .eof {
mr_type := p.parse_type()
mr_types << mr_type
if p.tok.kind == .comma {
@ -219,7 +223,7 @@ pub fn (mut p Parser) parse_any_type(language table.Language, is_ptr bool, check
p.check(.dot)
// prefix with full module
name = '${p.imports[name]}.$p.tok.lit'
if !p.tok.lit[0].is_capital() {
if p.tok.lit.len > 0 && !p.tok.lit[0].is_capital() {
p.error('imported types must start with a capital letter')
return 0
}

View File

@ -2102,7 +2102,7 @@ fn (mut p Parser) assoc() ast.Assoc {
mut fields := []string{}
mut vals := []ast.Expr{}
p.check(.pipe)
for {
for p.tok.kind != .eof {
fields << p.check_name()
p.check(.colon)
expr := p.expr(0)

View File

@ -890,10 +890,12 @@ fn (mut s Scanner) text_scan() token.Token {
if nextc == `=` {
s.pos++
return s.new_token(.ne, '', 2)
} else if nextc == `i` && s.text[s.pos + 2] == `n` && s.text[s.pos + 3].is_space() {
} else if s.text.len > s.pos + 3 &&
nextc == `i` && s.text[s.pos + 2] == `n` && s.text[s.pos + 3].is_space() {
s.pos += 2
return s.new_token(.not_in, '', 3)
} else if nextc == `i` && s.text[s.pos + 2] == `s` && s.text[s.pos + 3].is_space() {
} else if s.text.len > s.pos + 3 &&
nextc == `i` && s.text[s.pos + 2] == `s` && s.text[s.pos + 3].is_space() {
s.pos += 2
return s.new_token(.not_is, '', 3)
} else {
@ -943,7 +945,7 @@ fn (mut s Scanner) text_scan() token.Token {
start := s.pos + 2
mut nest_count := 1
// Skip comment
for nest_count > 0 {
for nest_count > 0 && s.pos < s.text.len - 1 {
s.pos++
if s.pos >= s.text.len {
s.line_nr--