parser: cleanup map syntax (#13713)
parent
c1c3ae2a18
commit
1993bf2a12
|
@ -46,12 +46,8 @@ pub fn (mut p Parser) check_expr(precedence int) ?ast.Expr {
|
||||||
p.inside_match = false
|
p.inside_match = false
|
||||||
} else if p.tok.lit == 'map' && p.peek_tok.kind == .lcbr && !(p.builtin_mod
|
} else if p.tok.lit == 'map' && p.peek_tok.kind == .lcbr && !(p.builtin_mod
|
||||||
&& p.file_base in ['map.v', 'map_d_gcboehm_opt.v']) {
|
&& p.file_base in ['map.v', 'map_d_gcboehm_opt.v']) {
|
||||||
p.warn_with_pos("deprecated map syntax, use syntax like `{'age': 20}`",
|
p.error_with_pos("deprecated map syntax, use syntax like `{'age': 20}`",
|
||||||
p.tok.pos())
|
p.tok.pos())
|
||||||
p.next() // `map`
|
|
||||||
p.next() // `{`
|
|
||||||
node = p.map_init()
|
|
||||||
p.check(.rcbr) // `}`
|
|
||||||
} else {
|
} else {
|
||||||
if p.inside_if && p.is_generic_name() && p.peek_tok.kind != .dot {
|
if p.inside_if && p.is_generic_name() && p.peek_tok.kind != .dot {
|
||||||
// $if T is string {}
|
// $if T is string {}
|
||||||
|
|
|
@ -2320,17 +2320,7 @@ pub fn (mut p Parser) name_expr() ast.Expr {
|
||||||
} else if (p.peek_tok.kind == .lcbr || (p.peek_tok.kind == .lt && lit0_is_capital))
|
} else if (p.peek_tok.kind == .lcbr || (p.peek_tok.kind == .lt && lit0_is_capital))
|
||||||
&& (!p.inside_match || (p.inside_select && prev_tok_kind == .arrow && lit0_is_capital))
|
&& (!p.inside_match || (p.inside_select && prev_tok_kind == .arrow && lit0_is_capital))
|
||||||
&& !p.inside_match_case && (!p.inside_if || p.inside_select)
|
&& !p.inside_match_case && (!p.inside_if || p.inside_select)
|
||||||
&& (!p.inside_for || p.inside_select) && !known_var { // && (p.tok.lit[0].is_capital() || p.builtin_mod) {
|
&& (!p.inside_for || p.inside_select) && !known_var {
|
||||||
// map.v has struct literal: map{field: expr}
|
|
||||||
if p.peek_tok.kind == .lcbr && !(p.builtin_mod
|
|
||||||
&& p.file_base in ['map.v', 'map_d_gcboehm_opt.v']) && p.tok.lit == 'map' {
|
|
||||||
// map{key_expr: val_expr}
|
|
||||||
p.check(.name)
|
|
||||||
p.check(.lcbr)
|
|
||||||
map_init := p.map_init()
|
|
||||||
p.check(.rcbr)
|
|
||||||
return map_init
|
|
||||||
}
|
|
||||||
return p.struct_init(p.mod + '.' + p.tok.lit, false) // short_syntax: false
|
return p.struct_init(p.mod + '.' + p.tok.lit, false) // short_syntax: false
|
||||||
} else if p.peek_tok.kind == .lcbr && p.inside_if && lit0_is_capital && !known_var
|
} else if p.peek_tok.kind == .lcbr && p.inside_if && lit0_is_capital && !known_var
|
||||||
&& language == .v {
|
&& language == .v {
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
vlib/v/parser/tests/map_syntax_err.vv:2:7: error: deprecated map syntax, use syntax like `{'age': 20}`
|
||||||
|
1 | fn main() {
|
||||||
|
2 | m := map{"aaa": 1}
|
||||||
|
| ~~~
|
||||||
|
3 | println(m)
|
||||||
|
4 | }
|
|
@ -0,0 +1,4 @@
|
||||||
|
fn main() {
|
||||||
|
m := map{"aaa": 1}
|
||||||
|
println(m)
|
||||||
|
}
|
Loading…
Reference in New Issue