@@ -8,35 +8,35 @@ pub enum WaveErrorKind {
88 InvalidString ( String ) ,
99 UnterminatedString ,
1010 UnterminatedComment ,
11-
11+
1212 // Parser errors
1313 SyntaxError ( String ) ,
1414 UnexpectedEndOfFile ,
1515 InvalidExpression ( String ) ,
1616 InvalidStatement ( String ) ,
1717 InvalidType ( String ) ,
18-
18+
1919 // Import/Module errors
2020 ModuleNotFound ( String ) ,
2121 ImportError ( String ) ,
2222 CircularImport ( String ) ,
23-
23+
2424 // Type checking errors
2525 TypeMismatch { expected : String , found : String } ,
2626 UndefinedVariable ( String ) ,
2727 UndefinedFunction ( String ) ,
2828 InvalidFunctionCall ( String ) ,
2929 InvalidAssignment ( String ) ,
30-
30+
3131 // Standard library errors
3232 StandardLibraryNotAvailable ,
3333 UnknownStandardLibraryModule ( String ) ,
3434 VexIntegrationRequired ( String ) ,
35-
35+
3636 // Compilation errors
3737 CompilationFailed ( String ) ,
3838 LinkingFailed ( String ) ,
39-
39+
4040 // I/O errors
4141 FileNotFound ( String ) ,
4242 FileReadError ( String ) ,
@@ -67,7 +67,13 @@ pub enum ErrorSeverity {
6767}
6868
6969impl WaveError {
70- pub fn new ( kind : WaveErrorKind , message : impl Into < String > , file : impl Into < String > , line : usize , column : usize ) -> Self {
70+ pub fn new (
71+ kind : WaveErrorKind ,
72+ message : impl Into < String > ,
73+ file : impl Into < String > ,
74+ line : usize ,
75+ column : usize ,
76+ ) -> Self {
7177 Self {
7278 kind,
7379 message : message. into ( ) ,
@@ -117,24 +123,39 @@ impl WaveError {
117123 pub fn stdlib_requires_vex ( module : & str , file : & str , line : usize , column : usize ) -> Self {
118124 Self :: new (
119125 WaveErrorKind :: VexIntegrationRequired ( module. to_string ( ) ) ,
120- format ! ( "standard library module 'std::{}' requires Vex package manager" , module) ,
126+ format ! (
127+ "standard library module 'std::{}' requires Vex package manager" ,
128+ module
129+ ) ,
121130 file,
122131 line,
123132 column,
124133 )
125134 . with_help ( "Wave compiler in standalone mode only supports low-level system programming" )
126135 . with_suggestion ( "Use 'vex build' or 'vex run' to access standard library modules" )
127- . with_suggestion ( format ! ( "Remove the import for 'std::{}' to use Wave in low-level mode" , module) )
136+ . with_suggestion ( format ! (
137+ "Remove the import for 'std::{}' to use Wave in low-level mode" ,
138+ module
139+ ) )
128140 }
129141
130142 /// Create a type mismatch error with detailed information
131- pub fn type_mismatch ( expected : & str , found : & str , file : & str , line : usize , column : usize ) -> Self {
143+ pub fn type_mismatch (
144+ expected : & str ,
145+ found : & str ,
146+ file : & str ,
147+ line : usize ,
148+ column : usize ,
149+ ) -> Self {
132150 Self :: new (
133- WaveErrorKind :: TypeMismatch {
134- expected : expected. to_string ( ) ,
135- found : found. to_string ( )
151+ WaveErrorKind :: TypeMismatch {
152+ expected : expected. to_string ( ) ,
153+ found : found. to_string ( ) ,
136154 } ,
137- format ! ( "mismatched types: expected `{}`, found `{}`" , expected, found) ,
155+ format ! (
156+ "mismatched types: expected `{}`, found `{}`" ,
157+ expected, found
158+ ) ,
138159 file,
139160 line,
140161 column,
@@ -168,15 +189,26 @@ impl WaveError {
168189
169190 // Main error message
170191 eprintln ! ( "{}: {}" , severity_str, self . message. bold( ) ) ;
171-
192+
172193 // Location
173- eprintln ! ( " {} {}:{}:{}" , "-->" . blue( ) . bold( ) , self . file, self . line, self . column) ;
194+ eprintln ! (
195+ " {} {}:{}:{}" ,
196+ "-->" . blue( ) . bold( ) ,
197+ self . file,
198+ self . line,
199+ self . column
200+ ) ;
174201 eprintln ! ( " {}" , "|" . blue( ) . bold( ) ) ;
175202
176203 // Source code with highlighting
177204 if let Some ( source_line) = & self . source {
178- eprintln ! ( "{:>3} {} {}" , self . line. to_string( ) . blue( ) . bold( ) , "|" . blue( ) . bold( ) , source_line) ;
179-
205+ eprintln ! (
206+ "{:>3} {} {}" ,
207+ self . line. to_string( ) . blue( ) . bold( ) ,
208+ "|" . blue( ) . bold( ) ,
209+ source_line
210+ ) ;
211+
180212 // Arrow pointing to the error
181213 let spaces = " " . repeat ( self . column . saturating_sub ( 1 ) ) ;
182214 let arrow = match self . severity {
@@ -185,9 +217,15 @@ impl WaveError {
185217 ErrorSeverity :: Note => "^" . cyan ( ) . bold ( ) ,
186218 ErrorSeverity :: Help => "^" . green ( ) . bold ( ) ,
187219 } ;
188-
220+
189221 if let Some ( label) = & self . label {
190- eprintln ! ( " {} {}{} {}" , "|" . blue( ) . bold( ) , spaces, arrow, label. dimmed( ) ) ;
222+ eprintln ! (
223+ " {} {}{} {}" ,
224+ "|" . blue( ) . bold( ) ,
225+ spaces,
226+ arrow,
227+ label. dimmed( )
228+ ) ;
191229 } else {
192230 eprintln ! ( " {} {}{}" , "|" . blue( ) . bold( ) , spaces, arrow) ;
193231 }
@@ -197,16 +235,31 @@ impl WaveError {
197235
198236 // Additional information
199237 if let Some ( note) = & self . note {
200- eprintln ! ( " {} {}: {}" , "=" . blue( ) . bold( ) , "note" . cyan( ) . bold( ) , note) ;
238+ eprintln ! (
239+ " {} {}: {}" ,
240+ "=" . blue( ) . bold( ) ,
241+ "note" . cyan( ) . bold( ) ,
242+ note
243+ ) ;
201244 }
202245
203246 if let Some ( help) = & self . help {
204- eprintln ! ( " {} {}: {}" , "=" . blue( ) . bold( ) , "help" . green( ) . bold( ) , help) ;
247+ eprintln ! (
248+ " {} {}: {}" ,
249+ "=" . blue( ) . bold( ) ,
250+ "help" . green( ) . bold( ) ,
251+ help
252+ ) ;
205253 }
206254
207255 // Suggestions
208256 for suggestion in & self . suggestions {
209- eprintln ! ( " {} {}: {}" , "=" . blue( ) . bold( ) , "suggestion" . green( ) . bold( ) , suggestion) ;
257+ eprintln ! (
258+ " {} {}: {}" ,
259+ "=" . blue( ) . bold( ) ,
260+ "suggestion" . green( ) . bold( ) ,
261+ suggestion
262+ ) ;
210263 }
211264 }
212265
@@ -218,20 +271,28 @@ impl WaveError {
218271 }
219272 error. display ( ) ;
220273 }
221-
274+
222275 if errors. len ( ) > 1 {
223- let error_count = errors. iter ( ) . filter ( |e| matches ! ( e. severity, ErrorSeverity :: Error ) ) . count ( ) ;
224- let warning_count = errors. iter ( ) . filter ( |e| matches ! ( e. severity, ErrorSeverity :: Warning ) ) . count ( ) ;
225-
276+ let error_count = errors
277+ . iter ( )
278+ . filter ( |e| matches ! ( e. severity, ErrorSeverity :: Error ) )
279+ . count ( ) ;
280+ let warning_count = errors
281+ . iter ( )
282+ . filter ( |e| matches ! ( e. severity, ErrorSeverity :: Warning ) )
283+ . count ( ) ;
284+
226285 eprintln ! ( ) ;
227286 if error_count > 0 {
228- eprintln ! ( "error: aborting due to {} previous error{}" ,
229- error_count,
287+ eprintln ! (
288+ "error: aborting due to {} previous error{}" ,
289+ error_count,
230290 if error_count == 1 { "" } else { "s" }
231291 ) ;
232292 }
233293 if warning_count > 0 {
234- eprintln ! ( "warning: {} warning{} emitted" ,
294+ eprintln ! (
295+ "warning: {} warning{} emitted" ,
235296 warning_count,
236297 if warning_count == 1 { "" } else { "s" }
237298 ) ;
@@ -243,4 +304,4 @@ impl WaveError {
243304 pub fn is_fatal ( & self ) -> bool {
244305 matches ! ( self . severity, ErrorSeverity :: Error )
245306 }
246- }
307+ }
0 commit comments