blob: 357cf6e4dcfa42e6ff233a0d61ba1ff6524b6156 [file] [log] [blame]
David Tolnay55535012018-01-05 16:39:23 -08001// Copyright 2018 Syn Developers
2//
3// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
4// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
5// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
6// option. This file may not be copied, modified, or distributed
7// except according to those terms.
8
David Tolnayc7a5d3d2017-06-04 12:11:05 -07009use super::*;
10
11ast_struct! {
David Tolnay48445662018-01-07 01:06:48 -080012 /// A complete file of Rust source code.
David Tolnay461d98e2018-01-07 11:07:19 -080013 ///
14 /// *This type is available if Syn is built with the `"full"` feature.*
David Tolnayc7a5d3d2017-06-04 12:11:05 -070015 pub struct File {
16 pub shebang: Option<String>,
17 pub attrs: Vec<Attribute>,
18 pub items: Vec<Item>,
19 }
20}
21
22#[cfg(feature = "parsing")]
23pub mod parsing {
24 use super::*;
25
26 use synom::Synom;
27
28 impl Synom for File {
29 named!(parse -> Self, do_parse!(
David Tolnay2c136452017-12-27 14:13:32 -050030 attrs: many0!(Attribute::parse_inner) >>
31 items: many0!(Item::parse) >>
David Tolnayc7a5d3d2017-06-04 12:11:05 -070032 (File {
33 shebang: None,
34 attrs: attrs,
35 items: items,
36 })
37 ));
38
39 fn description() -> Option<&'static str> {
40 Some("crate")
41 }
42 }
43}
44
45#[cfg(feature = "printing")]
46mod printing {
47 use super::*;
48 use attr::FilterAttrs;
David Tolnay51382052017-12-27 13:46:21 -050049 use quote::{ToTokens, Tokens};
David Tolnayc7a5d3d2017-06-04 12:11:05 -070050
51 impl ToTokens for File {
52 fn to_tokens(&self, tokens: &mut Tokens) {
53 tokens.append_all(self.attrs.inner());
54 tokens.append_all(&self.items);
55 }
56 }
57}