2019-07-29 19:21:36 +03:00
|
|
|
// Copyright (c) 2019 Alexander Medvednikov. All rights reserved.
|
|
|
|
// Use of this source code is governed by an MIT license
|
|
|
|
// that can be found in the LICENSE file.
|
|
|
|
|
2019-08-17 22:19:37 +03:00
|
|
|
module main
|
2019-07-29 19:21:36 +03:00
|
|
|
|
2019-08-17 22:19:37 +03:00
|
|
|
import strings
|
2019-07-29 19:21:36 +03:00
|
|
|
|
|
|
|
// fmt helpers
|
2019-08-07 09:19:27 +03:00
|
|
|
fn (scanner mut Scanner) fgen(s_ string) {
|
2019-08-17 22:19:37 +03:00
|
|
|
mut s := s_
|
2019-07-29 19:21:36 +03:00
|
|
|
if scanner.fmt_line_empty {
|
|
|
|
s = strings.repeat(`\t`, scanner.fmt_indent) + s
|
|
|
|
}
|
|
|
|
scanner.fmt_out.write(s)
|
|
|
|
scanner.fmt_line_empty = false
|
|
|
|
}
|
|
|
|
|
2019-08-07 09:19:27 +03:00
|
|
|
fn (scanner mut Scanner) fgenln(s_ string) {
|
2019-08-17 22:19:37 +03:00
|
|
|
mut s := s_
|
2019-07-29 19:21:36 +03:00
|
|
|
if scanner.fmt_line_empty {
|
|
|
|
s = strings.repeat(`\t`, scanner.fmt_indent) + s
|
|
|
|
}
|
|
|
|
scanner.fmt_out.writeln(s)
|
|
|
|
scanner.fmt_line_empty = true
|
|
|
|
}
|
|
|
|
|
|
|
|
fn (p mut Parser) fgen(s string) {
|
|
|
|
p.scanner.fgen(s)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn (p mut Parser) fspace() {
|
|
|
|
p.fgen(' ')
|
|
|
|
}
|
|
|
|
|
|
|
|
fn (p mut Parser) fgenln(s string) {
|
|
|
|
p.scanner.fgenln(s)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn (p mut Parser) peek() Token {
|
|
|
|
for {
|
2019-08-04 12:00:56 +03:00
|
|
|
p.cgen.line = p.scanner.line_nr + 1
|
2019-07-29 19:21:36 +03:00
|
|
|
tok := p.scanner.peek()
|
|
|
|
if tok != .nl {
|
|
|
|
return tok
|
|
|
|
}
|
|
|
|
}
|
2019-08-08 10:49:56 +03:00
|
|
|
return .eof // TODO can never get here - v doesn't know that
|
2019-07-29 19:21:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
fn (p mut Parser) fmt_inc() {
|
|
|
|
p.scanner.fmt_indent++
|
|
|
|
}
|
|
|
|
|
|
|
|
fn (p mut Parser) fmt_dec() {
|
|
|
|
p.scanner.fmt_indent--
|
|
|
|
}
|
|
|
|
|