~loic/decent-synquote-alternative

77c97122b69c44b74986b070182443c4c505899d — Loïc Lecrenier 3 years ago d987705
Work around rust-analyzer proc_macro bug
1 files changed, 19 insertions(+), 8 deletions(-)

M src/token_builder.rs
M src/token_builder.rs => src/token_builder.rs +19 -8
@@ 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);
        }
    }