From 6c193d5bebfbf466cd23d3c507ea36b628377b6b Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Sun, 25 Aug 2019 04:20:56 +0300 Subject: [PATCH 1/4] proc_macro: remove extraneous quotes in the Debug impl of Pat. --- src/proc_macro.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/proc_macro.rs b/src/proc_macro.rs index 95d61cc..06c008c 100644 --- a/src/proc_macro.rs +++ b/src/proc_macro.rs @@ -152,7 +152,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!(), From 1fc3588ab43eac96cb4c76dc8fd31adbc124d27d Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Sun, 25 Aug 2019 04:21:12 +0300 Subject: [PATCH 2/4] proc_macro: support LIFETIME in the Debug impl of Pat. --- src/proc_macro.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/proc_macro.rs b/src/proc_macro.rs index 06c008c..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("\"")?; From fdbd2745bc5fc0e04e71cfe08c1ee330db69870f Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Sun, 25 Aug 2019 04:23:51 +0300 Subject: [PATCH 3/4] parser: fix condition for resetting the expected_pats after a success. --- src/parser.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/parser.rs b/src/parser.rs index d6e025a..5e2a6f4 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -128,7 +128,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(); } From 64588e5132a9fbc5cd579912e52adeabb40c07cb Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Sun, 25 Aug 2019 04:27:21 +0300 Subject: [PATCH 4/4] parser: sort and deduplicate the expected patterns of a ParseError. --- src/parser.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/parser.rs b/src/parser.rs index 5e2a6f4..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) => {