fn extract_error(source: &Arc<File>, mut errors: Vec<ParseError>) -> Result<(), Error> {
    fn rank_error(e: &ParseError) -> u32 {
        match e {
            ParseError::Unexpected(node) => {
                // The node might point to an empty part of the input, so give those a low rank
                if node.range().is_empty() {
                    1
                } else {
                    2
                }
            }
            ParseError::UnexpectedEOFWanted(_) => 1, // at least contains the expected token
            ParseError::UnexpectedEOF => 0,          // almost no information
        }
    }

    if errors.is_empty() {
        return Ok(());
    }

    errors.sort_by_key(rank_error); // (should be a stable sort)

    trace!("{} errors:", errors.len());
    for error in &errors {
        trace!("{}", Error::from_inner(source.clone(), error.clone()));
    }

    // Pick the best error, or the first "good" error
    let error = errors.pop().unwrap();
    Err(Error::from_inner(source.clone(), error))
}
/// Takes a list of `ParseErrors` and tries to extract a human-readable parsing
/// error.
///
/// `rnix` will most likely return a whole list of errors, many of which just
/// say "unexpected end of file" even though that's not really accurate. That's
/// why this code ranks errors based on their type and other available
/// information, and then sorts the list of errors to obtain the error that's
/// most likely to be of highest value to a user.
Takes a list of `ParseErrors` and tries to extract a human-readable parsing
error.

`rnix` will most likely return a whole list of errors, many of which just
say "unexpected end of file" even though that's not really accurate. That's
why this code ranks errors based on their type and other available
information, and then sorts the list of errors to obtain the error that's
most likely to be of highest value to a user.
Takes a list of ` ParseErrors ` and tries to extract a human - readable parsing error . ` rnix ` will most likely return a whole list of errors many of which just say " unexpected end of file " even though that ' s not really accurate . That ' s why this code ranks errors based on their type and other available information and then sorts the list of errors to obtain the error that ' s most likely to be of highest value to a user .
fn extract_error(source: &Arc<File>, mut errors: Vec<ParseError>) -> Result<(), Error> {
    fn rank_error(e: &ParseError) -> u32 {
        match e {
            ParseError::Unexpected(node) => {
                // The node might point to an empty part of the input, so give those a low rank
                if node.range().is_empty() {
                    1
                } else {
                    2
                }
            }
            ParseError::UnexpectedEOFWanted(_) => 1, // at least contains the expected token
            ParseError::UnexpectedEOF => 0,          // almost no information
        }
    }
    if errors.is_empty() {
        return Ok(());
    }
    errors.sort_by_key(rank_error); // (should be a stable sort)
    trace!("{} errors:", errors.len());
    for error in &errors {
        trace!("{}", Error::from_inner(source.clone(), error.clone()));
    }
    // Pick the best error, or the first "good" error
    let error = errors.pop().unwrap();
    Err(Error::from_inner(source.clone(), error))
}
fn extract_error ( source : & Arc < File > , mut errors : Vec < ParseError > ) -> Result < ( ) , Error > { fn rank_error ( e : & ParseError ) -> u32 { match e { ParseError :: Unexpected ( node ) => { // The node might point to an empty part of the input, so give those a low rank if node . range ( ) . is_empty ( ) { 1 } else { 2 } } ParseError :: UnexpectedEOFWanted ( _ ) => 1 , // at least contains the expected token ParseError :: UnexpectedEOF => 0 , // almost no information } } if errors . is_empty ( ) { return Ok ( ( ) ) ; } errors . sort_by_key ( rank_error ) ; // (should be a stable sort) trace ! ( " " errors len ( ) ) ; for error in & errors { trace ! ( " " Error from_inner ( source clone ( ) error clone ( ) ) ) ; } // Pick the best error, or the first "good" error let error = errors . pop ( ) . unwrap ( ) ; Err ( Error :: from_inner ( source . clone ( ) , error ) ) }
Takes a list of `ParseErrors` and tries to extract a human-readable parsing
error.
Takes a list of ` ParseErrors ` and tries to extract a human - readable parsing error .
source
&Arc<File>
errors
Vec<ParseError>
source
&Arc<File>
errors
Vec<ParseError>