scanner: store errors and warnings on silent mode (#6883)

pull/6792/head
Ned Palacios 2020-11-20 17:44:19 +08:00 committed by GitHub
parent 159932d59b
commit b957c64905
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 26 additions and 5 deletions

View File

@ -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) {