Nika Layzell | 38b0379 | 2017-10-24 08:56:31 -0400 | [diff] [blame^] | 1 | #![cfg(all(feature = "full", feature = "extra-traits"))] |
| 2 | extern crate syn; |
| 3 | |
| 4 | use std::env; |
| 5 | use std::fs::File; |
| 6 | use std::io::{self, Read}; |
| 7 | |
| 8 | fn main() { |
| 9 | let mut args = env::args(); |
| 10 | let _ = args.next(); // executable name |
| 11 | let filename = args.next().unwrap_or_else(|| { |
| 12 | panic!("USAGE: dump-ast FILENAME"); |
| 13 | }); |
| 14 | if args.next().is_some() { |
| 15 | panic!("dump-ast only takes one argument"); |
| 16 | } |
| 17 | |
| 18 | let mut src = String::new(); |
| 19 | if filename != "-" { |
| 20 | let mut file = File::open(&filename).expect("Unable to open source file"); |
| 21 | file.read_to_string(&mut src).expect("Unable to read input file"); |
| 22 | } else { |
| 23 | io::stdin().read_to_string(&mut src).expect("Unable to read stdin"); |
| 24 | } |
| 25 | |
| 26 | let ast = syn::parse_file(&src).expect("Unable to parse file"); |
| 27 | println!("{:#?}", ast); |
| 28 | } |