Skip to content

Commit 968b03c

Browse files
committed
Move check for full parse into token_stream parser
1 parent cd58340 commit 968b03c

File tree

2 files changed

+6
-11
lines changed

2 files changed

+6
-11
lines changed

src/fallback.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::parse::{token_stream, Cursor};
1+
use crate::parse::{self, Cursor};
22
use crate::{Delimiter, Spacing, TokenTree};
33
#[cfg(span_locations)]
44
use std::cell::RefCell;
@@ -139,12 +139,7 @@ impl FromStr for TokenStream {
139139
// Create a dummy file & add it to the source map
140140
let cursor = get_cursor(src);
141141

142-
let (rest, tokens) = token_stream(cursor)?;
143-
if rest.is_empty() {
144-
Ok(tokens)
145-
} else {
146-
Err(LexError)
147-
}
142+
parse::token_stream(cursor)
148143
}
149144
}
150145

src/parse.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ impl<'a> Cursor<'a> {
2626
self.rest.starts_with(s)
2727
}
2828

29-
pub(crate) fn is_empty(&self) -> bool {
29+
fn is_empty(&self) -> bool {
3030
self.rest.is_empty()
3131
}
3232

@@ -148,7 +148,7 @@ fn word_break(input: Cursor) -> Result<Cursor, LexError> {
148148
}
149149
}
150150

151-
pub(crate) fn token_stream(mut input: Cursor) -> PResult<TokenStream> {
151+
pub(crate) fn token_stream(mut input: Cursor) -> Result<TokenStream, LexError> {
152152
let mut trees = Vec::new();
153153
let mut stack = Vec::new();
154154

@@ -217,8 +217,8 @@ pub(crate) fn token_stream(mut input: Cursor) -> PResult<TokenStream> {
217217
}
218218
}
219219

220-
if stack.is_empty() {
221-
Ok((input, TokenStream { inner: trees }))
220+
if stack.is_empty() && input.is_empty() {
221+
Ok(TokenStream { inner: trees })
222222
} else {
223223
Err(LexError)
224224
}

0 commit comments

Comments
 (0)