fmt: use `import module` syntax

pull/4410/head
Alexander Medvednikov 2020-04-14 19:32:23 +02:00
parent 2251634743
commit 233ae3f772
8 changed files with 39 additions and 52 deletions

View File

@ -3,11 +3,9 @@
// that can be found in the LICENSE file. // that can be found in the LICENSE file.
module fmt module fmt
import ( import v.ast
v.ast import v.table
v.table import strings
strings
)
const ( 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'] 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') f.out_imports.writeln('import ${imp_stmt_str}\n')
} else if imports.len > 1 { } else if imports.len > 1 {
*/ */
f.out_imports.writeln('import (') // f.out_imports.writeln('import (')
for imp in imports { for imp in imports {
if !(imp.mod in f.used_imports) { if !(imp.mod in f.used_imports) {
// TODO bring back once only unused imports are removed // TODO bring back once only unused imports are removed
// continue // 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(f.imp_stmt_str(imp))
} }
f.out_imports.writeln(')\n') f.out_imports.writeln('')
// f.out_imports.writeln(')\n')
// } // }
} }

View File

@ -1,7 +1,5 @@
import ( import math
math import os
os
)
const ( const (
mypi = math.pi mypi = math.pi

View File

@ -1,7 +1,5 @@
import ( import os
os import math
math
)
fn main() { fn main() {
// println(m.pi) // println(m.pi)

View File

@ -1,6 +1,4 @@
import ( import os
os
)
fn main() { fn main() {
} }

View File

@ -1,6 +1,4 @@
import ( import time
time
)
fn main() { fn main() {
println(time.now()) println(time.now())

View File

@ -3,16 +3,14 @@
// that can be found in the LICENSE file. // that can be found in the LICENSE file.
module gen module gen
import ( import strings
strings import v.ast
v.ast import v.table
v.table import v.pref
v.pref import v.token
v.token import v.util
v.util import v.depgraph
v.depgraph import term
term
)
const ( const (
c_reserved = ['delete', 'exit', 'unix', 'error', 'calloc', 'malloc', 'free', 'panic', 'auto', 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 } i := if it.key_var == '' { g.new_tmp_var() } else { it.key_var }
if cond_type_is_ptr { if cond_type_is_ptr {
g.writeln('for (int $i = 0; $i < ${atmp}->len; $i++) {') g.writeln('for (int $i = 0; $i < ${atmp}->len; $i++) {')
}else{ } else {
g.writeln('for (int $i = 0; $i < ${atmp}.len; $i++) {') g.writeln('for (int $i = 0; $i < ${atmp}.len; $i++) {')
} }
if cond_type_is_ptr { if cond_type_is_ptr {
g.writeln('\t$styp $it.val_var = (($styp*)${atmp}->data)[$i];') 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.writeln('\t$styp $it.val_var = (($styp*)${atmp}.data)[$i];')
} }
g.stmts(it.stmts) 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') verror('only V strings can be formatted with a ${sfmt} format')
} }
g.write('%' + sfmt[1..]) g.write('%' + sfmt[1..])
} else if node.expr_types[i] in [table.string_type, table.bool_type] || } else if node.expr_types[i] in [table.string_type, table.bool_type] || sym.kind in
sym.kind in [.enum_, .array, .array_fixed] { [.enum_, .array, .array_fixed] {
g.write('%.*s') g.write('%.*s')
} else if node.expr_types[i] in [table.f32_type, table.f64_type] { } else if node.expr_types[i] in [table.f32_type, table.f64_type] {
g.write('%f') g.write('%f')

View File

@ -3,12 +3,10 @@
// that can be found in the LICENSE file. // that can be found in the LICENSE file.
module parser module parser
import ( import v.ast
v.ast import v.table
v.table import v.scanner
v.scanner import v.token
v.token
)
pub fn (p mut Parser) call_expr(is_c bool, mod string) ast.CallExpr { pub fn (p mut Parser) call_expr(is_c bool, mod string) ast.CallExpr {
first_pos := p.tok.position() first_pos := p.tok.position()

View File

@ -3,16 +3,14 @@
// that can be found in the LICENSE file. // that can be found in the LICENSE file.
module parser module parser
import ( import v.scanner
v.scanner import v.ast
v.ast import v.token
v.token import v.table
v.table import v.pref
v.pref import v.util
v.util import term
term import os
os
)
struct Parser { struct Parser {
scanner &scanner.Scanner scanner &scanner.Scanner