Skip to content

Commit 45a06c4

Browse files
brsongraydon
authored andcommitted
---
yaml --- r: 1473 b: refs/heads/master c: 1badf93 h: refs/heads/master i: 1471: 916d26d v: v3
1 parent f14fa8e commit 45a06c4

File tree

3 files changed

+53
-1
lines changed

3 files changed

+53
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: 5e06ec977f4446a7b19a09dd3a3781bcf26f8442
2+
refs/heads/master: 1badf9316a174615e9e5c60e6cfd12e4f071d623

trunk/src/comp/front/pretty.rs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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+
//

trunk/src/comp/rustc.rc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ mod front {
88
mod extfmt;
99
mod lexer;
1010
mod parser;
11+
mod pretty;
1112
mod token;
1213
mod eval;
1314
}

0 commit comments

Comments
 (0)