@@ -19,6 +19,114 @@ 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 {
38+ attribute,
39+ found,
40+ min,
41+ max,
42+ } => {
43+ let label_msg = format ! ( "Found {found} {}" , Count ( "argument" , * found) ) ;
44+
45+ let note = if min == max {
46+ format ! ( "`{attribute}` takes {min} {}" , Count ( "argument" , * min) )
47+ } else {
48+ format ! ( "`{attribute}` takes between {min} and {max} arguments" )
49+ } ;
50+
51+ report
52+ . with_code ( "E01" )
53+ . with_message ( "Attribute argument count mismatch" )
54+ . with_label ( label. with_message ( label_msg) )
55+ . with_note ( note)
56+ . finish ( )
57+ }
58+ /*
59+ CompileErrorKind::BacktickShebang => todo!(),
60+ CompileErrorKind::CircularRecipeDependency { recipe, circle } => todo!(),
61+ CompileErrorKind::CircularVariableDependency { variable, circle } => todo!(),
62+ CompileErrorKind::DependencyArgumentCountMismatch { dependency, found, min, max } => todo!(),
63+ CompileErrorKind::Redefinition { first, first_type, name, second_type } => todo!(),
64+ */
65+ CompileErrorKind :: DuplicateAttribute { attribute, first } => {
66+ let original_label = source
67+ . line ( * first)
68+ . map ( |line| Label :: new ( ( & path, line. span ( ) ) ) . with_message ( "original" ) ) ;
69+
70+ let mut report = report
71+ . with_code ( "E02" )
72+ . with_message ( format ! ( "Duplicate attribute `{attribute}`" ) ) ;
73+ if let Some ( original) = original_label {
74+ report = report. with_label ( original) ;
75+ }
76+ report. with_label ( label. with_message ( "duplicate" ) ) . finish ( )
77+ }
78+ _ => {
79+ let message = format ! ( "{error}" ) ;
80+ report. with_message ( message) . with_label ( label) . finish ( )
81+ } /*
82+ CompileErrorKind::DuplicateParameter { recipe, parameter } => todo!(),
83+ CompileErrorKind::DuplicateSet { setting, first } => todo!(),
84+ CompileErrorKind::DuplicateVariable { variable } => todo!(),
85+ CompileErrorKind::DuplicateUnexport { variable } => todo!(),
86+ CompileErrorKind::ExpectedKeyword { expected, found } => todo!(),
87+ CompileErrorKind::ExportUnexported { variable } => todo!(),
88+ CompileErrorKind::ExtraLeadingWhitespace => todo!(),
89+ CompileErrorKind::ExtraneousAttributes { count } => todo!(),
90+ CompileErrorKind::FunctionArgumentCountMismatch { function, found, expected } => todo!(),
91+ CompileErrorKind::Include => todo!(),
92+ CompileErrorKind::InconsistentLeadingWhitespace { expected, found } => todo!(),
93+ CompileErrorKind::Internal { message } => todo!(),
94+ CompileErrorKind::InvalidAttribute { item_kind, item_name, attribute } => todo!(),
95+ CompileErrorKind::InvalidEscapeSequence { character } => todo!(),
96+ CompileErrorKind::MismatchedClosingDelimiter { close, open, open_line } => todo!(),
97+ CompileErrorKind::MixedLeadingWhitespace { whitespace } => todo!(),
98+ CompileErrorKind::ParameterFollowsVariadicParameter { parameter } => todo!(),
99+ CompileErrorKind::ParsingRecursionDepthExceeded => todo!(),
100+ CompileErrorKind::RequiredParameterFollowsDefaultParameter { parameter } => todo!(),
101+ CompileErrorKind::ShebangAndScriptAttribute { recipe } => todo!(),
102+ CompileErrorKind::ShellExpansion { err } => todo!(),
103+ CompileErrorKind::UndefinedVariable { variable } => todo!(),
104+ CompileErrorKind::UnexpectedCharacter { expected } => todo!(),
105+ CompileErrorKind::UnexpectedClosingDelimiter { close } => todo!(),
106+ CompileErrorKind::UnexpectedEndOfToken { expected } => todo!(),
107+ CompileErrorKind::UnexpectedToken { expected, found } => todo!(),
108+ CompileErrorKind::UnicodeEscapeCharacter { character } => todo!(),
109+ CompileErrorKind::UnicodeEscapeDelimiter { character } => todo!(),
110+ CompileErrorKind::UnicodeEscapeEmpty => todo!(),
111+ CompileErrorKind::UnicodeEscapeLength { hex } => todo!(),
112+ CompileErrorKind::UnicodeEscapeRange { hex } => todo!(),
113+ CompileErrorKind::UnicodeEscapeUnterminated => todo!(),
114+ CompileErrorKind::UnknownAliasTarget { alias, target } => todo!(),
115+ CompileErrorKind::UnknownAttribute { attribute } => todo!(),
116+ CompileErrorKind::UnknownDependency { recipe, unknown } => todo!(),
117+ CompileErrorKind::UnknownFunction { function } => todo!(),
118+ CompileErrorKind::UnknownSetting { setting } => todo!(),
119+ CompileErrorKind::UnknownStartOfToken => todo!(),
120+ CompileErrorKind::UnpairedCarriageReturn => todo!(),
121+ CompileErrorKind::UnterminatedBacktick => todo!(),
122+ CompileErrorKind::UnterminatedInterpolation => todo!(),
123+ CompileErrorKind::UnterminatedString => todo!(),
124+ */
125+ } ;
126+
127+ report. eprint ( ( & path, source) ) . unwrap ( ) ;
128+ }
129+
22130fn capitalize ( s : & str ) -> String {
23131 let mut chars = s. chars ( ) ;
24132 match chars. next ( ) {
0 commit comments