vfmt: re-write V files + fix {}

pull/3130/head
Alexander Medvednikov 2019-12-18 04:18:53 +03:00
parent 53b334145b
commit ad211a86a6
1 changed files with 8 additions and 5 deletions

View File

@ -141,7 +141,7 @@ fn (p mut Parser) fnext() {
//println('eof ret') //println('eof ret')
//return //return
//} //}
if p.tok == .rcbr && !p.inside_if_expr && p.prev_tok != .lcbr { if p.tok == .rcbr && !p.inside_if_expr { //&& p.prev_tok != .lcbr {
p.fmt_dec() p.fmt_dec()
} }
s := p.strtok() s := p.strtok()
@ -150,7 +150,7 @@ fn (p mut Parser) fnext() {
} }
// vfmt: increase indentation on `{` unless it's `{}` // vfmt: increase indentation on `{` unless it's `{}`
inc_indent := false inc_indent := false
if p.tok == .lcbr && !p.inside_if_expr && p.peek() != .rcbr { if p.tok == .lcbr && !p.inside_if_expr {// && p.peek() != .rcbr {
p.fgen_nl() p.fgen_nl()
p.fmt_inc() p.fmt_inc()
} }
@ -231,12 +231,15 @@ fn (p &Parser) gen_fmt() {
if s == '' { if s == '' {
return return
} }
//if !p.file_name.contains('parser.v') {return} if !p.file_name.contains('parser.v') {return}
println('generating ${p.file_name}') path := os.tmpdir() + '/' + p.file_name
mut out := os.create('/var/tmp/fmt/' + p.file_name) or { println('generating ${path}')
mut out := os.create(path) or {
verror('failed to create fmt.v') verror('failed to create fmt.v')
return return
} }
println('replacing ${p.file_path}...')
os.mv(path, p.file_path)
out.writeln(s)//p.scanner.fmt_out.str().trim_space()) out.writeln(s)//p.scanner.fmt_out.str().trim_space())
out.close() out.close()
} }