Mercurial > python-compiler.rs
comparison src/main.rs @ 90:4e62a8927dcc
Add a symtable module, to obtain information about symbols.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Thu, 23 Jun 2016 03:16:59 +0100 |
parents | 5923cd4bfc36 |
children | c06d12a81637 |
comparison
equal
deleted
inserted
replaced
89:898876834564 | 90:4e62a8927dcc |
---|---|
4 mod tests; | 4 mod tests; |
5 | 5 |
6 mod python_tb; | 6 mod python_tb; |
7 mod python_parse; | 7 mod python_parse; |
8 mod python_ast; | 8 mod python_ast; |
9 mod python_symtable; | |
9 mod ast_convert; | 10 mod ast_convert; |
10 mod ast_dump; | 11 mod ast_dump; |
11 //mod ast_scope; | 12 //mod ast_scope; |
12 //mod ast_rewrite; | 13 //mod ast_rewrite; |
13 //mod ast_type; | 14 //mod ast_type; |
37 let mut code = String::new(); | 38 let mut code = String::new(); |
38 file.read_to_string(&mut code).unwrap(); | 39 file.read_to_string(&mut code).unwrap(); |
39 code | 40 code |
40 }; | 41 }; |
41 | 42 |
42 let module = match python_parse::parse_ast(code) { | 43 let module = match python_parse::parse_ast(code.clone()) { |
43 Ok(module) => module, | 44 Ok(module) => module, |
44 Err(err) => { | 45 Err(err) => { |
45 // TODO: use stderr instead. | 46 // TODO: use stderr instead. |
46 println!("Error while parsing file “{}”:", filename); | 47 println!("Error while parsing file “{}”:", filename); |
47 python_tb::traceback(err); | 48 python_tb::traceback(err); |
48 std::process::exit(3); | 49 std::process::exit(3); |
49 } | 50 } |
50 }; | 51 }; |
52 | |
53 let symtable = match python_symtable::generate_symtable(code, &filename) { | |
54 Ok(symtable) => symtable, | |
55 Err(err) => { | |
56 // TODO: use stderr instead. | |
57 println!("Error while parsing file “{}”:", filename); | |
58 python_tb::traceback(err); | |
59 std::process::exit(4); | |
60 } | |
61 }; | |
62 println!("{:#?}", symtable); | |
51 | 63 |
52 let module_ast = ast_convert::convert_ast("__main__".to_string(), &module); | 64 let module_ast = ast_convert::convert_ast("__main__".to_string(), &module); |
53 println!("{}", ast_dump::dump_ast(&module_ast)); | 65 println!("{}", ast_dump::dump_ast(&module_ast)); |
54 //let scoped_ast = ast_scope::scope_ast(vec!(module_ast)); | 66 //let scoped_ast = ast_scope::scope_ast(vec!(module_ast)); |
55 //println!("{:#?}", scoped_ast); | 67 //println!("{:#?}", scoped_ast); |