mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
lots of vfmt fixes
This commit is contained in:
@ -6,7 +6,6 @@ module compiler
|
||||
|
||||
import strings
|
||||
|
||||
// fmt helpers
|
||||
[if vfmt]
|
||||
fn (scanner mut Scanner) fgen(s_ string) {
|
||||
mut s := s_
|
||||
@ -27,18 +26,36 @@ fn (scanner mut Scanner) fgenln(s_ string) {
|
||||
scanner.fmt_line_empty = true
|
||||
}
|
||||
|
||||
|
||||
[if vfmt]
|
||||
fn (p mut Parser) fgen(s string) {
|
||||
}
|
||||
[if vfmt]
|
||||
fn (p mut Parser) fgen2(s string) {
|
||||
if p.pass != .main {
|
||||
return
|
||||
}
|
||||
p.scanner.fgen(s)
|
||||
}
|
||||
|
||||
[if vfmt]
|
||||
fn (p mut Parser) fspace() {
|
||||
p.fgen(' ')
|
||||
if p.first_pass() {
|
||||
return
|
||||
}
|
||||
p.fgen2(' ')
|
||||
}
|
||||
|
||||
|
||||
[if vfmt]
|
||||
fn (p mut Parser) fgenln(s string) {
|
||||
}
|
||||
|
||||
[if vfmt]
|
||||
fn (p mut Parser) fgenln2(s string) {
|
||||
if p.pass != .main {
|
||||
return
|
||||
}
|
||||
p.scanner.fgenln(s)
|
||||
}
|
||||
|
||||
@ -57,11 +74,33 @@ fn (p mut Parser) peek() TokenKind {
|
||||
|
||||
[if vfmt]
|
||||
fn (p mut Parser) fmt_inc() {
|
||||
if p.pass != .main {
|
||||
return
|
||||
}
|
||||
p.scanner.fmt_indent++
|
||||
}
|
||||
|
||||
[if vfmt]
|
||||
fn (p mut Parser) fmt_dec() {
|
||||
if p.pass != .main {
|
||||
return
|
||||
}
|
||||
p.scanner.fmt_indent--
|
||||
}
|
||||
|
||||
[if vfmt]
|
||||
fn (p mut Parser) fnext() {
|
||||
if p.tok == .eof {
|
||||
return
|
||||
}
|
||||
if p.tok == .rcbr {
|
||||
p.fmt_dec()
|
||||
}
|
||||
p.fgen2(p.strtok())
|
||||
// vfmt: increase indentation on `{` unless it's `{}`
|
||||
if p.tok == .lcbr { //&& p.scanner.pos + 1 < p.scanner.text.len && p.scanner.text[p.scanner.pos + 1] != `}` {
|
||||
p.fgenln2('')
|
||||
p.fmt_inc()
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user