Skip to content

Commit ac665a5

Browse files
committed
feat: make Parser::*_{delimited} functions on TokenParser return Group
1 parent f071cbc commit ac665a5

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1212
### Changed
1313
- **Breaking Change** Added const generic buffer size to `TokenParser`.
1414
- **Breaking Change** `Peeker::peek` takes `&[TokenTree]` instead of `TokenParser`.
15+
- **Breaking Change** `*_{delimiter}` returns `Group` instead of the contained stream.
16+
To get to the stream call `.stream()`
1517
- `TokenParser` peeking supports `n` greater than stack buffer, allowing spilling to heap.
1618
- Increased default `TokenParser` peek buffer to `6`.
1719
- Marked parser functions as must_use.

src/assert.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ macro_rules! assert_tokens {
3333
};
3434
(@G $lhs:ident, $fn:ident, $aggr:expr, $sym:literal, $group:tt, {$($inner:tt)*}, $($rhs:tt)*) => {
3535
if let Some(lhs) = $lhs.$fn() {
36-
let mut lhs = $crate::TokenParser::<_, 3>::from(lhs);
36+
let mut lhs = $crate::TokenParser::<_, 3>::from($crate::__private::proc_macro2::Group::stream(&lhs));
3737
assert_tokens!(@O lhs, concat!($aggr, ' ', $sym), $($inner)*);
3838
} else if let Some(lhs) = $lhs.next() {
3939
assert_tokens!(@E $aggr, ($group), lhs);

src/parser.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -232,22 +232,20 @@ macro_rules! delimited {
232232
($($test:ident, $peek:ident, $peek_n:ident, $name:ident, $doc:literal;)*) => {
233233
$(#[doc = concat!("Returns the next token if it is a ", $doc ," group.")]
234234
#[must_use]
235-
pub fn $name(&mut self) -> Option<TokenStream> {
236-
self.$peek().map(|stream| {
237-
self.next().unwrap();
238-
stream
235+
pub fn $name(&mut self) -> Option<Group> {
236+
self.$peek().is_some().then(|| {
237+
self.next_group().unwrap()
239238
})
240239
})*
241240
$(#[doc = concat!("Returns the next token if it is a", $doc ," group, without advancing the parser.")]
242241
#[must_use]
243-
pub fn $peek(&mut self) -> Option<TokenStream> {
242+
pub fn $peek(&mut self) -> Option<&Group> {
244243
self.$peek_n(0)
245244
})*
246245
$(#[doc = concat!("Returns the `n`th token if it is a ", $doc ," group, without advancing the parser.")]
247246
#[must_use]
248-
pub fn $peek_n(&mut self, n: usize) -> Option<TokenStream> {
249-
self.peek_n(n).and_then(|token|
250-
token.$test().then(|| token.group().unwrap().stream()))
247+
pub fn $peek_n(&mut self, n: usize) -> Option<&Group> {
248+
self.peek_n_group(n).filter(|g| g.$test())
251249
})*
252250
};
253251
}

0 commit comments

Comments
 (0)