diff --git a/src/parser.rs b/src/parser.rs index d6e025a..9204b2b 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -26,7 +26,7 @@ pub struct ParseError { pub type ParseResult = Result>; -impl<'i, P, G, I: Input, Pat> Parser<'_, 'i, G, I, Pat> +impl<'i, P, G, I: Input, Pat: Ord> Parser<'_, 'i, G, I, Pat> where // FIXME(eddyb) these shouldn't be needed, as they are bounds on // `GrammarReflector::NodeKind`, but that's ignored currently. @@ -57,10 +57,13 @@ where remaining: range, }); - let error = ParseError { + let mut error = ParseError { at: I::source_info_point(&state.forest.input, state.last_input_pos), expected: state.expected_pats, }; + error.expected.sort(); + error.expected.dedup(); + match result { None => Err(error), Some(node) => { @@ -128,7 +131,7 @@ where match self.state.forest.input(self.remaining).match_left(&pat) { Some(n) => { let (matching, after, _) = self.remaining.split_at(n); - if n > 0 { + if after.first() > self.state.last_input_pos { self.state.last_input_pos = after.first(); self.state.expected_pats.clear(); } diff --git a/src/proc_macro.rs b/src/proc_macro.rs index 95d61cc..de841ad 100644 --- a/src/proc_macro.rs +++ b/src/proc_macro.rs @@ -139,6 +139,10 @@ impl, Pats: Deref]>> fmt::Debug for Pat< match &self.0[..] { [] => f.write_str("\"\""), [pat] => pat.fmt(f), + [FlatTokenPat::Punct { + ch: Some('\''), + joint: Some(true), + }, FlatTokenPat::Ident(None)] => f.write_str("LIFETIME"), pats => { let mut was_joint = true; f.write_str("\"")?; @@ -152,7 +156,7 @@ impl, Pats: Deref]>> fmt::Debug for Pat< was_joint = *joint == Some(true); } FlatTokenPat::Ident(Some(ident)) => { - write!(f, "\"{}\"", ident.as_ref())?; + write!(f, "{}", ident.as_ref())?; was_joint = false; } _ => unreachable!(),