1
- use std;
1
+ import std. _int ;
2
+ import std. _str ;
3
+ import std. _uint ;
4
+ import std. _vec ;
5
+
6
+ export print_expr;
2
7
3
8
fn unknown ( ) -> str {
4
9
ret "<unknown ast node>" ;
@@ -7,22 +12,34 @@ fn unknown() -> str {
7
12
fn print_expr ( @ast . expr expr) -> str {
8
13
alt ( expr. node ) {
9
14
case ( ast. expr_lit ( ?lit, _) ) {
10
- ret print_expr_lit ( lit) ;
15
+ ret print_lit ( lit) ;
11
16
}
12
17
case ( ast. expr_binary ( ?op, ?lhs, ?rhs, _) ) {
13
18
ret print_expr_binary ( op, lhs, rhs) ;
14
19
}
20
+ case ( ast. expr_call ( ?path, ?args, _) ) {
21
+ ret print_expr_call ( path, args) ;
22
+ }
23
+ case ( ast. expr_path ( ?path, _, _) ) {
24
+ ret print_path ( path) ;
25
+ }
15
26
case ( _) {
16
27
ret unknown ( ) ;
17
28
}
18
29
}
19
30
}
20
31
21
- fn print_expr_lit ( @ast. lit lit ) -> str {
32
+ fn print_lit ( @ast. lit lit ) -> str {
22
33
alt ( lit. node ) {
23
34
case ( ast. lit_str ( ?s) ) {
24
35
ret "\" " + s + "\" " ;
25
36
}
37
+ case ( ast. lit_int ( ?i) ) {
38
+ ret _int. to_str ( i, 10 u) ;
39
+ }
40
+ case ( ast. lit_uint ( ?u) ) {
41
+ ret _uint. to_str ( u, 10 u) ;
42
+ }
26
43
case ( _) {
27
44
ret unknown ( ) ;
28
45
}
@@ -39,6 +56,23 @@ fn print_expr_binary(ast.binop op, @ast.expr lhs, @ast.expr rhs) -> str {
39
56
}
40
57
}
41
58
59
+ fn print_expr_call ( @ast. expr path_expr , vec[ @ast. expr] args) -> str {
60
+ auto s = print_expr ( path_expr) ;
61
+
62
+ s += "(" ;
63
+ fn print_expr_ref ( & @ast. expr e ) -> str { ret print_expr ( e) ; }
64
+ auto mapfn = print_expr_ref;
65
+ auto argstrs = _vec. map [ @ast. expr , str] ( mapfn, args) ;
66
+ s += _str. connect ( argstrs, ", " ) ;
67
+ s += ")" ;
68
+
69
+ ret s;
70
+ }
71
+
72
+ fn print_path ( ast . path path) -> str {
73
+ ret _str. connect ( path. node . idents , "." ) ;
74
+ }
75
+
42
76
//
43
77
// Local Variables:
44
78
// mode: rust
0 commit comments