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

Fix edge case of take_int and take_ident at end of string #348

Merged
merged 2 commits into from
Nov 4, 2024
Merged
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
37 changes: 17 additions & 20 deletions impl/src/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,13 @@ impl Display<'_> {
Err(_) => return,
};
if !member_index.contains_key(&member) {
out += &int;
out += int;
continue;
}
member
}
'a'..='z' | 'A'..='Z' | '_' => {
let mut ident = take_ident(&mut read);
ident.set_span(span);
let ident = Ident::new(take_ident(&mut read), span);
Member::Named(ident)
}
_ => continue,
Expand Down Expand Up @@ -214,32 +213,30 @@ fn is_syn_full() -> bool {
}
}

fn take_int(read: &mut &str) -> String {
let mut int = String::new();
for (i, ch) in read.char_indices() {
fn take_int<'a>(read: &mut &'a str) -> &'a str {
let mut int_len = 0;
for ch in read.chars() {
match ch {
'0'..='9' => int.push(ch),
_ => {
*read = &read[i..];
break;
}
'0'..='9' => int_len += 1,
_ => break,
}
}
let (int, rest) = read.split_at(int_len);
*read = rest;
int
}

fn take_ident(read: &mut &str) -> Ident {
let mut ident = String::new();
for (i, ch) in read.char_indices() {
fn take_ident<'a>(read: &mut &'a str) -> &'a str {
let mut ident_len = 0;
for ch in read.chars() {
match ch {
'a'..='z' | 'A'..='Z' | '0'..='9' | '_' => ident.push(ch),
_ => {
*read = &read[i..];
break;
}
'a'..='z' | 'A'..='Z' | '0'..='9' | '_' => ident_len += 1,
_ => break,
}
}
Ident::new(&ident, Span::call_site())
let (ident, rest) = read.split_at(ident_len);
*read = rest;
ident
}

fn raw_if_needed(ident: &Ident) -> Ident {
Expand Down
Loading