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