parser: improve the error message for unexpected keywords
parent
444d49da75
commit
a5b10b5539
|
@ -1,6 +1,6 @@
|
||||||
vlib/v/checker/tests/trailing_comma_struct_attr.vv:3:31: error: unexpected `]`, expecting `name`
|
vlib/v/checker/tests/trailing_comma_struct_attr.vv:3:31: error: unexpected `]`, expecting `name`
|
||||||
1 | struct User {
|
1 | struct User {
|
||||||
2 | name string
|
2 | name string
|
||||||
3 | jobs []string [json:jobss;]
|
3 | jobs []string [json:jobss;]
|
||||||
| ^
|
| ^
|
||||||
4 | }
|
4 | }
|
||||||
|
|
|
@ -425,7 +425,8 @@ fn (mut p Parser) check(expected token.Kind) {
|
||||||
if expected == .name {
|
if expected == .name {
|
||||||
p.name_error = true
|
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()`')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,4 +4,4 @@ vlib/v/parser/tests/struct_update_err.vv:15:3: error: unexpected `...`, expectin
|
||||||
15 | ...f
|
15 | ...f
|
||||||
| ~~~
|
| ~~~
|
||||||
16 | }
|
16 | }
|
||||||
17 | }
|
17 | }
|
||||||
|
|
|
@ -2,4 +2,4 @@ vlib/v/parser/tests/uncomplete_module_call_err.vv:7:1: error: unexpected `}`, ex
|
||||||
5 | fn main() {
|
5 | fn main() {
|
||||||
6 | os.
|
6 | os.
|
||||||
7 | }
|
7 | }
|
||||||
| ^
|
| ^
|
||||||
|
|
|
@ -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 | }
|
|
@ -0,0 +1,12 @@
|
||||||
|
struct Abc {
|
||||||
|
x int
|
||||||
|
}
|
||||||
|
|
||||||
|
fn (s Abc) import(name string) {
|
||||||
|
println(name)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
s := Abc{}
|
||||||
|
s.import('lib')
|
||||||
|
}
|
Loading…
Reference in New Issue