1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

run vfmt on scanner.v

This commit is contained in:
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. // 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') 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_start_line := imax(0, (s.line_nr - error_context_before ))
context_end_line := imin(s.nlines-1, (s.line_nr + error_context_after + 1 )) context_end_line := imin(s.nlines-1, (s.line_nr + error_context_after + 1 ))
for cline := context_start_line; cline < context_end_line; cline++ { 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 { use_relative_paths := match verror_paths_override {
'relative' { true } 'relative' { true }
'absolute' { false } 'absolute' { false }
else { s.should_print_relative_paths_on_error } else { s.print_rel_paths_on_error }
} }
if use_relative_paths { if use_relative_paths {
workdir := os.getwd() + os.path_separator 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 { 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(){ 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') println('new_parser: V script')
} }
if p.pref.building_v { 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 { // if p.pref.generating_vh {
// Keep newlines // Keep newlines
@ -205,9 +205,9 @@ fn (v mut V) new_parser(scanner &Scanner) Parser {
p.is_js = true p.is_js = true
} }
if p.pref.is_repl { if p.pref.is_repl {
p.scanner.should_print_line_on_error = false p.scanner.print_line_on_error = false
p.scanner.should_print_errors_in_color = false p.scanner.print_colored_error = false
p.scanner.should_print_relative_paths_on_error = true p.scanner.print_rel_paths_on_error = true
} }
return p return p
} }
@ -942,7 +942,7 @@ fn (p mut Parser) get_type() string {
// fn type // fn type
if p.tok == .key_fn { if p.tok == .key_fn {
mut f := Fn{ mut f := Fn{
name: '_', name: '_'
mod: p.mod mod: p.mod
} }
p.next() p.next()
@ -2212,8 +2212,8 @@ fn (p mut Parser) index_expr(typ_ string,fn_ph int) string {
index_val := l[idx..].trim_space() index_val := l[idx..].trim_space()
p.cgen.resetln(l[..fn_ph]) p.cgen.resetln(l[..fn_ph])
p.table.varg_access << VargAccess{ p.table.varg_access << VargAccess{
fn_name: p.cur_fn.name, fn_name: p.cur_fn.name
tok_idx: index_error_tok_pos, tok_idx: index_error_tok_pos
index: index_val.int() index: index_val.int()
} }
p.cgen.set_placeholder(fn_ph, '${v.name}->args[$index_val]') 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) p.check_types(p.bool_expression(), f.typ)
if p.tok == .comma { if p.tok == .comma {
p.next() p.next()
p.fremove_last()
} }
if p.tok != .rcbr { if p.tok != .rcbr {
p.gen(',') p.gen(',')

View File

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