neo_solidity/
diagnostic_fmt.rs

1//! Diagnostic Formatter
2//!
3//! Pretty-prints compiler diagnostics.
4
5use crate::error::CompilerError;
6
7/// Diagnostic output format
8#[derive(Debug, Clone, Copy)]
9pub enum DiagnosticFormat {
10    Human,
11    Json,
12    Compact,
13}
14
15/// Format a compiler error for display
16pub fn format_error(err: &CompilerError, fmt: DiagnosticFormat) -> String {
17    match fmt {
18        DiagnosticFormat::Human => format_human(err),
19        DiagnosticFormat::Json => format_json(err),
20        DiagnosticFormat::Compact => format_compact(err),
21    }
22}
23
24fn format_human(err: &CompilerError) -> String {
25    format!("{}", err)
26}
27
28fn format_json(err: &CompilerError) -> String {
29    format!("{{\"error\": \"{}\"}}", err)
30}
31
32fn format_compact(err: &CompilerError) -> String {
33    format!("{}", err)
34}