mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
fix a bug in strings.Builder and wrap up vfmt
This commit is contained in:
@ -76,7 +76,7 @@ fn new_scanner_file(file_path string) &Scanner {
|
||||
fn new_scanner(text string) &Scanner {
|
||||
return &Scanner {
|
||||
text: text
|
||||
fmt_out: strings.new_builder(10000)
|
||||
fmt_out: strings.new_builder(1000)
|
||||
should_print_line_on_error: true
|
||||
should_print_errors_in_color: true
|
||||
should_print_relative_paths_on_error: true
|
||||
|
@ -238,7 +238,6 @@ fn (p mut Parser) struct_init(typ string) string {
|
||||
p.warn('type `$t.name` is private')
|
||||
}
|
||||
if p.gen_struct_init(typ, t) { return typ }
|
||||
p.scanner.fmt_out.cut(typ.len)
|
||||
ptr := typ.contains('*')
|
||||
mut did_gen_something := false
|
||||
// Loop thru all struct init keys and assign values
|
||||
|
@ -13,6 +13,8 @@ fn (scanner mut Scanner) fgen(s_ string) {
|
||||
if scanner.fmt_line_empty {
|
||||
s = strings.repeat(`\t`, scanner.fmt_indent) + s
|
||||
}
|
||||
|
||||
//scanner.fmt_out << s
|
||||
scanner.fmt_out.write(s)
|
||||
scanner.fmt_line_empty = false
|
||||
}
|
||||
@ -23,6 +25,8 @@ fn (scanner mut Scanner) fgenln(s_ string) {
|
||||
if scanner.fmt_line_empty {
|
||||
s = strings.repeat(`\t`, scanner.fmt_indent) + s
|
||||
}
|
||||
//scanner.fmt_out << s
|
||||
//scanner.fmt_out << '\n'
|
||||
scanner.fmt_out.writeln(s)
|
||||
scanner.fmt_line_empty = true
|
||||
}
|
||||
@ -111,6 +115,7 @@ fn (p mut Parser) fnext() {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[if vfmt]
|
||||
fn (p mut Parser) gen_fmt() {
|
||||
if p.pass != .main {
|
||||
@ -120,6 +125,7 @@ fn (p mut Parser) gen_fmt() {
|
||||
return
|
||||
}
|
||||
s := p.scanner.fmt_out.str().trim_space()
|
||||
//s := p.scanner.fmt_out.join('').trim_space()
|
||||
if s == '' {
|
||||
return
|
||||
}
|
||||
@ -128,8 +134,7 @@ fn (p mut Parser) gen_fmt() {
|
||||
verror('failed to create fmt.v')
|
||||
return
|
||||
}
|
||||
//println(p.scanner.fmt_out.str())
|
||||
out.writeln(p.scanner.fmt_out.str().trim_space())
|
||||
out.writeln(s)//p.scanner.fmt_out.str().trim_space())
|
||||
out.close()
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user