From 233ae3f772bbb01804643cb4182f516a83a7ccd3 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Tue, 14 Apr 2020 19:32:23 +0200 Subject: [PATCH] fmt: use `import module` syntax --- vlib/v/fmt/fmt.v | 17 ++++++------ vlib/v/fmt/tests/import_multiple_expected.vv | 6 ++--- .../import_multiple_with_alias_expected.vv | 6 ++--- vlib/v/fmt/tests/import_single_expected.vv | 4 +-- vlib/v/fmt/tests/missing_import_expected.vv | 4 +-- vlib/v/gen/cgen.v | 26 +++++++++---------- vlib/v/parser/fn.v | 10 +++---- vlib/v/parser/parser.v | 18 ++++++------- 8 files changed, 39 insertions(+), 52 deletions(-) diff --git a/vlib/v/fmt/fmt.v b/vlib/v/fmt/fmt.v index feb6e15537..8e2b79dd0c 100644 --- a/vlib/v/fmt/fmt.v +++ b/vlib/v/fmt/fmt.v @@ -3,11 +3,9 @@ // that can be found in the LICENSE file. module fmt -import ( - v.ast - v.table - strings -) +import v.ast +import v.table +import strings const ( tabs = ['', '\t', '\t\t', '\t\t\t', '\t\t\t\t', '\t\t\t\t\t', '\t\t\t\t\t\t', '\t\t\t\t\t\t\t'] @@ -109,16 +107,19 @@ fn (f mut Fmt) imports(imports []ast.Import) { f.out_imports.writeln('import ${imp_stmt_str}\n') } else if imports.len > 1 { */ - f.out_imports.writeln('import (') + // f.out_imports.writeln('import (') for imp in imports { if !(imp.mod in f.used_imports) { // TODO bring back once only unused imports are removed // continue } - f.out_imports.write('\t') + // f.out_imports.write('\t') + // f.out_imports.writeln(f.imp_stmt_str(imp)) + f.out_imports.write('import ') f.out_imports.writeln(f.imp_stmt_str(imp)) } - f.out_imports.writeln(')\n') + f.out_imports.writeln('') + // f.out_imports.writeln(')\n') // } } diff --git a/vlib/v/fmt/tests/import_multiple_expected.vv b/vlib/v/fmt/tests/import_multiple_expected.vv index 1fcc0a0244..5769710c0f 100644 --- a/vlib/v/fmt/tests/import_multiple_expected.vv +++ b/vlib/v/fmt/tests/import_multiple_expected.vv @@ -1,7 +1,5 @@ -import ( - math - os -) +import math +import os const ( mypi = math.pi diff --git a/vlib/v/fmt/tests/import_multiple_with_alias_expected.vv b/vlib/v/fmt/tests/import_multiple_with_alias_expected.vv index 3839113d42..e2ee3220ce 100644 --- a/vlib/v/fmt/tests/import_multiple_with_alias_expected.vv +++ b/vlib/v/fmt/tests/import_multiple_with_alias_expected.vv @@ -1,7 +1,5 @@ -import ( - os - math -) +import os +import math fn main() { // println(m.pi) diff --git a/vlib/v/fmt/tests/import_single_expected.vv b/vlib/v/fmt/tests/import_single_expected.vv index 31184f6790..6dd15c16de 100644 --- a/vlib/v/fmt/tests/import_single_expected.vv +++ b/vlib/v/fmt/tests/import_single_expected.vv @@ -1,6 +1,4 @@ -import ( - os -) +import os fn main() { } diff --git a/vlib/v/fmt/tests/missing_import_expected.vv b/vlib/v/fmt/tests/missing_import_expected.vv index 3e9a2f867c..c463392943 100644 --- a/vlib/v/fmt/tests/missing_import_expected.vv +++ b/vlib/v/fmt/tests/missing_import_expected.vv @@ -1,6 +1,4 @@ -import ( - time -) +import time fn main() { println(time.now()) diff --git a/vlib/v/gen/cgen.v b/vlib/v/gen/cgen.v index 07bb7c8fbd..344cbec0c5 100644 --- a/vlib/v/gen/cgen.v +++ b/vlib/v/gen/cgen.v @@ -3,16 +3,14 @@ // that can be found in the LICENSE file. module gen -import ( - strings - v.ast - v.table - v.pref - v.token - v.util - v.depgraph - term -) +import strings +import v.ast +import v.table +import v.pref +import v.token +import v.util +import v.depgraph +import term const ( c_reserved = ['delete', 'exit', 'unix', 'error', 'calloc', 'malloc', 'free', 'panic', 'auto', @@ -563,12 +561,12 @@ fn (g mut Gen) for_in(it ast.ForInStmt) { i := if it.key_var == '' { g.new_tmp_var() } else { it.key_var } if cond_type_is_ptr { g.writeln('for (int $i = 0; $i < ${atmp}->len; $i++) {') - }else{ + } else { g.writeln('for (int $i = 0; $i < ${atmp}.len; $i++) {') } if cond_type_is_ptr { g.writeln('\t$styp $it.val_var = (($styp*)${atmp}->data)[$i];') - }else{ + } else { g.writeln('\t$styp $it.val_var = (($styp*)${atmp}.data)[$i];') } g.stmts(it.stmts) @@ -2200,8 +2198,8 @@ fn (g mut Gen) string_inter_literal(node ast.StringInterLiteral) { verror('only V strings can be formatted with a ${sfmt} format') } g.write('%' + sfmt[1..]) - } else if node.expr_types[i] in [table.string_type, table.bool_type] || - sym.kind in [.enum_, .array, .array_fixed] { + } else if node.expr_types[i] in [table.string_type, table.bool_type] || sym.kind in + [.enum_, .array, .array_fixed] { g.write('%.*s') } else if node.expr_types[i] in [table.f32_type, table.f64_type] { g.write('%f') diff --git a/vlib/v/parser/fn.v b/vlib/v/parser/fn.v index a74c0b1f47..0786ca882d 100644 --- a/vlib/v/parser/fn.v +++ b/vlib/v/parser/fn.v @@ -3,12 +3,10 @@ // that can be found in the LICENSE file. module parser -import ( - v.ast - v.table - v.scanner - v.token -) +import v.ast +import v.table +import v.scanner +import v.token pub fn (p mut Parser) call_expr(is_c bool, mod string) ast.CallExpr { first_pos := p.tok.position() diff --git a/vlib/v/parser/parser.v b/vlib/v/parser/parser.v index 798db4426c..d7368313db 100644 --- a/vlib/v/parser/parser.v +++ b/vlib/v/parser/parser.v @@ -3,16 +3,14 @@ // that can be found in the LICENSE file. module parser -import ( - v.scanner - v.ast - v.token - v.table - v.pref - v.util - term - os -) +import v.scanner +import v.ast +import v.token +import v.table +import v.pref +import v.util +import term +import os struct Parser { scanner &scanner.Scanner