compiler: Reworked Preprocessor To Support Better Error Messages
Can now support showing the trail of includes in an error message. Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
This commit is contained in:
@@ -55,8 +55,16 @@ public struct ErrorWithLocation: Errorable, Equatable, CustomStringConvertible {
|
||||
|
||||
let prior_snipped = prior.trimmingPrefix(["\n"])
|
||||
let after_snipped = after.prefix { $0 != "\n" }
|
||||
let include_list = fp.reversed().map {
|
||||
let at = if let whence = $0.whence {
|
||||
" included at position \(whence) in"
|
||||
} else {
|
||||
""
|
||||
}
|
||||
return $0.path.string + at
|
||||
}.joined(separator: " ")
|
||||
return formatter.formatWithStyle("Error: ", Style(StyleColor.Red))
|
||||
+ "In \(fp), there was an error: \n..." + prior_snipped
|
||||
+ "In \(include_list), there was an error: \n..." + prior_snipped
|
||||
+ formatter.formatWithStyle(source, Style(.none, [StyleFormat.Underline])) + after_snipped
|
||||
+ "...\n"
|
||||
+ self._msg
|
||||
|
||||
Reference in New Issue
Block a user