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 {
|
macro_rules! expect {
|
||||||
($self:expr, $token_type:pat) => { expect!($self, $token_type if true) };
|
($self:expr, $token_kind:pat) => { expect!($self, $token_kind if true) };
|
||||||
($self:expr, $token_type:pat if $cond:expr) => {
|
($self:expr, $expected_kind:pat if $cond:expr) => {
|
||||||
match $self.peek() {
|
{
|
||||||
$token_type if $cond => $self.next(),
|
let tok = $self.token_handler.peek_token();
|
||||||
tok => {
|
match tok.get_kind() {
|
||||||
let msg = format!("Expected {}, got {:?}", print_token_pattern!($token_type), tok);
|
$expected_kind if $cond => $self.next(),
|
||||||
return ParseError::new(&msg);
|
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]
|
#[recursive_descent_method]
|
||||||
fn for_expr_body(&mut self) -> ParseResult<ForBody> {
|
fn for_expr_body(&mut self) -> ParseResult<ForBody> {
|
||||||
use self::ForBody::*;
|
use self::ForBody::*;
|
||||||
Ok(match self.peek() {
|
let tok = self.token_handler.peek_token();
|
||||||
|
Ok(match tok.get_kind() {
|
||||||
LCurlyBrace => {
|
LCurlyBrace => {
|
||||||
let statements = delimited!(self, LCurlyBrace, statement, Newline | Semicolon, RCurlyBrace, nonstrict);
|
let statements = delimited!(self, LCurlyBrace, statement, Newline | Semicolon, RCurlyBrace, nonstrict);
|
||||||
StatementBlock(statements.into_iter().map(|s| Node::new(s)).collect())
|
StatementBlock(statements.into_iter().map(|s| Node::new(s)).collect())
|
||||||
@ -991,7 +995,7 @@ impl Parser {
|
|||||||
self.next();
|
self.next();
|
||||||
MonadicReturn(self.expression()?)
|
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