Prototype for support of custom keywords
First prototype for support of custom keywords with syn's new parsing
API. Documentation and tests aren't present for now as I'm mainly
reaching for feedback.
This patch introduces a new Keyword trait, a new macro custom_keyword!
and exposes the existing TokenMarker enum. The Keyword trait
automatically implements the Token trait, making it possible to peek on
custom keywords (this is why I had to make TokenMarker public).
The custom macro generates a structure storing an Ident and implementing
the Keyword and Parse traits. A function with the same name as the
structure is also generated in order to use it like any predefined
keyword.
diff --git a/src/token.rs b/src/token.rs
index 4a44067..637d901 100644
--- a/src/token.rs
+++ b/src/token.rs
@@ -118,7 +118,7 @@
#[cfg(feature = "parsing")]
use lookahead;
#[cfg(feature = "parsing")]
-use parse::{Parse, ParseStream};
+use parse::{Keyword, Parse, ParseStream};
use span::IntoSpans;
/// Marker trait for types that represent single tokens.
@@ -144,6 +144,9 @@
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));