small vfmt fixes

pull/3182/head
Alexander Medvednikov 2019-12-22 01:27:03 +03:00
parent 749d3ec14d
commit b76227b781
4 changed files with 17 additions and 7 deletions

View File

@ -36,7 +36,7 @@ TCCREPO := https://github.com/vlang/tccbin_win
VCFILE := v_win.c VCFILE := v_win.c
endif endif
all: latest_vc all: latest_vc latest_tcc
ifdef WIN32 ifdef WIN32
$(CC) -std=c99 -w -o v0.exe $(TMPVC)/$(VCFILE) $(LDFLAGS) $(CC) -std=c99 -w -o v0.exe $(TMPVC)/$(VCFILE) $(LDFLAGS)
./v0.exe -o v.exe v.v ./v0.exe -o v.exe v.v

View File

@ -586,6 +586,7 @@ fn (p mut Parser) parse(pass Pass) {
for i := start; i < end; i++ { for i := start; i < end; i++ {
p.cgen.lines[i] = '' p.cgen.lines[i] = ''
} }
p.fgen_nl()
} }
else { else {
p.error('unexpected token `${p.strtok()}`') p.error('unexpected token `${p.strtok()}`')
@ -793,6 +794,9 @@ fn (p mut Parser) type_decl() {
cat: .alias cat: .alias
is_public: is_pub is_public: is_pub
}) })
if p.tok != .key_type {
p.fspace()
}
} }
// current token is `(` // current token is `(`

View File

@ -81,6 +81,7 @@ fn (p mut Parser) fgen_nl() {
// Previous token is a comment, and NL has already been generated? // Previous token is a comment, and NL has already been generated?
// Don't generate a second NL. // Don't generate a second NL.
if p.scanner.fmt_lines.len > 0 && p.scanner.fmt_lines.last() == '\n' && if p.scanner.fmt_lines.len > 0 && p.scanner.fmt_lines.last() == '\n' &&
p.token_idx > 2 &&
p.tokens[p.token_idx-2].tok == .line_comment p.tokens[p.token_idx-2].tok == .line_comment
{ {
//if p.fileis('parser.v') { //if p.fileis('parser.v') {
@ -231,21 +232,26 @@ fn (p &Parser) gen_fmt() {
if p.pass != .main { if p.pass != .main {
return return
} }
//println('gen fmt name=$p.file_name path=$p.file_path')
if p.file_name == '' { if p.file_name == '' {
return return
} }
//s := p.scanner.fmt_out.str().replace('\n\n\n', '\n').trim_space() //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_out.str().trim_space()
//p.scanner.fgenln('// nice') //p.scanner.fgenln('// nice')
s := p.scanner.fmt_lines.join('')/*.replace_each([ s := p.scanner.fmt_lines.join('')
/*.replace_each([
'\n\n\n\n', '\n\n', '\n\n\n\n', '\n\n',
' \n', '\n', ' \n', '\n',
') or{', ') or {', ') or{', ') or {',
]) ])
*/ */
//.replace('\n\n\n\n', '\n\n') //.replace('\n\n\n\n', '\n\n')
.replace(' \n', '\n') .replace_each([
.replace(') or{', ') or {') ' \n', '\n',
') or{', ') or {',
')or{', ') or {',
] )
if s == '' { if s == '' {
return return