Add production name in ParseError

for debugging
This commit is contained in:
greg 2019-10-01 21:40:30 -07:00
parent f9a59838b0
commit 28056b1f89
2 changed files with 6 additions and 2 deletions

View File

@ -32,7 +32,10 @@ impl Fold for RecursiveDescentFn {
if self.parse_level != 0 {
self.parse_level -= 1;
}
result
result.map_err(|mut parse_error: ParseError| {
parse_error.production_name = Some(stringify!(#ident).to_string());
parse_error
})
}
};
i.block = Box::new(new_block);

View File

@ -160,13 +160,14 @@ use crate::ast::*;
/// Represents a parsing error
#[derive(Debug)]
pub struct ParseError {
pub production_name: Option<String>,
pub msg: String,
pub token: Token
}
impl ParseError {
fn new_with_token<T, M>(msg: M, token: Token) -> ParseResult<T> where M: Into<String> {
Err(ParseError { msg: msg.into(), token })
Err(ParseError { msg: msg.into(), token, production_name: None })
}
}