mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
parser: cleanup map syntax (#13713)
This commit is contained in:
parent
c1c3ae2a18
commit
1993bf2a12
@ -46,12 +46,8 @@ pub fn (mut p Parser) check_expr(precedence int) ?ast.Expr {
|
||||
p.inside_match = false
|
||||
} 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.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.next() // `map`
|
||||
p.next() // `{`
|
||||
node = p.map_init()
|
||||
p.check(.rcbr) // `}`
|
||||
} else {
|
||||
if p.inside_if && p.is_generic_name() && p.peek_tok.kind != .dot {
|
||||
// $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))
|
||||
&& (!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_for || p.inside_select) && !known_var { // && (p.tok.lit[0].is_capital() || p.builtin_mod) {
|
||||
// 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
|
||||
}
|
||||
&& (!p.inside_for || p.inside_select) && !known_var {
|
||||
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
|
||||
&& language == .v {
|
||||
|
6
vlib/v/parser/tests/map_syntax_err.out
Normal file
6
vlib/v/parser/tests/map_syntax_err.out
Normal file
@ -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 | }
|
4
vlib/v/parser/tests/map_syntax_err.vv
Normal file
4
vlib/v/parser/tests/map_syntax_err.vv
Normal file
@ -0,0 +1,4 @@
|
||||
fn main() {
|
||||
m := map{"aaa": 1}
|
||||
println(m)
|
||||
}
|
Loading…
Reference in New Issue
Block a user