diff --git a/vlib/v/scanner/scanner.v b/vlib/v/scanner/scanner.v index 8e902e3c79..9c2fb59067 100644 --- a/vlib/v/scanner/scanner.v +++ b/vlib/v/scanner/scanner.v @@ -7,6 +7,7 @@ import os import v.token import v.pref import v.util +import v.errors const ( single_quote = `\'` @@ -45,6 +46,8 @@ pub mut: eofs int pref &pref.Preferences vet_errors []string + errors []errors.Error + warnings []errors.Warning } /* @@ -1186,21 +1189,39 @@ fn (mut s Scanner) inc_line_number() { } } -pub fn (s &Scanner) warn(msg string) { +pub fn (mut s Scanner) warn(msg string) { pos := token.Position{ line_nr: s.line_nr pos: s.pos } - eprintln(util.formatted_error('warning:', msg, s.file_path, pos)) + if s.pref.output_mode == .stdout { + eprintln(util.formatted_error('warning:', msg, s.file_path, pos)) + } else { + s.warnings << errors.Warning{ + file_path: s.file_path + pos: pos + reporter: .scanner + message: msg + } + } } -pub fn (s &Scanner) error(msg string) { +pub fn (mut s Scanner) error(msg string) { pos := token.Position{ line_nr: s.line_nr pos: s.pos } - eprintln(util.formatted_error('error:', msg, s.file_path, pos)) - exit(1) + if s.pref.output_mode == .stdout { + eprintln(util.formatted_error('error:', msg, s.file_path, pos)) + exit(1) + } else { + s.errors << errors.Error{ + file_path: s.file_path + pos: pos + reporter: .scanner + message: msg + } + } } fn (mut s Scanner) vet_error(msg string) {