token: fix Token.str() for punctuation and operators (#8610)
parent
d284918554
commit
b92f980274
|
@ -250,11 +250,11 @@ pub fn (mut p Parser) expr(precedence int) ast.Expr {
|
|||
node = p.struct_init(true) // short_syntax: true
|
||||
} else if p.tok.kind == .name {
|
||||
p.next()
|
||||
s := if p.tok.lit != '' { '`$p.tok.lit`' } else { p.tok.kind.str() }
|
||||
p.error_with_pos('unexpected $s, expecting `:`', p.tok.position())
|
||||
p.error_with_pos('unexpected $p.tok, expecting `:` after struct field name',
|
||||
p.tok.position())
|
||||
return ast.Expr{}
|
||||
} else {
|
||||
p.error_with_pos('unexpected `$p.tok.lit`, expecting struct key',
|
||||
p.error_with_pos('unexpected $p.tok, expecting struct field name',
|
||||
p.tok.position())
|
||||
return ast.Expr{}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
vlib/v/parser/tests/anon_fn_return_type.vv:7:22: error: expected return type, not string "hi" for anonymous function
|
||||
vlib/v/parser/tests/anon_fn_return_type.vv:7:22: error: expected return type, not string `hi` for anonymous function
|
||||
5 | _ = fn (name string) flag.Flag
|
||||
6 | _ = fn (name string) flag.Flag {return {}}
|
||||
7 | _ = fn (name string) "hi" + name
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
vlib/v/parser/tests/struct_field_expected.vv:6:2: error: unexpected `.`, expecting struct field name
|
||||
4 |
|
||||
5 | x = {
|
||||
6 | .a : 'Alpha'
|
||||
| ^
|
||||
7 | .b : 'Beta'
|
||||
8 | }
|
|
@ -0,0 +1,9 @@
|
|||
enum TestEnum {
|
||||
a b
|
||||
}
|
||||
|
||||
x = {
|
||||
.a : 'Alpha'
|
||||
.b : 'Beta'
|
||||
}
|
||||
|
|
@ -324,7 +324,16 @@ pub fn (t Kind) str() string {
|
|||
}
|
||||
|
||||
pub fn (t Token) str() string {
|
||||
return '$t.kind.str() "$t.lit"'
|
||||
mut s := t.kind.str()
|
||||
if s.len == 0 {
|
||||
eprintln('missing token kind string')
|
||||
} else if !s[0].is_letter() {
|
||||
// punctuation, operators
|
||||
return '`$s`'
|
||||
}
|
||||
// string contents etc
|
||||
if t.lit != '' { s += ' `$t.lit`' }
|
||||
return s
|
||||
}
|
||||
|
||||
// Representation of highest and lowest precedence
|
||||
|
|
Loading…
Reference in New Issue