vv: make warns/errors usable in emacs/vim
parent
7882312697
commit
7bf49aba54
|
@ -19,6 +19,8 @@ fn test_c_files() {
|
||||||
println('Running V => C tests')
|
println('Running V => C tests')
|
||||||
vexe := os.getenv('VEXE')
|
vexe := os.getenv('VEXE')
|
||||||
vroot := filepath.dir(vexe)
|
vroot := filepath.dir(vexe)
|
||||||
|
term_ok := term.ok_message('OK')
|
||||||
|
term_fail := term.fail_message('FAIL')
|
||||||
for i in 1 .. nr_tests + 1 {
|
for i in 1 .. nr_tests + 1 {
|
||||||
path := '$vroot/vlib/v/gen/tests/${i}.vv'
|
path := '$vroot/vlib/v/gen/tests/${i}.vv'
|
||||||
ctext := os.read_file('$vroot/vlib/v/gen/tests/${i}.c') or {
|
ctext := os.read_file('$vroot/vlib/v/gen/tests/${i}.c') or {
|
||||||
|
@ -28,12 +30,11 @@ fn test_c_files() {
|
||||||
program := parser.parse_file(path, table)
|
program := parser.parse_file(path, table)
|
||||||
res := gen.cgen([program], table)
|
res := gen.cgen([program], table)
|
||||||
if compare_texts(res, ctext) {
|
if compare_texts(res, ctext) {
|
||||||
eprintln('${i}... ' + term.green('OK'))
|
eprintln('${term_ok} ${i}')
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
eprintln('${i}... ' + term.red('FAIL'))
|
eprintln('${term_fail} ${i}')
|
||||||
eprintln(path)
|
eprintln('${path}: got\n{$res}')
|
||||||
eprintln('got:\n$res')
|
|
||||||
assert false
|
assert false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,9 @@ import (
|
||||||
term
|
term
|
||||||
os
|
os
|
||||||
)
|
)
|
||||||
|
const (
|
||||||
|
colored_output = term.can_show_color_on_stderr()
|
||||||
|
)
|
||||||
|
|
||||||
type PrefixParseFn fn()ast.Expr
|
type PrefixParseFn fn()ast.Expr
|
||||||
|
|
||||||
|
@ -249,17 +252,32 @@ pub fn (p mut Parser) assign_stmt() ast.AssignStmt {
|
||||||
|
|
||||||
pub fn (p &Parser) error(s string) {
|
pub fn (p &Parser) error(s string) {
|
||||||
print_backtrace()
|
print_backtrace()
|
||||||
println(term.bold(term.red('$p.file_name:$p.tok.line_nr: $s')))
|
final_msg_line := '$p.file_name:$p.tok.line_nr: error: $s'
|
||||||
|
if colored_output {
|
||||||
|
eprintln(term.bold(term.red(final_msg_line)))
|
||||||
|
}else{
|
||||||
|
eprintln(final_msg_line)
|
||||||
|
}
|
||||||
exit(1)
|
exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (p &Parser) error_at_line(s string, line_nr int) {
|
pub fn (p &Parser) error_at_line(s string, line_nr int) {
|
||||||
println(term.bold(term.red('$p.file_name:$line_nr: $s')))
|
final_msg_line := '$p.file_name:$line_nr: error: $s'
|
||||||
|
if colored_output {
|
||||||
|
eprintln(term.bold(term.red(final_msg_line)))
|
||||||
|
}else{
|
||||||
|
eprintln(final_msg_line)
|
||||||
|
}
|
||||||
exit(1)
|
exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (p &Parser) warn(s string) {
|
pub fn (p &Parser) warn(s string) {
|
||||||
println(term.blue('$p.file_name:$p.tok.line_nr: $s'))
|
final_msg_line := '$p.file_name:$p.tok.line_nr: warning: $s'
|
||||||
|
if colored_output {
|
||||||
|
eprintln(term.bold(term.blue(final_msg_line)))
|
||||||
|
}else{
|
||||||
|
eprintln(final_msg_line)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (p mut Parser) name_expr() (ast.Expr,types.TypeIdent) {
|
pub fn (p mut Parser) name_expr() (ast.Expr,types.TypeIdent) {
|
||||||
|
|
|
@ -245,7 +245,8 @@ pub fn (t mut Table) register_type(typ types.Type, name string, idx int) {
|
||||||
}
|
}
|
||||||
t.type_idxs[name] = idx
|
t.type_idxs[name] = idx
|
||||||
t.types << typ
|
t.types << typ
|
||||||
t.methods << []Fn // TODO [] breaks V
|
efn := []Fn
|
||||||
|
t.methods << efn // TODO [] breaks V
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (t mut Table) register_struct(typ types.Struct) int {
|
pub fn (t mut Table) register_struct(typ types.Struct) int {
|
||||||
|
|
Loading…
Reference in New Issue