Fix minor nits

- rename `map_tok` to `map_token`

- Add backticks about unrecognized token
This commit is contained in:
Joeri van Ruth 2017-09-12 17:04:14 +02:00
parent 27b4b05720
commit 564cc5c066
2 changed files with 6 additions and 5 deletions

View File

@ -164,8 +164,9 @@ fn expr_intern_tok_display_err() {
// The problem is that (usize,&str) and () do not implement fmt::Display,
// so neither does the ParseError.
// We can fix that by rewriting them to something that has fmt::Display
let disp = err.map_tok(|(_,t)|t).map_err(|_| "error");
assert!(disp.to_string().contains("Unrecognized token +"));
let disp = err.map_token(|(_,t)|t).map_err(|_| "error");
let message = disp.to_string();
assert!(message.contains("Unrecognized token `+`"));
// We can even convert the locations to a line number
let line_based = disp.map_loc(|offset| {

View File

@ -55,7 +55,7 @@ impl<L, T, E> ParseError<L, T, E> {
self.map_intern(op, |x|x, |x|x)
}
pub fn map_tok<F,TT>(self, op: F) -> ParseError<L, TT, E> where F: Fn(T) -> TT {
pub fn map_token<F,TT>(self, op: F) -> ParseError<L, TT, E> where F: Fn(T) -> TT {
self.map_intern(|x|x, op, |x|x)
}
@ -77,7 +77,7 @@ where L: fmt::Display,
UnrecognizedToken { ref token, ref expected } => {
match *token {
Some((ref start, ref token, ref end)) =>
try!(write!(f, "Unrecognized token {} found at {}:{}", token, start, end)),
try!(write!(f, "Unrecognized token `{}` found at {}:{}", token, start, end)),
None =>
try!(write!(f, "Unrecognized EOF")),
}
@ -133,7 +133,7 @@ mod tests {
.map(|s| s.to_string())
.collect()
};
assert_eq!(format!("{}", err), "Unrecognized token t0 found at 1:2\n\
assert_eq!(format!("{}", err), "Unrecognized token `t0` found at 1:2\n\
Expected one of t1, t2 or t3");
}
}