parser: fix silent parsing examples/vmod.v (#7264)

pull/7271/head
Daniel Däschle 2020-12-11 18:14:07 +01:00 committed by GitHub
parent 74dc57e678
commit 9c1a5c5117
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 3 deletions

View File

@ -611,3 +611,4 @@ jobs:
./v test-parser examples/fibonacci.v
./v test-parser examples/cli.v
./v test-parser examples/json.v
./v test-parser examples/vmod.v

View File

@ -1140,7 +1140,7 @@ pub fn (mut p Parser) name_expr() ast.Expr {
p.check(.dot)
p.expr_mod = mod
}
lit0_is_capital := if p.tok.kind != .eof { p.tok.lit[0].is_capital() } else { false }
lit0_is_capital := if p.tok.kind != .eof && p.tok.lit.len > 0 { p.tok.lit[0].is_capital() } else { false }
// use heuristics to detect `func<T>()` from `var < expr`
is_generic_call := !lit0_is_capital && p.peek_tok.kind == .lt && (match p.peek_tok2.kind {
.name {

View File

@ -763,8 +763,11 @@ fn (mut s Scanner) text_scan() token.Token {
return s.new_token(.comma, '', 1)
}
`@` {
s.pos++
name := s.ident_name()
mut name := ''
if nextc != `\0` {
s.pos++
name = s.ident_name()
}
if s.is_fmt {
return s.new_token(.name, '@' + name, name.len + 1)
}