Skip to content

Commit 688910f

Browse files
committed
TokenParser::span
1 parent 7157c84 commit 688910f

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7-
<!-- ## [Unreleased] -->
7+
## [Unreleased]
8+
### Added
9+
- `span()` to `TokenParser`.
810

911
## [0.9.0] - 2024-03-13
1012
### Added

src/parser.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::{iter, mem};
44

55
#[cfg(doc)]
66
use proc_macro2::Spacing;
7-
use proc_macro2::{token_stream, Group, Ident, Literal, Punct, TokenStream, TokenTree};
7+
use proc_macro2::{token_stream, Group, Ident, Literal, Punct, Span, TokenStream, TokenTree};
88
use smallvec::{smallvec, SmallVec};
99

1010
use crate::{Delimited, TokenStream2Ext, TokenTree2Ext, TokenTreeLiteral, TokenTreePunct};
@@ -362,6 +362,12 @@ impl<I, const PEEKER_LEN: usize> TokenParser<I, PEEKER_LEN>
362362
where
363363
I: Iterator<Item = TokenTree>,
364364
{
365+
/// Returns span of the next token or [`Span::call_site()`].
366+
#[must_use]
367+
pub fn span(&mut self) -> Span {
368+
self.peek().map_or_else(Span::call_site, TokenTree::span)
369+
}
370+
365371
/// Checks if there are remaining tokens
366372
/// ```
367373
/// use proc_macro_utils::TokenParser;

0 commit comments

Comments
 (0)