@@ -4,11 +4,11 @@ import syntax::codemap;
4
4
import codemap:: span;
5
5
6
6
export emitter, emit_diagnostic;
7
- export diagnostictype , fatal, error, warning, note;
7
+ export level , fatal, error, warning, note;
8
8
export handler, mk_codemap_handler;
9
9
10
10
type emitter = fn @( cmsp : option < ( codemap:: codemap , span ) > ,
11
- msg : str , t : diagnostictype ) ;
11
+ msg : str , lvl : level ) ;
12
12
13
13
14
14
iface handler {
@@ -88,7 +88,7 @@ fn mk_codemap_handler(cm: codemap::codemap,
88
88
some( e) { e }
89
89
none. {
90
90
let f = fn @( cmsp: option<( codemap:: codemap, span) >,
91
- msg: str, t: diagnostictype ) {
91
+ msg: str, t: level ) {
92
92
emit_diagnostic ( cmsp, msg, t) ;
93
93
} ;
94
94
f
@@ -102,56 +102,56 @@ fn mk_codemap_handler(cm: codemap::codemap,
102
102
} as handler
103
103
}
104
104
105
- tag diagnostictype {
105
+ tag level {
106
106
fatal;
107
107
error;
108
108
warning;
109
109
note;
110
110
}
111
111
112
- fn diagnosticstr ( t : diagnostictype ) -> str {
113
- alt t {
112
+ fn diagnosticstr ( lvl : level ) -> str {
113
+ alt lvl {
114
114
fatal. { "error" }
115
115
error. { "error" }
116
116
warning. { "warning" }
117
117
note. { "note" }
118
118
}
119
119
}
120
120
121
- fn diagnosticcolor ( t : diagnostictype ) -> u8 {
122
- alt t {
121
+ fn diagnosticcolor ( lvl : level ) -> u8 {
122
+ alt lvl {
123
123
fatal. { term : : color_bright_red }
124
124
error. { term:: color_bright_red }
125
125
warning. { term:: color_bright_yellow }
126
126
note. { term:: color_bright_green }
127
127
}
128
128
}
129
129
130
- fn print_diagnostic ( topic : str , t : diagnostictype , msg : str ) {
130
+ fn print_diagnostic ( topic : str , lvl : level , msg : str ) {
131
131
if str:: is_not_empty ( topic) {
132
132
io:: stdout ( ) . write_str ( #fmt[ "%s " , topic] ) ;
133
133
}
134
134
if term:: color_supported ( ) {
135
- term:: fg ( io:: stdout ( ) , diagnosticcolor ( t ) ) ;
135
+ term:: fg ( io:: stdout ( ) , diagnosticcolor ( lvl ) ) ;
136
136
}
137
- io:: stdout ( ) . write_str ( #fmt[ "%s:" , diagnosticstr ( t ) ] ) ;
137
+ io:: stdout ( ) . write_str ( #fmt[ "%s:" , diagnosticstr ( lvl ) ] ) ;
138
138
if term:: color_supported ( ) {
139
139
term:: reset ( io:: stdout ( ) ) ;
140
140
}
141
141
io:: stdout ( ) . write_str ( #fmt[ " %s\n " , msg] ) ;
142
142
}
143
143
144
144
fn emit_diagnostic ( cmsp : option < ( codemap:: codemap , span ) > ,
145
- msg : str , t : diagnostictype ) {
145
+ msg : str , lvl : level ) {
146
146
alt cmsp {
147
147
some( ( cm, sp) ) {
148
148
let ss = codemap:: span_to_str ( sp, cm) ;
149
149
let lines = codemap:: span_to_lines ( sp, cm) ;
150
- print_diagnostic ( ss, t , msg) ;
150
+ print_diagnostic ( ss, lvl , msg) ;
151
151
highlight_lines ( cm, sp, lines) ;
152
152
}
153
153
none. {
154
- print_diagnostic ( "" , t , msg) ;
154
+ print_diagnostic ( "" , lvl , msg) ;
155
155
}
156
156
}
157
157
}
0 commit comments