From 43ff08b04c771de9b1545f62f14ca91456e67de0 Mon Sep 17 00:00:00 2001 From: greg Date: Wed, 11 Jul 2018 02:32:29 -0700 Subject: [PATCH] Add some debugging info around parse error --- schala-lang/src/parsing.rs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) 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 + } } }; }