syn_graphs/
lib.rs

1pub mod dot;
2pub mod pet;
3pub mod unparse;
4
5// transplant the unparsing logic from prettyplease
6
7use prettyplease::{algorithm, ring};
8
9const MARGIN: isize = 89;
10const INDENT: isize = 4;
11const MIN_SPACE: isize = 60;
12
13#[allow(unused)]
14mod prettyplease {
15    pub(crate) mod algorithm;
16    pub(crate) mod convenience;
17    pub(crate) mod iter;
18    pub(crate) mod lit;
19    pub(crate) mod ring;
20    pub(crate) mod token;
21}
22
23macro_rules! enum_of_kws {
24    (
25        $(#[$meta:meta])*
26        pub enum $this:ident {
27            $(
28                #[name = $lit:literal]
29                $variant:ident($inner:ty)
30            ),* $(,)?
31        }
32    ) => {
33        $(#[$meta])*
34        #[derive(
35            derive_syn_parse::Parse,
36            derive_quote_to_tokens::ToTokens,
37            Debug,
38            PartialEq,
39            Eq,
40            Clone,
41            Hash,
42        )]
43        pub enum $this {
44            $(
45                // stringify!($inner) doesn't work here
46                #[peek($inner, name = $lit)]
47                $variant($inner),
48            )*
49        }
50        impl std::fmt::Display for $this {
51            fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
52                let s = match self {
53                    $(
54                        Self::$variant(_) => $lit,
55                    )*
56                };
57                f.write_str(s)
58            }
59        }
60    };
61}
62pub(crate) use enum_of_kws;
63
64#[cfg(test)]
65macro_rules! tok {
66    ($($fn_name:ident -> $ty_name:ty),* $(,)?) => {
67        $(
68            pub fn $fn_name() -> $ty_name { Default::default() }
69        )*
70    };
71}
72#[cfg(test)]
73pub(crate) use tok;