More use of Token in error messages
This commit is contained in:
parent
f2f8ac7ee8
commit
22f2750853
@ -121,13 +121,16 @@ macro_rules! print_token_pattern {
|
||||
}
|
||||
|
||||
macro_rules! expect {
|
||||
($self:expr, $token_type:pat) => { expect!($self, $token_type if true) };
|
||||
($self:expr, $token_type:pat if $cond:expr) => {
|
||||
match $self.peek() {
|
||||
$token_type if $cond => $self.next(),
|
||||
tok => {
|
||||
let msg = format!("Expected {}, got {:?}", print_token_pattern!($token_type), tok);
|
||||
return ParseError::new(&msg);
|
||||
($self:expr, $token_kind:pat) => { expect!($self, $token_kind if true) };
|
||||
($self:expr, $expected_kind:pat if $cond:expr) => {
|
||||
{
|
||||
let tok = $self.token_handler.peek_token();
|
||||
match tok.get_kind() {
|
||||
$expected_kind if $cond => $self.next(),
|
||||
actual_kind => {
|
||||
let msg = format!("Expected {}, got {:?}", print_token_pattern!($expected_kind), actual_kind);
|
||||
return ParseError::new_with_token(&msg, tok);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -982,7 +985,8 @@ impl Parser {
|
||||
#[recursive_descent_method]
|
||||
fn for_expr_body(&mut self) -> ParseResult<ForBody> {
|
||||
use self::ForBody::*;
|
||||
Ok(match self.peek() {
|
||||
let tok = self.token_handler.peek_token();
|
||||
Ok(match tok.get_kind() {
|
||||
LCurlyBrace => {
|
||||
let statements = delimited!(self, LCurlyBrace, statement, Newline | Semicolon, RCurlyBrace, nonstrict);
|
||||
StatementBlock(statements.into_iter().map(|s| Node::new(s)).collect())
|
||||
@ -991,7 +995,7 @@ impl Parser {
|
||||
self.next();
|
||||
MonadicReturn(self.expression()?)
|
||||
},
|
||||
_ => return ParseError::new("for expressions must end in a block or 'return'"),
|
||||
_ => return ParseError::new_with_token("for expressions must end in a block or 'return'", tok),
|
||||
})
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user