aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbnewbold <bnewbold@robocracy.org>2016-12-18 11:33:36 -0800
committerbnewbold <bnewbold@robocracy.org>2016-12-18 11:33:36 -0800
commitc9db85ca1446ecd82cce4ac72a6b07ed92f9b209 (patch)
tree04cbd501c9b2435fd283cd35b889166f05bc476e
parentc564b5c4c0efc541886648ba97d69a4ad25d7464 (diff)
downloadmodelthing-c9db85ca1446ecd82cce4ac72a6b07ed92f9b209.tar.gz
modelthing-c9db85ca1446ecd82cce4ac72a6b07ed92f9b209.zip
parser: don't print expected if there aren't any
-rw-r--r--modelica-parser-lalrpop/src/lib.rs16
1 files 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<usize, (usize, &str), ()>) -> 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(),