From c9db85ca1446ecd82cce4ac72a6b07ed92f9b209 Mon Sep 17 00:00:00 2001 From: bnewbold Date: Sun, 18 Dec 2016 11:33:36 -0800 Subject: parser: don't print expected if there aren't any --- modelica-parser-lalrpop/src/lib.rs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/modelica-parser-lalrpop/src/lib.rs b/modelica-parser-lalrpop/src/lib.rs index f6f1e8b..a109607 100644 --- a/modelica-parser-lalrpop/src/lib.rs +++ b/modelica-parser-lalrpop/src/lib.rs @@ -45,15 +45,23 @@ pub fn pp_parseerror(raw: &str, pe: ParseError) -> Str "parse error:".red().bold(), pp_segment(raw, location, location+1)) }, ParseError::UnrecognizedToken{token: Some((start, (_, tok), end)), expected} => { - format!("{} unrecognized token '{}' (expected one of {:?}):\n{}", + format!("{} unrecognized token '{}'{}:\n{}", "parse error:".red().bold(), tok, - expected, + if expected.len() > 0 { + format!(" (expected one of {:?})", expected) + } else { + format!("") + }, pp_segment(raw, start, end)) }, ParseError::UnrecognizedToken{token: None, expected} => { - format!("{} premature end-of-file (expected one of {:?})", + format!("{} premature end-of-file{}", "parse error:".red().bold(), - expected) }, + if expected.len() > 0 { + format!(" (expected one of {:?})", expected) + } else { + format!("") + }) }, ParseError::ExtraToken{token: (start, (_, tok), end)} => { format!("{} unexpected extra token '{}':\n{}", "parse error:".red().bold(), -- cgit v1.2.3