diff --git a/schala-lang/src/parsing.rs b/schala-lang/src/parsing.rs index e507b89..75ea3ee 100644 --- a/schala-lang/src/parsing.rs +++ b/schala-lang/src/parsing.rs @@ -140,14 +140,18 @@ enumerator := identifier '<-' expression | identifier '=' expression //TODO add type TokenIter = Peekable>; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct ParseError { pub msg: String, + pub token: Option } impl ParseError { fn new(msg: &str) -> ParseResult { - Err(ParseError { msg: msg.to_string() }) + Err(ParseError { + msg: msg.to_string(), + token: None + }) } } @@ -203,7 +207,7 @@ macro_rules! expect { $token_type if $cond => $self.next(), tok => { let msg = format!("Expected {}, got {:?}", print_token_pattern!($token_type), tok); - return Err(ParseError { msg }) + return ParseError::new(&msg); } } } @@ -226,7 +230,11 @@ macro_rules! parse_method { if $self.parse_level != 0 { $self.parse_level -= 1; } - result + match result { + Err(ParseError { token: None, msg }) => + Err(ParseError { token: Some(next_token), msg }), + _ => result + } } }; }