1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
use crate::{Span, TrimmedLiteral};
pub fn annotated_literals_raw<'a>(
    source: &'a str,
) -> impl Iterator<Item = proc_macro2::Literal> + 'a {
    let stream = syn::parse_str::<proc_macro2::TokenStream>(source).expect("Must be valid rust");
    stream
        .into_iter()
        .filter_map(|x| {
            if let proc_macro2::TokenTree::Group(group) = x {
                Some(group.stream().into_iter())
            } else {
                None
            }
        })
        .flatten()
        .filter_map(|x| {
            if let proc_macro2::TokenTree::Literal(literal) = x {
                Some(literal)
            } else {
                None
            }
        })
}
pub fn annotated_literals(source: &str) -> Vec<TrimmedLiteral> {
    annotated_literals_raw(source)
        .map(|literal| {
            let span = Span::from(literal.span());
            TrimmedLiteral::load_from(source, span)
                .expect("Literals must be convertable to trimmed literals")
        })
        .collect()
}