Custom keywords polish
diff --git a/src/token.rs b/src/token.rs
index 637d901..8892c33 100644
--- a/src/token.rs
+++ b/src/token.rs
@@ -118,7 +118,7 @@
#[cfg(feature = "parsing")]
use lookahead;
#[cfg(feature = "parsing")]
-use parse::{Keyword, Parse, ParseStream};
+use parse::{Parse, ParseStream};
use span::IntoSpans;
/// Marker trait for types that represent single tokens.
@@ -144,9 +144,6 @@
impl private::Sealed for Ident {}
#[cfg(feature = "parsing")]
-impl<K: Keyword> private::Sealed for K {}
-
-#[cfg(feature = "parsing")]
fn peek_impl(cursor: Cursor, peek: fn(ParseStream) -> bool) -> bool {
let scope = Span::call_site();
let unexpected = Rc::new(Cell::new(None));
@@ -194,6 +191,28 @@
#[cfg(any(feature = "full", feature = "derive"))]
impl_token!(LitBool "boolean literal");
+// Not public API.
+#[cfg(feature = "parsing")]
+#[doc(hidden)]
+pub trait CustomKeyword {
+ fn ident() -> &'static str;
+ fn display() -> &'static str;
+}
+
+#[cfg(feature = "parsing")]
+impl<K: CustomKeyword> private::Sealed for K {}
+
+#[cfg(feature = "parsing")]
+impl<K: CustomKeyword> Token for K {
+ fn peek(cursor: Cursor) -> bool {
+ parsing::peek_keyword(cursor, K::ident())
+ }
+
+ fn display() -> &'static str {
+ K::display()
+ }
+}
+
macro_rules! define_keywords {
($($token:tt pub struct $name:ident #[$doc:meta])*) => {
$(