diff options
| author | Marijn Haverbeke <[email protected]> | 2011-03-04 07:22:43 +0100 |
|---|---|---|
| committer | Graydon Hoare <[email protected]> | 2011-03-07 12:58:08 -0800 |
| commit | 0624f9db4aeaa5681941750c3a1a17ca5fbb7e72 (patch) | |
| tree | 91844d79c0c5614ce660c3c20f1c67eaef2d5021 /src/comp/front | |
| parent | Construct the wrappers to native functions. Hello world now works :-) (diff) | |
| download | rust-0624f9db4aeaa5681941750c3a1a17ca5fbb7e72.tar.xz rust-0624f9db4aeaa5681941750c3a1a17ca5fbb7e72.zip | |
Add a pretty-printer
Adds a -pp option to the compiler which will cause it to simply
pretty-print the given file.
Diffstat (limited to 'src/comp/front')
| -rw-r--r-- | src/comp/front/ast.rs | 36 | ||||
| -rw-r--r-- | src/comp/front/parser.rs | 1 | ||||
| -rw-r--r-- | src/comp/front/pretty.rs | 2 |
3 files changed, 39 insertions, 0 deletions
diff --git a/src/comp/front/ast.rs b/src/comp/front/ast.rs index ed1e2114..d45260f3 100644 --- a/src/comp/front/ast.rs +++ b/src/comp/front/ast.rs @@ -122,6 +122,31 @@ tag binop { gt; } +fn binop_to_str(binop op) -> str { + alt (op) { + case (add) {ret "+";} + case (sub) {ret "-";} + case (mul) {ret "*";} + case (div) {ret "/";} + case (rem) {ret "%";} + case (and) {ret "&&";} + case (or) {ret "||";} + case (bitxor) {ret "^";} + case (bitand) {ret "&";} + case (bitor) {ret "|";} + case (lsl) {ret "<<";} + case (lsr) {ret ">>";} + case (asr) {ret ">>>";} + case (eq) {ret "==";} + case (lt) {ret "<";} + case (le) {ret "<=";} + case (ne) {ret "!=";} + case (ge) {ret ">=";} + case (gt) {ret ">";} + } +} + + tag unop { box; deref; @@ -131,6 +156,17 @@ tag unop { _mutable; } +fn unop_to_str(unop op) -> str { + alt (op) { + case (box) {ret "@";} + case (deref) {ret "*";} + case (bitnot) {ret "~";} + case (not) {ret "!";} + case (neg) {ret "-";} + case (_mutable) {ret "mutable";} + } +} + tag mode { val; alias; diff --git a/src/comp/front/parser.rs b/src/comp/front/parser.rs index 6f3111c7..f60ff36b 100644 --- a/src/comp/front/parser.rs +++ b/src/comp/front/parser.rs @@ -983,6 +983,7 @@ impure fn parse_prefix_expr(parser p) -> @ast.expr { type op_spec = rec(token.token tok, ast.binop op, int prec); +// FIXME make this a const, don't store it in parser state fn prec_table() -> vec[op_spec] { ret vec(rec(tok=token.BINOP(token.STAR), op=ast.mul, prec=11), rec(tok=token.BINOP(token.SLASH), op=ast.div, prec=11), diff --git a/src/comp/front/pretty.rs b/src/comp/front/pretty.rs index 267763e3..2fd58126 100644 --- a/src/comp/front/pretty.rs +++ b/src/comp/front/pretty.rs @@ -5,6 +5,8 @@ import std._vec; export print_expr; +// FIXME this is superseded by ../pretty/pprust.rs. can it be dropped? + fn unknown() -> str { ret "<unknown ast node>"; } |