Skip to content

Commit

Permalink
Inline lookahead::is_delimiter into delimiter Token impls
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Jun 20, 2024
1 parent 8a2a86b commit 7cc7eac
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
6 changes: 1 addition & 5 deletions src/lookahead.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::error::{self, Error};
use crate::sealed::lookahead::Sealed;
use crate::span::IntoSpans;
use crate::token::Token;
use proc_macro2::{Delimiter, Span};
use proc_macro2::Span;
use std::cell::RefCell;

/// Support for checking the next token in a stream to decide how to parse.
Expand Down Expand Up @@ -162,8 +162,4 @@ impl<S> IntoSpans<S> for TokenMarker {
}
}

pub(crate) fn is_delimiter(cursor: Cursor, delimiter: Delimiter) -> bool {
cursor.group(delimiter).is_some()
}

impl<F: Copy + FnOnce(TokenMarker) -> T, T: Token> Sealed for F {}
10 changes: 4 additions & 6 deletions src/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,6 @@ use crate::lifetime::Lifetime;
#[cfg(feature = "parsing")]
use crate::lit::{Lit, LitBool, LitByte, LitByteStr, LitChar, LitFloat, LitInt, LitStr};
#[cfg(feature = "parsing")]
use crate::lookahead;
#[cfg(feature = "parsing")]
use crate::parse::{Parse, ParseStream};
use crate::span::IntoSpans;
use proc_macro2::extra::DelimSpan;
Expand Down Expand Up @@ -692,7 +690,7 @@ impl private::Sealed for Group {}
#[cfg(feature = "parsing")]
impl Token for Paren {
fn peek(cursor: Cursor) -> bool {
lookahead::is_delimiter(cursor, Delimiter::Parenthesis)
cursor.group(Delimiter::Parenthesis).is_some()
}

fn display() -> &'static str {
Expand All @@ -703,7 +701,7 @@ impl Token for Paren {
#[cfg(feature = "parsing")]
impl Token for Brace {
fn peek(cursor: Cursor) -> bool {
lookahead::is_delimiter(cursor, Delimiter::Brace)
cursor.group(Delimiter::Brace).is_some()
}

fn display() -> &'static str {
Expand All @@ -714,7 +712,7 @@ impl Token for Brace {
#[cfg(feature = "parsing")]
impl Token for Bracket {
fn peek(cursor: Cursor) -> bool {
lookahead::is_delimiter(cursor, Delimiter::Bracket)
cursor.group(Delimiter::Bracket).is_some()
}

fn display() -> &'static str {
Expand All @@ -725,7 +723,7 @@ impl Token for Bracket {
#[cfg(feature = "parsing")]
impl Token for Group {
fn peek(cursor: Cursor) -> bool {
lookahead::is_delimiter(cursor, Delimiter::None)
cursor.group(Delimiter::None).is_some()
}

fn display() -> &'static str {
Expand Down

0 comments on commit 7cc7eac

Please sign in to comment.