David Tolnay | 4a51dc7 | 2016-10-01 00:40:31 -0700 | [diff] [blame] | 1 | use super::*; |
| 2 | |
| 3 | #[derive(Debug, Clone, Eq, PartialEq)] |
| 4 | pub struct Crate { |
| 5 | attrs: Vec<Attribute>, |
| 6 | items: Vec<Item>, |
| 7 | } |
| 8 | |
| 9 | #[cfg(feature = "parsing")] |
| 10 | pub mod parsing { |
| 11 | use super::*; |
| 12 | use attr::parsing::inner_attr; |
David Tolnay | 14cbdeb | 2016-10-01 12:13:59 -0700 | [diff] [blame^] | 13 | use space::whitespace; |
David Tolnay | 4a51dc7 | 2016-10-01 00:40:31 -0700 | [diff] [blame] | 14 | use item::parsing::item; |
David Tolnay | 4a51dc7 | 2016-10-01 00:40:31 -0700 | [diff] [blame] | 15 | |
| 16 | named!(pub krate -> Crate, do_parse!( |
| 17 | attrs: many0!(inner_attr) >> |
| 18 | items: many0!(item) >> |
David Tolnay | 14cbdeb | 2016-10-01 12:13:59 -0700 | [diff] [blame^] | 19 | option!(whitespace) >> |
David Tolnay | 4a51dc7 | 2016-10-01 00:40:31 -0700 | [diff] [blame] | 20 | (Crate { |
| 21 | attrs: attrs, |
| 22 | items: items, |
| 23 | }) |
| 24 | )); |
| 25 | } |
| 26 | |
| 27 | #[cfg(feature = "printing")] |
| 28 | mod printing { |
| 29 | use super::*; |
| 30 | use attr::FilterAttrs; |
| 31 | use quote::{Tokens, ToTokens}; |
| 32 | |
| 33 | impl ToTokens for Crate { |
| 34 | fn to_tokens(&self, tokens: &mut Tokens) { |
| 35 | for attr in self.attrs.inner() { |
| 36 | attr.to_tokens(tokens); |
| 37 | } |
| 38 | for item in &self.items { |
| 39 | item.to_tokens(tokens); |
| 40 | } |
| 41 | } |
| 42 | } |
| 43 | } |