vfmt: minor fixes

pull/3157/head
Alexander Medvednikov 2019-12-19 05:41:12 +03:00
parent aa0ad9d922
commit 519f2990f2
5 changed files with 51 additions and 39 deletions

View File

@ -199,8 +199,8 @@ fn (p mut Parser) comp_time() {
fn (p mut Parser) chash() {
hash := p.lit.trim_space()
// println('chsh() file=$p.file hash="$hash"')
p.fgen_nl()
p.next()
p.fgen_nl()
if hash.starts_with('flag ') {
if p.first_pass() {
mut flag := hash[5..]

View File

@ -3,6 +3,8 @@
// that can be found in the LICENSE file.
module compiler
import (
strings
)
@ -1655,3 +1657,4 @@ pub fn (f &Fn) str_for_error() string {
}
return s + ')'
}

View File

@ -3,6 +3,8 @@
// that can be found in the LICENSE file.
module compiler
import (
os
strings
@ -464,6 +466,7 @@ fn (p mut Parser) parse(pass Pass) {
}
}
.key_pub {
p.fspace()
next := p.peek()
match next {
.key_fn {

View File

@ -24,11 +24,12 @@ fn (scanner mut Scanner) fgen(s_ string) {
[if vfmt]
fn (scanner mut Scanner) fgenln(s_ string) {
mut s := s_//.trim_space()
mut s := s_.trim_right(' ')
if scanner.fmt_line_empty && scanner.fmt_indent > 0 {
s = strings.repeat(`\t`, scanner.fmt_indent) + s
}
scanner.fmt_lines << s
//println('s="$s"')
//scanner.fmt_lines << '//!'
scanner.fmt_lines << '\n'
//scanner.fmt_out.writeln(s)
@ -235,15 +236,21 @@ fn (p &Parser) gen_fmt() {
}
//s := p.scanner.fmt_out.str().replace('\n\n\n', '\n').trim_space()
//s := p.scanner.fmt_out.str().trim_space()
s := p.scanner.fmt_lines.join('').trim_space().replace_each([
//p.scanner.fgenln('// nice')
s := p.scanner.fmt_lines.join('')/*.replace_each([
'\n\n\n\n', '\n\n',
' \n', '\n',
') or{', ') or {',
])
*/
//.replace('\n\n\n\n', '\n\n')
.replace(' \n', '\n')
.replace(') or{', ') or {')
if s == '' {
return
}
//if !p.file_name.contains('float.v') {return}
if !p.file_path.contains('fn.v') {return}
path := os.tmpdir() + '/' + p.file_name
println('generating ${path}')
mut out := os.create(path) or {
@ -251,7 +258,8 @@ fn (p &Parser) gen_fmt() {
return
}
println('replacing ${p.file_path}...\n')
out.writeln(s)//p.scanner.fmt_out.str().trim_space())
out.writeln(s.trim_space())//p.scanner.fmt_out.str().trim_space())
out.writeln('')
out.close()
os.mv(path, p.file_path)
}

View File

@ -1,20 +1,20 @@
module os
// (Must be realized in Syscall) (Must be specified)
// File modes.
const (
O_RDONLY = 1 // open the file read-only.
O_WRONLY = 2 // open the file write-only.
O_RDWR = 3 // open the file read-write.
O_APPEND = 8 // append data to the file when writing.
O_CREATE = 16 // create a new file if none exists.
O_EXCL = 32 // used with O_CREATE, file must not exist.
O_SYNC = 64 // open for synchronous I/O.
O_TRUNC = 128 // truncate regular writable file when opened.
)
// ref: http://www.ccfit.nsu.ru/~deviv/courses/unix/unix/ng7c229.html
const (
S_IFMT = 0xF000 // type of file
@ -28,5 +28,3 @@ const(
STD_ERROR_HANDLE = -12
)