Skip to content
This repository was archived by the owner on Oct 6, 2024. It is now read-only.

Commit 5f4b1b6

Browse files
committed
Move ident-specific string cleanup out of segments
1 parent 181e987 commit 5f4b1b6

File tree

2 files changed

+20
-14
lines changed

2 files changed

+20
-14
lines changed

src/lib.rs

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -332,21 +332,35 @@ fn parse_bracket_as_segments(input: TokenStream, scope: Span) -> Result<Vec<Segm
332332
None => return Err(Error::new(scope, "expected `[< ... >]`")),
333333
}
334334

335-
let segments = segment::parse(&mut tokens)?;
335+
let mut segments = segment::parse(&mut tokens)?;
336336

337337
match &tokens.next() {
338338
Some(TokenTree::Punct(punct)) if punct.as_char() == '>' => {}
339339
Some(wrong) => return Err(Error::new(wrong.span(), "expected `>`")),
340340
None => return Err(Error::new(scope, "expected `[< ... >]`")),
341341
}
342342

343-
match tokens.next() {
344-
Some(unexpected) => Err(Error::new(
343+
if let Some(unexpected) = tokens.next() {
344+
return Err(Error::new(
345345
unexpected.span(),
346346
"unexpected input, expected `[< ... >]`",
347-
)),
348-
None => Ok(segments),
347+
));
349348
}
349+
350+
for segment in &mut segments {
351+
if let Segment::String(string) = segment {
352+
if string.value.contains(&['#', '\\', '.', '+'][..]) {
353+
return Err(Error::new(string.span, "unsupported literal"));
354+
}
355+
string.value = string
356+
.value
357+
.replace('"', "")
358+
.replace('\'', "")
359+
.replace('-', "_");
360+
}
361+
}
362+
363+
Ok(segments)
350364
}
351365

352366
fn pasted_to_tokens(mut pasted: String, span: Span) -> Result<TokenStream> {

src/segment.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -96,16 +96,8 @@ pub(crate) fn parse(tokens: &mut Peekable<token_stream::IntoIter>) -> Result<Vec
9696
}
9797
}
9898
TokenTree::Literal(lit) => {
99-
let mut lit_string = lit.to_string();
100-
if lit_string.contains(&['#', '\\', '.', '+'][..]) {
101-
return Err(Error::new(lit.span(), "unsupported literal"));
102-
}
103-
lit_string = lit_string
104-
.replace('"', "")
105-
.replace('\'', "")
106-
.replace('-', "_");
10799
segments.push(Segment::String(LitStr {
108-
value: lit_string,
100+
value: lit.to_string(),
109101
span: lit.span(),
110102
}));
111103
}

0 commit comments

Comments
 (0)