From 7d0f38c1ff244f47bd3619515567246b498b493e Mon Sep 17 00:00:00 2001 From: NanoTech Date: Tue, 6 Dec 2016 04:09:01 -0600 Subject: Print some error context --- src/main.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/main.rs b/src/main.rs index e5238dc..e60a893 100644 --- a/src/main.rs +++ b/src/main.rs @@ -14,8 +14,14 @@ use std::io::{self, Read}; fn main() { let mut buffer = String::new(); io::stdin().read_to_string(&mut buffer).unwrap(); - let r = parser::parse_expr(&buffer); - println!("{:?}", r); + match parser::parse_expr(&buffer) { + Ok(e) => println!("{:?}", e), + Err(lalrpop_util::ParseError::User { error: lexer::LexicalError::Error(pos, e) }) => { + let context = &buffer[pos..::std::cmp::min(buffer.len(), pos + 20)]; + println!("Unexpected token in {:?}: {:?}...", e, context); + } + Err(e) => println!("{:?}", e), + } /* expr <- case exprFromText (Directed "(stdin)" 0 0 0 0) inText of -- cgit v1.2.3