pub fn format_errors(src: &str, errors: Vec<Simple<String>>) -> String {
    let mut reports = vec![];

    for e in errors {
        let report = Report::build(ReportKind::Error, (), e.span().start);

        let report = match e.reason() {
            chumsky::error::SimpleReason::Unclosed { span, delimiter } => report
                .with_message(format!(
                    "Unclosed delimiter {}",
                    delimiter.fg(Color::Yellow)
                ))
                .with_label(
                    Label::new(span.clone())
                        .with_message(format!(
                            "Unclosed delimiter {}",
                            delimiter.fg(Color::Yellow)
                        ))
                        .with_color(Color::Yellow),
                )
                .with_label(
                    Label::new(e.span())
                        .with_message(format!(
                            "Must be closed before this {}",
                            e.found()
                                .unwrap_or(&"end of file".to_string())
                                .fg(Color::Red)
                        ))
                        .with_color(Color::Red),
                ),
            chumsky::error::SimpleReason::Unexpected => report
                .with_message(format!(
                    "{}, expected {}",
                    if e.found().is_some() {
                        "Unexpected token in input"
                    } else {
                        "Unexpected end of input"
                    },
                    if e.expected().len() == 0 {
                        "end of input".to_string()
                    } else {
                        e.expected()
                            .map(|expected| match expected {
                                Some(expected) => expected.to_string(),
                                None => "end of input".to_string(),
                            })
                            .collect::<Vec<_>>()
                            .join(", ")
                    }
                ))
                .with_label(
                    Label::new(e.span())
                        .with_message(format!(
                            "Unexpected token {}",
                            e.found()
                                .unwrap_or(&"end of file".to_string())
                                .fg(Color::Red)
                        ))
                        .with_color(Color::Red),
                ),
            chumsky::error::SimpleReason::Custom(msg) => report.with_message(msg).with_label(
                Label::new(e.span())
                    .with_message(format!("{}", msg.fg(Color::Red)))
                    .with_color(Color::Red),
            ),
        };

        let mut buf = vec![];
        report.finish().write(Source::from(&src), &mut buf).unwrap();
        reports.push(std::str::from_utf8(&buf[..]).unwrap().to_string());
    }

    reports.join("\n")
}
/// Format parser errors into a human-readable message.
Format parser errors into a human-readable message.
Format parser errors into a human - readable message .
pub fn format_errors(src: &str, errors: Vec<Simple<String>>) -> String {
    let mut reports = vec![];
    for e in errors {
        let report = Report::build(ReportKind::Error, (), e.span().start);
        let report = match e.reason() {
            chumsky::error::SimpleReason::Unclosed { span, delimiter } => report
                .with_message(format!(
                    "Unclosed delimiter {}",
                    delimiter.fg(Color::Yellow)
                ))
                .with_label(
                    Label::new(span.clone())
                        .with_message(format!(
                            "Unclosed delimiter {}",
                            delimiter.fg(Color::Yellow)
                        ))
                        .with_color(Color::Yellow),
                )
                .with_label(
                    Label::new(e.span())
                        .with_message(format!(
                            "Must be closed before this {}",
                            e.found()
                                .unwrap_or(&"end of file".to_string())
                                .fg(Color::Red)
                        ))
                        .with_color(Color::Red),
                ),
            chumsky::error::SimpleReason::Unexpected => report
                .with_message(format!(
                    "{}, expected {}",
                    if e.found().is_some() {
                        "Unexpected token in input"
                    } else {
                        "Unexpected end of input"
                    },
                    if e.expected().len() == 0 {
                        "end of input".to_string()
                    } else {
                        e.expected()
                            .map(|expected| match expected {
                                Some(expected) => expected.to_string(),
                                None => "end of input".to_string(),
                            })
                            .collect::<Vec<_>>()
                            .join(", ")
                    }
                ))
                .with_label(
                    Label::new(e.span())
                        .with_message(format!(
                            "Unexpected token {}",
                            e.found()
                                .unwrap_or(&"end of file".to_string())
                                .fg(Color::Red)
                        ))
                        .with_color(Color::Red),
                ),
            chumsky::error::SimpleReason::Custom(msg) => report.with_message(msg).with_label(
                Label::new(e.span())
                    .with_message(format!("{}", msg.fg(Color::Red)))
                    .with_color(Color::Red),
            ),
        };
        let mut buf = vec![];
        report.finish().write(Source::from(&src), &mut buf).unwrap();
        reports.push(std::str::from_utf8(&buf[..]).unwrap().to_string());
    }
    reports.join("\n")
}
pub fn format_errors ( src : & str , errors : Vec < Simple < String > > ) -> String { let mut reports = vec ! [ ] ; for e in errors { let report = Report :: build ( ReportKind :: Error , ( ) , e . span ( ) . start ) ; let report = match e . reason ( ) { chumsky :: error :: SimpleReason :: Unclosed { span , delimiter } => report . with_message ( format ! ( " " delimiter fg ( Color Yellow ) ) ) . with_label ( Label :: new ( span . clone ( ) ) . with_message ( format ! ( " " delimiter fg ( Color Yellow ) ) ) . with_color ( Color :: Yellow ) , ) . with_label ( Label :: new ( e . span ( ) ) . with_message ( format ! ( " " e found ( ) unwrap_or ( " " to_string ( ) ) fg ( Color Red ) ) ) . with_color ( Color :: Red ) , ) , chumsky :: error :: SimpleReason :: Unexpected => report . with_message ( format ! ( " " if e found ( ) is_some ( ) { " " } else { " " } if e expected ( ) len ( ) 0 { " " to_string ( ) } else { e expected ( ) map ( expected match expected { Some ( expected ) expected to_string ( ) None " " to_string ( ) } ) collect Vec ( ) join ( " " ) } ) ) . with_label ( Label :: new ( e . span ( ) ) . with_message ( format ! ( " " e found ( ) unwrap_or ( " " to_string ( ) ) fg ( Color Red ) ) ) . with_color ( Color :: Red ) , ) , chumsky :: error :: SimpleReason :: Custom ( msg ) => report . with_message ( msg ) . with_label ( Label :: new ( e . span ( ) ) . with_message ( format ! ( " " msg fg ( Color Red ) ) ) . with_color ( Color :: Red ) , ) , } ; let mut buf = vec ! [ ] ; report . finish ( ) . write ( Source :: from ( & src ) , & mut buf ) . unwrap ( ) ; reports . push ( std :: str :: from_utf8 ( & buf [ .. ] ) . unwrap ( ) . to_string ( ) ) ; } reports . join ( " \n " ) }
Format parser errors into a human-readable message.
Format parser errors into a human - readable message .
src
&str
errors
Vec<Simple<String>>
src
&str
errors
Vec<Simple<String>>