Remove Lookahead1::cursor method
diff --git a/src/lookahead.rs b/src/lookahead.rs
index a63b9f2..15e0346 100644
--- a/src/lookahead.rs
+++ b/src/lookahead.rs
@@ -78,7 +78,7 @@
impl<'a> Lookahead1<'a> {
pub fn peek<T: Peek>(&self, token: T) -> bool {
let _ = token;
- if T::Token::peek(self) {
+ if T::Token::peek(self.cursor) {
return true;
}
self.comparisons.borrow_mut().push(T::Token::display());
@@ -104,10 +104,6 @@
}
}
}
-
- pub fn cursor(&self) -> Cursor<'a> {
- self.cursor
- }
}
/// Types that can be parsed by looking at just one token.
@@ -136,8 +132,8 @@
}
}
-pub fn is_delimiter(lookahead: &Lookahead1, delimiter: Delimiter) -> bool {
- lookahead.cursor.group(delimiter).is_some()
+pub fn is_delimiter(cursor: Cursor, delimiter: Delimiter) -> bool {
+ cursor.group(delimiter).is_some()
}
mod private {
diff --git a/src/parse.rs b/src/parse.rs
index b98361f..8c4a83d 100644
--- a/src/parse.rs
+++ b/src/parse.rs
@@ -343,7 +343,7 @@
impl<T: Parse + Token> Parse for Option<T> {
fn parse(input: ParseStream) -> Result<Self> {
- if T::peek(&input.lookahead1()) {
+ if T::peek(input.cursor()) {
Ok(Some(input.parse()?))
} else {
Ok(None)
diff --git a/src/punctuated.rs b/src/punctuated.rs
index 19fd6c6..fe29afb 100644
--- a/src/punctuated.rs
+++ b/src/punctuated.rs
@@ -704,7 +704,7 @@
loop {
let value = parser(input)?;
punctuated.push_value(value);
- if !P::peek(&input.lookahead1()) {
+ if !P::peek(input.cursor()) {
break;
}
let punct = input.parse()?;
diff --git a/src/token.rs b/src/token.rs
index 2e54077..68f9475 100644
--- a/src/token.rs
+++ b/src/token.rs
@@ -106,6 +106,8 @@
use quote::{ToTokens, TokenStreamExt};
#[cfg(feature = "parsing")]
+use buffer::Cursor;
+#[cfg(feature = "parsing")]
use error::Result;
#[cfg(any(feature = "full", feature = "derive"))]
#[cfg(feature = "parsing")]
@@ -116,7 +118,7 @@
#[cfg(feature = "parsing")]
use lookahead;
#[cfg(feature = "parsing")]
-use parse::{Lookahead1, Parse, ParseStream};
+use parse::{Parse, ParseStream};
use span::IntoSpans;
/// Marker trait for types that represent single tokens.
@@ -126,7 +128,7 @@
pub trait Token: private::Sealed {
// Not public API.
#[doc(hidden)]
- fn peek(lookahead: &Lookahead1) -> bool;
+ fn peek(cursor: Cursor) -> bool;
// Not public API.
#[doc(hidden)]
@@ -142,10 +144,9 @@
($name:ident $display:expr) => {
#[cfg(feature = "parsing")]
impl Token for $name {
- fn peek(lookahead: &Lookahead1) -> bool {
+ fn peek(cursor: Cursor) -> bool {
// TODO factor out in a way that can be compiled just once
let scope = Span::call_site();
- let cursor = lookahead.cursor();
let unexpected = Rc::new(Cell::new(None));
::private::new_parse_buffer(scope, cursor, unexpected)
.parse::<Self>()
@@ -423,8 +424,8 @@
#[cfg(feature = "parsing")]
impl Token for Paren {
- fn peek(lookahead: &Lookahead1) -> bool {
- lookahead::is_delimiter(lookahead, Delimiter::Parenthesis)
+ fn peek(cursor: Cursor) -> bool {
+ lookahead::is_delimiter(cursor, Delimiter::Parenthesis)
}
fn display() -> String {
@@ -434,8 +435,8 @@
#[cfg(feature = "parsing")]
impl Token for Brace {
- fn peek(lookahead: &Lookahead1) -> bool {
- lookahead::is_delimiter(lookahead, Delimiter::Brace)
+ fn peek(cursor: Cursor) -> bool {
+ lookahead::is_delimiter(cursor, Delimiter::Brace)
}
fn display() -> String {
@@ -445,8 +446,8 @@
#[cfg(feature = "parsing")]
impl Token for Bracket {
- fn peek(lookahead: &Lookahead1) -> bool {
- lookahead::is_delimiter(lookahead, Delimiter::Bracket)
+ fn peek(cursor: Cursor) -> bool {
+ lookahead::is_delimiter(cursor, Delimiter::Bracket)
}
fn display() -> String {
@@ -456,8 +457,8 @@
#[cfg(feature = "parsing")]
impl Token for Group {
- fn peek(lookahead: &Lookahead1) -> bool {
- lookahead::is_delimiter(lookahead, Delimiter::None)
+ fn peek(cursor: Cursor) -> bool {
+ lookahead::is_delimiter(cursor, Delimiter::None)
}
fn display() -> String {