| 1 | |
| 2 |
|
| 3 | use crate::attr::Attribute;
|
| 4 | use crate::item::Item;
|
| 5 |
|
| 6 | ast_struct! {
|
| 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 | |
| 53 | |
| 54 | |
| 55 | |
| 56 | |
| 57 | |
| 58 | |
| 59 | |
| 60 | |
| 61 | |
| 62 | |
| 63 | |
| 64 | |
| 65 | |
| 66 | |
| 67 | |
| 68 | |
| 69 | |
| 70 | |
| 71 | |
| 72 | |
| 73 | |
| 74 | |
| 75 | |
| 76 | |
| 77 | |
| 78 | |
| 79 | |
| 80 | #[cfg_attr(docsrs, doc(cfg(feature = "full")))]
|
| 81 | pub struct File {
|
| 82 | pub shebang: Option<String>,
|
| 83 | pub attrs: Vec<Attribute>,
|
| 84 | pub items: Vec<Item>,
|
| 85 | }
|
| 86 | }
|
| 87 |
|
| 88 | #[cfg(feature = "parsing")]
|
| 89 | pub(crate) mod parsing {
|
| 90 | use crate::attr::Attribute;
|
| 91 | use crate::error::Result;
|
| 92 | use crate::file::File;
|
| 93 | use crate::parse::{Parse, ParseStream};
|
| 94 |
|
| 95 | #[cfg_attr(docsrs, doc(cfg(feature = "parsing")))]
|
| 96 | impl Parse for File {
|
| 97 | fn parse(input: ParseStream) -> Result<Self> {
|
| 98 | Ok(File {
|
| 99 | shebang: None,
|
| 100 | attrs: input.call(Attribute::parse_inner)?,
|
| 101 | items: {
|
| 102 | let mut items = Vec::new();
|
| 103 | while !input.is_empty() {
|
| 104 | items.push(input.parse()?);
|
| 105 | }
|
| 106 | items
|
| 107 | },
|
| 108 | })
|
| 109 | }
|
| 110 | }
|
| 111 | }
|
| 112 |
|
| 113 | #[cfg(feature = "printing")]
|
| 114 | mod printing {
|
| 115 | use crate::attr::FilterAttrs;
|
| 116 | use crate::file::File;
|
| 117 | use proc_macro2::TokenStream;
|
| 118 | use quote::{ToTokens, TokenStreamExt};
|
| 119 |
|
| 120 | #[cfg_attr(docsrs, doc(cfg(feature = "printing")))]
|
| 121 | impl ToTokens for File {
|
| 122 | fn to_tokens(&self, tokens: &mut TokenStream) {
|
| 123 | tokens.append_all(self.attrs.inner());
|
| 124 | tokens.append_all(&self.items);
|
| 125 | }
|
| 126 | }
|
| 127 | }
|