Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make parser's fallback Ident symmetric with Group and Literal #485

Merged
merged 1 commit into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -971,6 +971,13 @@ impl Ident {
}
}

fn _new_fallback(inner: fallback::Ident) -> Self {
Ident {
inner: imp::Ident::from(inner),
_marker: MARKER,
}
}

/// Creates a new `Ident` with the given `string` as well as the specified
/// `span`.
///
Expand Down
16 changes: 6 additions & 10 deletions src/parse.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::fallback::{
self, is_ident_continue, is_ident_start, Group, LexError, Literal, Span, TokenStream,
self, is_ident_continue, is_ident_start, Group, Ident, LexError, Literal, Span, TokenStream,
TokenStreamBuilder,
};
use crate::{Delimiter, Punct, Spacing, TokenTree};
Expand Down Expand Up @@ -300,10 +300,8 @@ fn ident_any(input: Cursor) -> PResult<crate::Ident> {
let (rest, sym) = ident_not_raw(rest)?;

if !raw {
let ident = crate::Ident::_new(crate::imp::Ident::new_unchecked(
sym,
fallback::Span::call_site(),
));
let ident =
crate::Ident::_new_fallback(Ident::new_unchecked(sym, fallback::Span::call_site()));
return Ok((rest, ident));
}

Expand All @@ -312,10 +310,8 @@ fn ident_any(input: Cursor) -> PResult<crate::Ident> {
_ => {}
}

let ident = crate::Ident::_new(crate::imp::Ident::new_raw_unchecked(
sym,
fallback::Span::call_site(),
));
let ident =
crate::Ident::_new_fallback(Ident::new_raw_unchecked(sym, fallback::Span::call_site()));
Ok((rest, ident))
}

Expand Down Expand Up @@ -941,7 +937,7 @@ fn doc_comment<'a>(input: Cursor<'a>, trees: &mut TokenStreamBuilder) -> PResult
trees.push_token_from_parser(TokenTree::Punct(bang));
}

let doc_ident = crate::Ident::_new(crate::imp::Ident::new_unchecked("doc", fallback_span));
let doc_ident = crate::Ident::_new_fallback(Ident::new_unchecked("doc", fallback_span));
let mut equal = Punct::new('=', Spacing::Alone);
equal.set_span(span);
let mut literal = crate::Literal::_new_fallback(Literal::string(comment));
Expand Down
14 changes: 6 additions & 8 deletions src/wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -693,10 +693,6 @@ impl Ident {
}
}

pub(crate) fn new_unchecked(string: &str, span: fallback::Span) -> Self {
Ident::Fallback(fallback::Ident::new_unchecked(string, span))
}

#[track_caller]
pub(crate) fn new_raw_checked(string: &str, span: Span) -> Self {
match span {
Expand All @@ -705,10 +701,6 @@ impl Ident {
}
}

pub(crate) fn new_raw_unchecked(string: &str, span: fallback::Span) -> Self {
Ident::Fallback(fallback::Ident::new_raw_unchecked(string, span))
}

pub(crate) fn span(&self) -> Span {
match self {
Ident::Compiler(t) => Span::Compiler(t.span()),
Expand All @@ -733,6 +725,12 @@ impl Ident {
}
}

impl From<fallback::Ident> for Ident {
fn from(inner: fallback::Ident) -> Self {
Ident::Fallback(inner)
}
}

impl PartialEq for Ident {
fn eq(&self, other: &Ident) -> bool {
match (self, other) {
Expand Down
Loading