@@ -19,6 +19,102 @@ impl<'src> CompileError<'src> {
1919 }
2020}
2121
22+ pub ( crate ) fn render_compile_error ( error : & CompileError ) {
23+ use ariadne:: { Label , Report , ReportKind , Source } ;
24+
25+ let token = error. token ;
26+ let source = Source :: from ( token. src ) ;
27+
28+ let start = token. offset ;
29+ let end = token. offset + token. length ;
30+
31+ let path = format ! ( "{}" , token. path. display( ) ) ;
32+ let label = Label :: new ( ( & path, start..end) ) ;
33+
34+ let report = Report :: build ( ReportKind :: Error , & path, start) ;
35+
36+ let report = match & * error. kind {
37+ CompileErrorKind :: AttributeArgumentCountMismatch { attribute, found, min, max } => {
38+
39+ let label_msg = format ! ( "Found {found} {}" , Count ( "argument" , * found) ) ;
40+
41+ let note = if min == max {
42+ format ! ( "`{attribute}` takes {min} {}" , Count ( "argument" , * min) )
43+ } else {
44+ format ! ( "`{attribute}` takes between {min} and {max} arguments" )
45+ } ;
46+
47+ report
48+ . with_code ( 1 )
49+ . with_message ( "Attribute argument count mismatch" )
50+ . with_label ( label. with_message ( label_msg) )
51+ . with_note ( note)
52+ . finish ( )
53+ } ,
54+ _ => {
55+
56+ let message = format ! ( "{error}" ) ;
57+ report
58+ . with_message ( message)
59+ . with_label ( label)
60+ . finish ( )
61+ }
62+ /*
63+ CompileErrorKind::BacktickShebang => todo!(),
64+ CompileErrorKind::CircularRecipeDependency { recipe, circle } => todo!(),
65+ CompileErrorKind::CircularVariableDependency { variable, circle } => todo!(),
66+ CompileErrorKind::DependencyArgumentCountMismatch { dependency, found, min, max } => todo!(),
67+ CompileErrorKind::Redefinition { first, first_type, name, second_type } => todo!(),
68+ CompileErrorKind::DuplicateAttribute { attribute, first } => todo!(),
69+ CompileErrorKind::DuplicateParameter { recipe, parameter } => todo!(),
70+ CompileErrorKind::DuplicateSet { setting, first } => todo!(),
71+ CompileErrorKind::DuplicateVariable { variable } => todo!(),
72+ CompileErrorKind::DuplicateUnexport { variable } => todo!(),
73+ CompileErrorKind::ExpectedKeyword { expected, found } => todo!(),
74+ CompileErrorKind::ExportUnexported { variable } => todo!(),
75+ CompileErrorKind::ExtraLeadingWhitespace => todo!(),
76+ CompileErrorKind::ExtraneousAttributes { count } => todo!(),
77+ CompileErrorKind::FunctionArgumentCountMismatch { function, found, expected } => todo!(),
78+ CompileErrorKind::Include => todo!(),
79+ CompileErrorKind::InconsistentLeadingWhitespace { expected, found } => todo!(),
80+ CompileErrorKind::Internal { message } => todo!(),
81+ CompileErrorKind::InvalidAttribute { item_kind, item_name, attribute } => todo!(),
82+ CompileErrorKind::InvalidEscapeSequence { character } => todo!(),
83+ CompileErrorKind::MismatchedClosingDelimiter { close, open, open_line } => todo!(),
84+ CompileErrorKind::MixedLeadingWhitespace { whitespace } => todo!(),
85+ CompileErrorKind::ParameterFollowsVariadicParameter { parameter } => todo!(),
86+ CompileErrorKind::ParsingRecursionDepthExceeded => todo!(),
87+ CompileErrorKind::RequiredParameterFollowsDefaultParameter { parameter } => todo!(),
88+ CompileErrorKind::ShebangAndScriptAttribute { recipe } => todo!(),
89+ CompileErrorKind::ShellExpansion { err } => todo!(),
90+ CompileErrorKind::UndefinedVariable { variable } => todo!(),
91+ CompileErrorKind::UnexpectedCharacter { expected } => todo!(),
92+ CompileErrorKind::UnexpectedClosingDelimiter { close } => todo!(),
93+ CompileErrorKind::UnexpectedEndOfToken { expected } => todo!(),
94+ CompileErrorKind::UnexpectedToken { expected, found } => todo!(),
95+ CompileErrorKind::UnicodeEscapeCharacter { character } => todo!(),
96+ CompileErrorKind::UnicodeEscapeDelimiter { character } => todo!(),
97+ CompileErrorKind::UnicodeEscapeEmpty => todo!(),
98+ CompileErrorKind::UnicodeEscapeLength { hex } => todo!(),
99+ CompileErrorKind::UnicodeEscapeRange { hex } => todo!(),
100+ CompileErrorKind::UnicodeEscapeUnterminated => todo!(),
101+ CompileErrorKind::UnknownAliasTarget { alias, target } => todo!(),
102+ CompileErrorKind::UnknownAttribute { attribute } => todo!(),
103+ CompileErrorKind::UnknownDependency { recipe, unknown } => todo!(),
104+ CompileErrorKind::UnknownFunction { function } => todo!(),
105+ CompileErrorKind::UnknownSetting { setting } => todo!(),
106+ CompileErrorKind::UnknownStartOfToken => todo!(),
107+ CompileErrorKind::UnpairedCarriageReturn => todo!(),
108+ CompileErrorKind::UnterminatedBacktick => todo!(),
109+ CompileErrorKind::UnterminatedInterpolation => todo!(),
110+ CompileErrorKind::UnterminatedString => todo!(),
111+ */
112+ } ;
113+
114+ report. eprint ( ( & path, source) )
115+ . unwrap ( ) ;
116+ }
117+
22118fn capitalize ( s : & str ) -> String {
23119 let mut chars = s. chars ( ) ;
24120 match chars. next ( ) {
0 commit comments