summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNanoTech2016-12-06 04:09:01 -0600
committerNanoTech2017-03-10 23:48:27 -0600
commit7d0f38c1ff244f47bd3619515567246b498b493e (patch)
tree9535817f129c92580090c0a489e158a9a8dbf898
parent10577fc72af7260255493999294eda8e4413b6a5 (diff)
Print some error context
-rw-r--r--src/main.rs10
1 files changed, 8 insertions, 2 deletions
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