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.
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')
// }
}

View File

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

View File

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

View File

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

View File

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

View File

@ -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')

View File

@ -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()

View File

@ -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