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