@@ -2,31 +2,27 @@ use ariadne::{Label, Report, ReportKind, Source};
2
2
use clap:: Command ;
3
3
use colorful:: Colorful ;
4
4
use lento_core:: {
5
- interpreter:: error:: RuntimeError , lexer:: lexer:: InputSource , parser:: error:: ParseError ,
6
- type_checker:: checker:: TypeError , util:: error:: BaseError ,
5
+ interpreter:: error:: RuntimeError ,
6
+ lexer:: lexer:: InputSource ,
7
+ parser:: error:: ParseError ,
8
+ type_checker:: checker:: TypeError ,
9
+ util:: error:: { BaseError , BaseErrorExt } ,
7
10
} ;
8
11
9
12
pub fn print_parse_error ( err : ParseError , content : & str , source : & InputSource ) {
10
- // print_error_simple("parse error", err.message);
11
- // print_error_simple_at(err.info, source)
12
- print_error_report ( "parse error" , err. inner , content, source) ;
13
+ print_error_report ( "parse error" , err. to_base ( ) , content, source) ;
13
14
}
14
15
15
16
pub fn print_runtime_error ( err : RuntimeError , content : & str , source : & InputSource ) {
16
- // print_error_simple("runtime error", err.message);
17
- // print_error_simple_at(err.info, source)
18
- print_error_report ( "runtime error" , err. inner , content, source) ;
17
+ print_error_report ( "runtime error" , err. to_base ( ) , content, source) ;
19
18
}
20
19
21
20
pub fn print_type_error ( err : TypeError , content : & str , source : & InputSource ) {
22
- // print_error_simple("type error", err.message);
23
- // print_error_simple_at(err.info, source)
24
- print_error_report ( "type error" , err. inner , content, source) ;
21
+ print_error_report ( "type error" , err. to_base ( ) , content, source) ;
25
22
}
26
23
27
24
pub fn print_error_report ( kind : & str , base : BaseError , content : & str , source : & InputSource ) {
28
25
let mut colors = ariadne:: ColorGenerator :: new ( ) ;
29
-
30
26
let mut report = Report :: build (
31
27
ReportKind :: Custom ( kind, ariadne:: Color :: BrightRed ) ,
32
28
( source. name ( ) , base. info . start . index ..base. info . end . index ) ,
@@ -71,21 +67,6 @@ pub fn print_error_simple(kind: &str, msg: String) {
71
67
println ! ( "{}: {}" , kind. light_red( ) , msg) ;
72
68
}
73
69
74
- // pub fn print_error_simple_at(info: LineInfo, source: &InputSource) {
75
- // let msg = match info.end.eof {
76
- // true => format!("line {}:{} to end of", info.start.line, info.start.column),
77
- // false if info.start.line == info.end.line => format!(
78
- // "line {}:{} to {}",
79
- // info.start.line, info.start.column, info.end.column
80
- // ),
81
- // false => format!(
82
- // "line {}:{} to line {}:{} in",
83
- // info.start.line, info.start.column, info.end.line, info.end.column
84
- // ),
85
- // };
86
- // print_error_simple("└─ at", format!("{} {}\n", msg, source.human_readable()));
87
- // }
88
-
89
70
pub fn print_error ( msg : String ) {
90
71
print_error_simple ( "error" , msg)
91
72
}
0 commit comments