mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
vfmt: fix alignment of value formatting for "x := {.
: 1, ♖
: 2}"
This commit is contained in:
parent
1709d175bb
commit
4718a818b8
@ -2326,15 +2326,17 @@ pub fn (mut f Fmt) map_init(node ast.MapInit) {
|
|||||||
for key in node.keys {
|
for key in node.keys {
|
||||||
skey := f.node_str(key).trim_space()
|
skey := f.node_str(key).trim_space()
|
||||||
skeys << skey
|
skeys << skey
|
||||||
if skey.len > max_field_len {
|
skey_len := skey.len_utf8()
|
||||||
max_field_len = skey.len
|
if skey_len > max_field_len {
|
||||||
|
max_field_len = skey_len
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for i, _ in node.keys {
|
for i, _ in node.keys {
|
||||||
skey := skeys[i]
|
skey := skeys[i]
|
||||||
f.write(skey)
|
f.write(skey)
|
||||||
f.write(': ')
|
f.write(': ')
|
||||||
f.write(strings.repeat(` `, max_field_len - skey.len))
|
skey_len := skey.len_utf8()
|
||||||
|
f.write(strings.repeat(` `, max_field_len - skey_len))
|
||||||
f.expr(node.vals[i])
|
f.expr(node.vals[i])
|
||||||
f.comments(node.comments[i], prev_line: node.vals[i].pos().last_line, has_nl: false)
|
f.comments(node.comments[i], prev_line: node.vals[i].pos().last_line, has_nl: false)
|
||||||
f.writeln('')
|
f.writeln('')
|
||||||
|
@ -0,0 +1,35 @@
|
|||||||
|
enum Pieces {
|
||||||
|
empty
|
||||||
|
off
|
||||||
|
wp
|
||||||
|
wn
|
||||||
|
wb
|
||||||
|
wr
|
||||||
|
wq
|
||||||
|
wk
|
||||||
|
bp
|
||||||
|
bn
|
||||||
|
bb
|
||||||
|
br
|
||||||
|
bq
|
||||||
|
bk
|
||||||
|
}
|
||||||
|
|
||||||
|
const unicode_piece_map = {
|
||||||
|
`.`: Pieces.empty
|
||||||
|
`♙`: Pieces.wp
|
||||||
|
`♘`: Pieces.wn
|
||||||
|
`♗`: Pieces.wb
|
||||||
|
`♖`: Pieces.wr
|
||||||
|
`♕`: Pieces.wq
|
||||||
|
`♔`: Pieces.wk
|
||||||
|
`♟`: Pieces.bp
|
||||||
|
`♞`: Pieces.bn
|
||||||
|
`♝`: Pieces.bb
|
||||||
|
`♜`: Pieces.br
|
||||||
|
`♛`: Pieces.bq
|
||||||
|
`♚`: Pieces.bk
|
||||||
|
`o`: Pieces.off
|
||||||
|
}
|
||||||
|
|
||||||
|
dump(unicode_piece_map)
|
@ -305,8 +305,11 @@ pub fn (mut p Parser) parse_language() ast.Language {
|
|||||||
// parse_inline_sum_type parses the type and registers it in case the type is an anonymous sum type.
|
// parse_inline_sum_type parses the type and registers it in case the type is an anonymous sum type.
|
||||||
// It also takes care of inline sum types where parse_type only parses a standalone type.
|
// It also takes care of inline sum types where parse_type only parses a standalone type.
|
||||||
pub fn (mut p Parser) parse_inline_sum_type() ast.Type {
|
pub fn (mut p Parser) parse_inline_sum_type() ast.Type {
|
||||||
p.warn('inline sum types have been deprecated and will be removed on January 1, 2023 due ' +
|
if !p.pref.is_fmt {
|
||||||
'to complicating the language and the compiler too much; define named sum types with `type Foo = Bar | Baz` instead')
|
p.warn(
|
||||||
|
'inline sum types have been deprecated and will be removed on January 1, 2023 due ' +
|
||||||
|
'to complicating the language and the compiler too much; define named sum types with `type Foo = Bar | Baz` instead')
|
||||||
|
}
|
||||||
variants := p.parse_sum_type_variants()
|
variants := p.parse_sum_type_variants()
|
||||||
if variants.len > 1 {
|
if variants.len > 1 {
|
||||||
if variants.len > parser.maximum_inline_sum_type_variants {
|
if variants.len > parser.maximum_inline_sum_type_variants {
|
||||||
|
Loading…
Reference in New Issue
Block a user