blob: 58753488c48098420bc661e6de929096d7b77148 [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 Tolnayc7a5d3d2017-06-04 12:11:05 -070013 pub struct File {
14 pub shebang: Option<String>,
15 pub attrs: Vec<Attribute>,
16 pub items: Vec<Item>,
17 }
18}
19
20#[cfg(feature = "parsing")]
21pub mod parsing {
22 use super::*;
23
24 use synom::Synom;
25
26 impl Synom for File {
27 named!(parse -> Self, do_parse!(
David Tolnay2c136452017-12-27 14:13:32 -050028 attrs: many0!(Attribute::parse_inner) >>
29 items: many0!(Item::parse) >>
David Tolnayc7a5d3d2017-06-04 12:11:05 -070030 (File {
31 shebang: None,
32 attrs: attrs,
33 items: items,
34 })
35 ));
36
37 fn description() -> Option<&'static str> {
38 Some("crate")
39 }
40 }
41}
42
43#[cfg(feature = "printing")]
44mod printing {
45 use super::*;
46 use attr::FilterAttrs;
David Tolnay51382052017-12-27 13:46:21 -050047 use quote::{ToTokens, Tokens};
David Tolnayc7a5d3d2017-06-04 12:11:05 -070048
49 impl ToTokens for File {
50 fn to_tokens(&self, tokens: &mut Tokens) {
51 tokens.append_all(self.attrs.inner());
52 tokens.append_all(&self.items);
53 }
54 }
55}