diff --git a/README.md b/README.md index 73a72c6c04..9ffe3baa1c 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ [![Twitter handle][]][Twitter badge] -**V's backend has just been replaced on April 1, 15k lines of code were removed, some things are broken, we are working hard to fix them all by April 4.** +**V's backend has just been replaced on April 1, 15k lines of code were removed, some things are broken, we are working hard to fix them all by April 5.** https://vlang.io diff --git a/cmd/tools/vfmt.v b/cmd/tools/vfmt.v index 97b4d099d5..41bb8f325f 100644 --- a/cmd/tools/vfmt.v +++ b/cmd/tools/vfmt.v @@ -43,10 +43,10 @@ const ( ) fn main() { - if os.getenv('VFMT_ENABLE') == '' { - eprintln('v fmt is disabled for now') - exit(1) - } + //if os.getenv('VFMT_ENABLE') == '' { + //eprintln('v fmt is disabled for now') + //exit(1) + //} toolexe := os.executable() util.set_vroot_folder(os.dir(os.dir(os.dir(toolexe)))) args := join_flags_and_argument() @@ -54,7 +54,7 @@ fn main() { is_2: '-2' in args is_c: '-c' in args is_l: '-l' in args - is_w: '-ww' in args + is_w: '-w' in args is_diff: '-diff' in args is_verbose: '-verbose' in args || '--verbose' in args is_all: '-all' in args || '--all' in args diff --git a/vlib/v/fmt/fmt.v b/vlib/v/fmt/fmt.v index da30981efe..4c4ab2f147 100644 --- a/vlib/v/fmt/fmt.v +++ b/vlib/v/fmt/fmt.v @@ -361,7 +361,7 @@ fn (f mut Fmt) expr(node ast.Expr) { match node { ast.ArrayInit { // `x := []string` - if it.exprs.len == 0 && it.typ != 0 { + if it.exprs.len == 0 && it.typ != 0 && it.typ != table.void_type { f.write(f.table.type_to_str(it.typ)) } // `[1,2,3]` @@ -420,7 +420,8 @@ fn (f mut Fmt) expr(node ast.Expr) { f.or_expr(it.or_block) } else { - f.write('${it.name}(') + name := short_module(it.name) + f.write('${name}(') f.call_args(it.args) f.write(')') f.or_expr(it.or_block) @@ -472,7 +473,8 @@ fn (f mut Fmt) expr(node ast.Expr) { f.write('_') } else { - f.write('$it.name') + name := short_module(it.name) + f.write(name) } } ast.InfixExpr { @@ -518,8 +520,8 @@ fn (f mut Fmt) expr(node ast.Expr) { f.writeln(' {') f.indent++ for i, branch in it.branches { - // normal branch if i < it.branches.len - 1 { + // normal branch for j, expr in branch.exprs { f.expr(expr) if j < branch.exprs.len - 1 { @@ -527,8 +529,8 @@ fn (f mut Fmt) expr(node ast.Expr) { } } } - // else branch else { + // else branch f.write('else') } if branch.stmts.len == 0 { @@ -602,12 +604,13 @@ fn (f mut Fmt) expr(node ast.Expr) { } ast.StructInit { type_sym := f.table.get_type_symbol(it.typ) + name := short_module(type_sym.name) // `Foo{}` on one line if there are no fields if it.fields.len == 0 { - f.write('$type_sym.name{}') + f.write('$name{}') } else { - f.writeln('$type_sym.name{') + f.writeln('$name{') for i, field in it.fields { f.write('\t$field: ') f.expr(it.exprs[i]) @@ -676,3 +679,15 @@ fn (f mut Fmt) comment(node ast.Comment) { } f.writeln('*/') } + +// foo.bar.fn() => bar.fn() +fn short_module(name string) string { + if !name.contains('.') { + return name + } + vals := name.split('.') + if vals.len < 2 { + return name + } + return vals[vals.len-2] + '.' + vals[vals.len-1] +} diff --git a/vlib/v/parser/parser.v b/vlib/v/parser/parser.v index e22d817d6c..c64aa88ed5 100644 --- a/vlib/v/parser/parser.v +++ b/vlib/v/parser/parser.v @@ -35,36 +35,24 @@ mut: is_amp bool returns bool - inside_match_case bool + inside_match_case bool // to separate `match_expr { }` from `Struct{}` comments []ast.Comment - // sdfsdfd - } - - //inside_match_case bool // to separate `match_expr { }` from `Struct{}` - // prefix_parse_fns []PrefixParseFn - // vars []string - - - - - // for tests pub fn parse_stmt(text string, table &table.Table, scope &ast.Scope) ast.Stmt { s := scanner.new_scanner(text, .skip_comments) - a := 324 mut p := Parser{ scanner: s table: table pref: &pref.Preferences{} scope: scope + // scope: &ast.Scope{start_pos: 0, parent: 0} global_scope: &ast.Scope{ start_pos: 0 parent: 0 } } - // scope: &ast.Scope{start_pos: 0, parent: 0} p.init_parse_fns() p.read_first_token() return p.stmt() diff --git a/vlib/v/table/atypes.v b/vlib/v/table/atypes.v index e0eeaa73e5..0f723211d2 100644 --- a/vlib/v/table/atypes.v +++ b/vlib/v/table/atypes.v @@ -612,6 +612,9 @@ pub fn (table &Table) type_to_str(t Type) string { if vals.len > 2 { res = vals[vals.len - 2] + '.' + vals[vals.len - 1] } + if sym.kind == .array { + res = '[]' + res + } } if type_is(t, .optional) { res = '?' + res