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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
use super::*;

pub(in crate)
struct CompileTimeString /* = */ (
    pub(in crate) String,
);

impl Parse for CompileTimeString {
    fn parse (input: ParseStream<'_>)
      -> Result<Self>
    {
        let lookahead = input.lookahead1();
        macro_rules! compile_time_string_macros {(
            $(
                $macro_name:ident !(...)
            ),+ $(,)?
        ) => ({
            mod kw {
                $(
                    ::syn::custom_keyword!($macro_name);
                )+
            }
            match () {
                _case if lookahead.peek(LitStr) => {
                    Ok(Self(
                        input
                            .parse::<LitStr>()
                            .unwrap()
                            .value()
                    ))
                },
                $(
                    _case if lookahead.peek(kw::$macro_name) => {
                        let _: kw::$macro_name = input.parse().unwrap();
                        let _: Token![!] = input.parse()?;
                        let contents = input.parse::<Group>()?.stream();
                        Ok(Self(
                            crate::builtin::$macro_name::call_on(contents)?
                        ))
                    },
                )+
                _default => Err(lookahead.error()),
            }
        })}
        return compile_time_string_macros![
            concat!(...),
            env!(...),
            include_str_from_root!(...),
            stringify!(...),
        ];
    }
}