File tree Expand file tree Collapse file tree 2 files changed +52
-0
lines changed Expand file tree Collapse file tree 2 files changed +52
-0
lines changed Original file line number Diff line number Diff line change
1
+ use std;
2
+
3
+ fn unknown ( ) -> str {
4
+ ret "<unknown ast node>" ;
5
+ }
6
+
7
+ fn print_expr ( @ast . expr expr) -> str {
8
+ alt ( expr. node ) {
9
+ case ( ast. expr_lit ( ?lit, _) ) {
10
+ ret print_expr_lit ( lit) ;
11
+ }
12
+ case ( ast. expr_binary ( ?op, ?lhs, ?rhs, _) ) {
13
+ ret print_expr_binary ( op, lhs, rhs) ;
14
+ }
15
+ case ( _) {
16
+ ret unknown ( ) ;
17
+ }
18
+ }
19
+ }
20
+
21
+ fn print_expr_lit ( @ast. lit lit ) -> str {
22
+ alt ( lit. node ) {
23
+ case ( ast. lit_str ( ?s) ) {
24
+ ret "\" " + s + "\" " ;
25
+ }
26
+ case ( _) {
27
+ ret unknown ( ) ;
28
+ }
29
+ }
30
+ }
31
+
32
+ fn print_expr_binary ( ast. binop op , @ast. expr lhs , @ast. expr rhs ) -> str {
33
+ alt ( op) {
34
+ case ( ast. add ) {
35
+ auto l = print_expr ( lhs) ;
36
+ auto r = print_expr ( rhs) ;
37
+ ret l + " + " + r;
38
+ }
39
+ }
40
+ }
41
+
42
+ //
43
+ // Local Variables:
44
+ // mode: rust
45
+ // fill-column: 78;
46
+ // indent-tabs-mode: nil
47
+ // c-basic-offset: 4
48
+ // buffer-file-coding-system: utf-8-unix
49
+ // compile-command: "make -k -C ../.. 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
50
+ // End:
51
+ //
Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ mod front {
8
8
mod extfmt;
9
9
mod lexer;
10
10
mod parser;
11
+ mod pretty;
11
12
mod token;
12
13
mod eval;
13
14
}
You can’t perform that action at this time.
0 commit comments