1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

parser: improve the error message for unexpected keywords

This commit is contained in:
Delyan Angelov 2021-01-25 15:03:12 +02:00
parent 444d49da75
commit a5b10b5539
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
6 changed files with 25 additions and 5 deletions

View File

@ -425,7 +425,8 @@ fn (mut p Parser) check(expected token.Kind) {
if expected == .name {
p.name_error = true
}
p.error('unexpected `$p.tok.kind.str()`, expecting `$expected.str()`')
label := if token.is_key(p.tok.lit) { 'keyword ' } else { '' }
p.error('unexpected $label`$p.tok.kind.str()`, expecting `$expected.str()`')
}
}

View File

@ -0,0 +1,7 @@
vlib/v/parser/tests/unexpected_keyword.vv:5:12: error: unexpected keyword `import`, expecting `(`
3 | }
4 |
5 | fn (s Abc) import(name string) {
| ~~~~~~
6 | println(name)
7 | }

View File

@ -0,0 +1,12 @@
struct Abc {
x int
}
fn (s Abc) import(name string) {
println(name)
}
fn main() {
s := Abc{}
s.import('lib')
}