David Tolnay | c7a5d3d | 2017-06-04 12:11:05 -0700 | [diff] [blame] | 1 | use super::*; |
| 2 | |
| 3 | ast_struct! { |
| 4 | pub struct File { |
| 5 | pub shebang: Option<String>, |
| 6 | pub attrs: Vec<Attribute>, |
| 7 | pub items: Vec<Item>, |
| 8 | } |
| 9 | } |
| 10 | |
| 11 | #[cfg(feature = "parsing")] |
| 12 | pub mod parsing { |
| 13 | use super::*; |
| 14 | |
| 15 | use synom::Synom; |
| 16 | |
| 17 | impl Synom for File { |
| 18 | named!(parse -> Self, do_parse!( |
| 19 | attrs: many0!(call!(Attribute::parse_inner)) >> |
| 20 | items: many0!(syn!(Item)) >> |
| 21 | (File { |
| 22 | shebang: None, |
| 23 | attrs: attrs, |
| 24 | items: items, |
| 25 | }) |
| 26 | )); |
| 27 | |
| 28 | fn description() -> Option<&'static str> { |
| 29 | Some("crate") |
| 30 | } |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | #[cfg(feature = "printing")] |
| 35 | mod printing { |
| 36 | use super::*; |
| 37 | use attr::FilterAttrs; |
David Tolnay | 5138205 | 2017-12-27 13:46:21 -0500 | [diff] [blame^] | 38 | use quote::{ToTokens, Tokens}; |
David Tolnay | c7a5d3d | 2017-06-04 12:11:05 -0700 | [diff] [blame] | 39 | |
| 40 | impl ToTokens for File { |
| 41 | fn to_tokens(&self, tokens: &mut Tokens) { |
| 42 | tokens.append_all(self.attrs.inner()); |
| 43 | tokens.append_all(&self.items); |
| 44 | } |
| 45 | } |
| 46 | } |