@@ 1,3 1,5 @@
+use std::str::FromStr;
+
use proc_macro2::{Delimiter, Group, Ident, Literal, Punct, TokenStream, TokenTree};
pub trait TokenBuilderExtend {
@@ 122,10 124,14 @@ impl TokenBuilder {
let mut between_delimiter_matches = what.split(is_delimiter);
if let Some(first_match_no_delimiter) = between_delimiter_matches.next() {
- let ts = first_match_no_delimiter.parse::<TokenStream>().expect(&format!(
- "Could not parse the following string into a token stream: {}",
- first_match_no_delimiter
- ));
+ let ts = if first_match_no_delimiter.trim().is_empty() {
+ TokenStream::new()
+ } else {
+ proc_macro2::TokenStream::from_str(first_match_no_delimiter).expect(&format!(
+ "Could not parse the following string into a token stream: bye {}",
+ first_match_no_delimiter
+ ))
+ };
self.extend(&ts);
}
@@ 139,10 145,15 @@ impl TokenBuilder {
"]" => self.pop_group(Delimiter::Bracket),
_ => unreachable!(),
}
- let ts = ts.parse::<TokenStream>().expect(&format!(
- "Could not parse the following string into a token stream: {}",
- ts
- ));
+ let ts = if ts.trim().is_empty() {
+ TokenStream::new()
+ } else {
+ proc_macro2::TokenStream::from_str(ts).expect(&format!(
+ "Could not parse the following string into a token stream: hello {}",
+ ts
+ ))
+ };
+
self.extend(&ts);
}
}