Mercurial > python-compiler.rs
comparison src/main.rs @ 0:211b0df72e64
Hello world!
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Sun, 29 May 2016 19:15:02 +0100 |
parents | |
children | fa7e285f88e7 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:211b0df72e64 |
---|---|
1 extern crate cpython; | |
2 | |
3 mod python_tb; | |
4 mod python_parse; | |
5 mod python_dump; | |
6 mod python_ast; | |
7 mod ast_convert; | |
8 mod ast_dump; | |
9 //mod ast_rewrite; | |
10 mod ast_type; | |
11 | |
12 use std::fs::File; | |
13 use std::io::Read; | |
14 | |
15 fn main() { | |
16 let filename = match std::env::args().nth(1) { | |
17 Some(filename) => filename, | |
18 None => { | |
19 // TODO: use stderr instead. | |
20 println!("USAGE: {} <filename> [filename…]", std::env::args().nth(0).unwrap()); | |
21 std::process::exit(1); | |
22 } | |
23 }; | |
24 | |
25 let code = { | |
26 let mut file = match File::open(&filename) { | |
27 Ok(file) => file, | |
28 Err(err) => { | |
29 // TODO: use stderr instead. | |
30 println!("Error while opening file “{}”: {}", filename, err); | |
31 std::process::exit(2); | |
32 } | |
33 }; | |
34 let mut code = String::new(); | |
35 file.read_to_string(&mut code).unwrap(); | |
36 code | |
37 }; | |
38 | |
39 let module = match python_parse::parse_ast(code) { | |
40 Ok(module) => module, | |
41 Err(err) => { | |
42 // TODO: use stderr instead. | |
43 println!("Error while parsing file “{}”:", filename); | |
44 python_tb::traceback(err); | |
45 std::process::exit(3); | |
46 } | |
47 }; | |
48 | |
49 //python_dump::dump_module(&module); | |
50 let module_ast = ast_convert::convert_ast("__main__".to_string(), &module); | |
51 ast_dump::dump_ast(&module_ast); | |
52 //ast_rewrite::rewrite_ast(module_ast); | |
53 ast_type::type_ast(module_ast); | |
54 } |