Put rest last
diff --git a/src/attr.rs b/src/attr.rs
index 3955876..b95ac9f 100644
--- a/src/attr.rs
+++ b/src/attr.rs
@@ -423,7 +423,7 @@
fn lit_doc_comment(input: Cursor) -> PResult<TokenTree> {
match input.literal() {
- Some((rest, span, lit)) => {
+ Some((span, lit, rest)) => {
let literal = lit.to_string();
if literal.starts_with("//") || literal.starts_with("/*") {
Ok((
diff --git a/src/cursor.rs b/src/cursor.rs
index f4fe859..570322d 100644
--- a/src/cursor.rs
+++ b/src/cursor.rs
@@ -101,12 +101,6 @@
}
}
-pub struct Group<'a> {
- pub span: Span,
- pub inside: Cursor<'a>,
- pub outside: Cursor<'a>,
-}
-
/// A cursor into an input `TokenStream`'s data. This cursor holds a reference
/// into the immutable data which is used internally to represent a
/// `TokenStream`, and can be efficiently manipulated and copied around.
@@ -208,7 +202,7 @@
/// If the cursor is pointing at a Group with the given `Delimiter`, return
/// a cursor into that group, and one pointing to the next `TokenTree`.
- pub fn group(mut self, delim: Delimiter) -> Option<Group<'a>> {
+ pub fn group(mut self, delim: Delimiter) -> Option<(Cursor<'a>, Span, Cursor<'a>)> {
// If we're not trying to enter a none-delimited group, we want to
// ignore them. We have to make sure to _not_ ignore them when we want
// to enter them, of course. For obvious reasons.
@@ -218,11 +212,7 @@
if let Entry::Group(span, group_delim, ref buf) = *self.entry() {
if group_delim == delim {
- return Some(Group {
- span: span,
- inside: buf.begin(),
- outside: unsafe { self.bump() },
- });
+ return Some((buf.begin(), span, unsafe { self.bump() }));
}
}
@@ -231,30 +221,30 @@
/// If the cursor is pointing at a Term, return it and a cursor pointing at
/// the next `TokenTree`.
- pub fn term(mut self) -> Option<(Cursor<'a>, Span, Term)> {
+ pub fn term(mut self) -> Option<(Span, Term, Cursor<'a>)> {
self.ignore_none();
match *self.entry() {
- Entry::Term(span, term) => Some((unsafe { self.bump() }, span, term)),
+ Entry::Term(span, term) => Some((span, term, unsafe { self.bump() })),
_ => None,
}
}
/// If the cursor is pointing at an Op, return it and a cursor pointing
/// at the next `TokenTree`.
- pub fn op(mut self) -> Option<(Cursor<'a>, Span, char, Spacing)> {
+ pub fn op(mut self) -> Option<(Span, char, Spacing, Cursor<'a>)> {
self.ignore_none();
match *self.entry() {
- Entry::Op(span, chr, spacing) => Some((unsafe { self.bump() }, span, chr, spacing)),
+ Entry::Op(span, op, spacing) => Some((span, op, spacing, unsafe { self.bump() })),
_ => None,
}
}
/// If the cursor is pointing at a Literal, return it and a cursor pointing
/// at the next `TokenTree`.
- pub fn literal(mut self) -> Option<(Cursor<'a>, Span, Literal)> {
+ pub fn literal(mut self) -> Option<(Span, Literal, Cursor<'a>)> {
self.ignore_none();
match *self.entry() {
- Entry::Literal(span, ref lit) => Some((unsafe { self.bump() }, span, lit.clone())),
+ Entry::Literal(span, ref lit) => Some((span, lit.clone(), unsafe { self.bump() })),
_ => None,
}
}
@@ -263,9 +253,9 @@
pub fn token_stream(self) -> TokenStream {
let mut tts = Vec::new();
let mut cursor = self;
- while let Some((next, tt)) = cursor.token_tree() {
+ while let Some((tt, rest)) = cursor.token_tree() {
tts.push(tt);
- cursor = next;
+ cursor = rest;
}
tts.into_iter().collect()
}
@@ -276,7 +266,7 @@
///
/// This method does not treat `None`-delimited groups as invisible, and
/// will return a `Group(None, ..)` if the cursor is looking at one.
- pub fn token_tree(self) -> Option<(Cursor<'a>, TokenTree)> {
+ pub fn token_tree(self) -> Option<(TokenTree, Cursor<'a>)> {
let tree = match *self.entry() {
Entry::Group(span, delim, ref buf) => {
let stream = buf.begin().token_stream();
@@ -302,7 +292,7 @@
}
};
- Some((unsafe { self.bump() }, tree))
+ Some((tree, unsafe { self.bump() }))
}
}
diff --git a/src/ident.rs b/src/ident.rs
index f370e34..21a5cbd 100644
--- a/src/ident.rs
+++ b/src/ident.rs
@@ -231,7 +231,7 @@
impl Synom for Ident {
fn parse(input: Cursor) -> PResult<Self> {
- let (rest, span, term) = match input.term() {
+ let (span, term, rest) = match input.term() {
Some(term) => term,
_ => return parse_error(),
};
diff --git a/src/lifetime.rs b/src/lifetime.rs
index 65f3f37..8c47dba 100644
--- a/src/lifetime.rs
+++ b/src/lifetime.rs
@@ -99,7 +99,7 @@
impl Synom for Lifetime {
fn parse(input: Cursor) -> PResult<Self> {
- let (rest, span, term) = match input.term() {
+ let (span, term, rest) = match input.term() {
Some(term) => term,
_ => return parse_error(),
};
diff --git a/src/lit.rs b/src/lit.rs
index b7b1e3e..539e30d 100644
--- a/src/lit.rs
+++ b/src/lit.rs
@@ -105,7 +105,7 @@
impl Synom for Lit {
fn parse(input: Cursor) -> PResult<Self> {
match input.literal() {
- Some((rest, span, lit)) => Ok((
+ Some((span, lit, rest)) => Ok((
rest,
Lit {
span: span,
@@ -113,7 +113,7 @@
},
)),
_ => match input.term() {
- Some((rest, span, term)) => {
+ Some((span, term, rest)) => {
let kind = if term.as_str() == "true" {
LitKind::Bool(true)
} else if term.as_str() == "false" {
diff --git a/src/token.rs b/src/token.rs
index a41b6e8..6872922 100644
--- a/src/token.rs
+++ b/src/token.rs
@@ -510,7 +510,7 @@
for (i, (ch, slot)) in chars.zip(&mut spans).enumerate() {
match tokens.op() {
- Some((rest, span, c, kind)) if c == ch => {
+ Some((span, op, kind, rest)) if op == ch => {
if i != s.len() - 1 {
match kind {
Spacing::Joint => {}
@@ -527,7 +527,7 @@
}
pub fn keyword<'a, T>(keyword: &str, tokens: Cursor<'a>, new: fn(Span) -> T) -> PResult<'a, T> {
- if let Some((rest, span, term)) = tokens.term() {
+ if let Some((span, term, rest)) = tokens.term() {
if term.as_str() == keyword {
return Ok((rest, new(span)));
}
@@ -553,11 +553,11 @@
_ => panic!("unknown delimiter: {}", delim),
};
- if let Some(group) = tokens.group(delim) {
- match f(group.inside) {
+ if let Some((inside, span, rest)) = tokens.group(delim) {
+ match f(inside) {
Ok((remaining, ret)) => {
if remaining.eof() {
- return Ok((group.outside, (new(group.span), ret)));
+ return Ok((rest, (new(span), ret)));
}
}
Err(err) => return Err(err),
diff --git a/src/tt.rs b/src/tt.rs
index d8d497b..a3bebe3 100644
--- a/src/tt.rs
+++ b/src/tt.rs
@@ -11,11 +11,11 @@
pub fn delimited(input: Cursor) -> PResult<(MacroDelimiter, TokenStream)> {
match input.token_tree() {
Some((
- rest,
TokenTree {
span,
kind: TokenNode::Group(delimiter, tts),
},
+ rest,
)) => {
let delimiter = match delimiter {
Delimiter::Parenthesis => MacroDelimiter::Paren(Paren(span)),
@@ -33,11 +33,11 @@
pub fn braced(input: Cursor) -> PResult<(Brace, TokenStream)> {
match input.token_tree() {
Some((
- rest,
TokenTree {
span,
kind: TokenNode::Group(Delimiter::Brace, tts),
},
+ rest,
)) => Ok((rest, (Brace(span), tts))),
_ => parse_error(),
}
@@ -47,11 +47,11 @@
pub fn parenthesized(input: Cursor) -> PResult<(Paren, TokenStream)> {
match input.token_tree() {
Some((
- rest,
TokenTree {
span,
kind: TokenNode::Group(Delimiter::Parenthesis, tts),
},
+ rest,
)) => Ok((rest, (Paren(span), tts))),
_ => parse_error(),
}