mirror of
https://github.com/fluencelabs/lalrpop
synced 2025-03-28 06:01:02 +00:00
Fix minor nits
- rename `map_tok` to `map_token` - Add backticks about unrecognized token
This commit is contained in:
parent
27b4b05720
commit
564cc5c066
@ -164,8 +164,9 @@ fn expr_intern_tok_display_err() {
|
|||||||
// The problem is that (usize,&str) and () do not implement fmt::Display,
|
// The problem is that (usize,&str) and () do not implement fmt::Display,
|
||||||
// so neither does the ParseError.
|
// so neither does the ParseError.
|
||||||
// We can fix that by rewriting them to something that has fmt::Display
|
// We can fix that by rewriting them to something that has fmt::Display
|
||||||
let disp = err.map_tok(|(_,t)|t).map_err(|_| "error");
|
let disp = err.map_token(|(_,t)|t).map_err(|_| "error");
|
||||||
assert!(disp.to_string().contains("Unrecognized token +"));
|
let message = disp.to_string();
|
||||||
|
assert!(message.contains("Unrecognized token `+`"));
|
||||||
|
|
||||||
// We can even convert the locations to a line number
|
// We can even convert the locations to a line number
|
||||||
let line_based = disp.map_loc(|offset| {
|
let line_based = disp.map_loc(|offset| {
|
||||||
|
@ -55,7 +55,7 @@ impl<L, T, E> ParseError<L, T, E> {
|
|||||||
self.map_intern(op, |x|x, |x|x)
|
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)
|
self.map_intern(|x|x, op, |x|x)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -77,7 +77,7 @@ where L: fmt::Display,
|
|||||||
UnrecognizedToken { ref token, ref expected } => {
|
UnrecognizedToken { ref token, ref expected } => {
|
||||||
match *token {
|
match *token {
|
||||||
Some((ref start, ref token, ref end)) =>
|
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 =>
|
None =>
|
||||||
try!(write!(f, "Unrecognized EOF")),
|
try!(write!(f, "Unrecognized EOF")),
|
||||||
}
|
}
|
||||||
@ -133,7 +133,7 @@ mod tests {
|
|||||||
.map(|s| s.to_string())
|
.map(|s| s.to_string())
|
||||||
.collect()
|
.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");
|
Expected one of t1, t2 or t3");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user