Lifetimes as single tokens from cursor
diff --git a/src/buffer.rs b/src/buffer.rs
index 9c5738f..b918a9a 100644
--- a/src/buffer.rs
+++ b/src/buffer.rs
@@ -20,12 +20,13 @@
feature = "proc-macro"
))]
use proc_macro as pm;
-use proc_macro2::{Delimiter, Ident, Literal, Span, TokenStream};
-use proc_macro2::{Group, Punct, TokenTree};
+use proc_macro2::{Delimiter, Group, Ident, Literal, Punct, Spacing, Span, TokenStream, TokenTree};
use std::marker::PhantomData;
use std::ptr;
+use Lifetime;
+
/// Internal type which is used instead of `TokenTree` to represent a token tree
/// within a `TokenBuffer`.
enum Entry {
@@ -266,7 +267,9 @@
pub fn punct(mut self) -> Option<(Punct, Cursor<'a>)> {
self.ignore_none();
match *self.entry() {
- Entry::Punct(ref op) => Some((op.clone(), unsafe { self.bump() })),
+ Entry::Punct(ref op) if op.as_char() != '\'' => {
+ Some((op.clone(), unsafe { self.bump() }))
+ }
_ => None,
}
}
@@ -281,6 +284,28 @@
}
}
+ /// If the cursor is pointing at a `Lifetime`, returns it along with a
+ /// cursor pointing at the next `TokenTree`.
+ pub fn lifetime(mut self) -> Option<(Lifetime, Cursor<'a>)> {
+ self.ignore_none();
+ match *self.entry() {
+ Entry::Punct(ref op) if op.as_char() == '\'' && op.spacing() == Spacing::Joint => {
+ let next = unsafe { self.bump() };
+ match next.ident() {
+ Some((ident, rest)) => {
+ let lifetime = Lifetime {
+ apostrophe: op.span(),
+ ident: ident,
+ };
+ Some((lifetime, rest))
+ }
+ None => None,
+ }
+ }
+ _ => None,
+ }
+ }
+
/// Copies all remaining tokens visible from this cursor into a
/// `TokenStream`.
pub fn token_stream(self) -> TokenStream {