run vfmt on scanner.v

pull/3134/head
Alexander Medvednikov 2019-12-18 08:13:31 +03:00
parent 20e73ff69a
commit 81045023c4
7 changed files with 412 additions and 420 deletions

View File

@ -89,7 +89,7 @@ fn (s &Scanner) error_with_col(msg string, col int) {
// to find the source file, when the IDE has a different working folder than v itself.
eprintln('${fullpath}:${s.line_nr + 1}:${col}: $final_message')
if s.should_print_line_on_error && s.nlines > 0 {
if s.print_line_on_error && s.nlines > 0 {
context_start_line := imax(0, (s.line_nr - error_context_before ))
context_end_line := imin(s.nlines-1, (s.line_nr + error_context_after + 1 ))
for cline := context_start_line; cline < context_end_line; cline++ {
@ -130,7 +130,7 @@ fn (s &Scanner) get_error_filepath() string {
use_relative_paths := match verror_paths_override {
'relative' { true }
'absolute' { false }
else { s.should_print_relative_paths_on_error }
else { s.print_rel_paths_on_error }
}
if use_relative_paths {
workdir := os.getwd() + os.path_separator
@ -143,7 +143,7 @@ fn (s &Scanner) get_error_filepath() string {
}
fn (s &Scanner) is_color_output_on() bool {
return s.should_print_errors_in_color && term.can_show_color_on_stderr()
return s.print_colored_error && term.can_show_color_on_stderr()
}
fn (p mut Parser) print_error_context(){

View File

@ -172,7 +172,7 @@ fn (v mut V) new_parser_from_file(path string) Parser {
println('new_parser: V script')
}
if p.pref.building_v {
p.scanner.should_print_relative_paths_on_error = true
p.scanner.print_rel_paths_on_error = true
}
// if p.pref.generating_vh {
// Keep newlines
@ -205,9 +205,9 @@ fn (v mut V) new_parser(scanner &Scanner) Parser {
p.is_js = true
}
if p.pref.is_repl {
p.scanner.should_print_line_on_error = false
p.scanner.should_print_errors_in_color = false
p.scanner.should_print_relative_paths_on_error = true
p.scanner.print_line_on_error = false
p.scanner.print_colored_error = false
p.scanner.print_rel_paths_on_error = true
}
return p
}
@ -942,7 +942,7 @@ fn (p mut Parser) get_type() string {
// fn type
if p.tok == .key_fn {
mut f := Fn{
name: '_',
name: '_'
mod: p.mod
}
p.next()
@ -2212,8 +2212,8 @@ fn (p mut Parser) index_expr(typ_ string,fn_ph int) string {
index_val := l[idx..].trim_space()
p.cgen.resetln(l[..fn_ph])
p.table.varg_access << VargAccess{
fn_name: p.cur_fn.name,
tok_idx: index_error_tok_pos,
fn_name: p.cur_fn.name
tok_idx: index_error_tok_pos
index: index_val.int()
}
p.cgen.set_placeholder(fn_ph, '${v.name}->args[$index_val]')

File diff suppressed because it is too large Load Diff

View File

@ -315,6 +315,7 @@ fn (p mut Parser) struct_init(typ string) string {
p.check_types(p.bool_expression(), f.typ)
if p.tok == .comma {
p.next()
p.fremove_last()
}
if p.tok != .rcbr {
p.gen(',')

View File

@ -12,4 +12,4 @@ fn test_type_alias() {
}
}

View File

@ -161,8 +161,8 @@ fn (p mut Parser) fnext() {
if p.tokens[p.token_idx].tok in [.line_comment, .mline_comment] {
// Newline before the comment and after consts and closing }
if p.inside_const {
p.fgen_nl()
p.fgen_nl()
//p.fgen_nl()
//p.fgen_nl()
}
//is_rcbr := p.tok == .rcbr
for p.token_idx < p.tokens.len - 1 {
@ -218,6 +218,12 @@ fn (p mut Parser) fnext() {
}
}
[if vfmt]
fn (p mut Parser) fremove_last() {
p.scanner.fmt_lines[p.scanner.fmt_lines.len-1] = ''
}
[if vfmt]
fn (p &Parser) gen_fmt() {
@ -237,7 +243,7 @@ fn (p &Parser) gen_fmt() {
if s == '' {
return
}
if !p.file_name.contains('parser.v') {return}
if !p.file_name.contains('scanner.v') {return}
path := os.tmpdir() + '/' + p.file_name
println('generating ${path}')
mut out := os.create(path) or {

View File

@ -28,4 +28,4 @@ fn main() {
C.SDL_DestroyRenderer(renderer)
C.SDL_DestroyWindow(window)
C.SDL_Quit()
}
}