From c0e173e19a3a7a69cda13e5c39da96c39fa09d73 Mon Sep 17 00:00:00 2001 From: Graydon Hoare Date: Fri, 20 Aug 2010 15:57:59 -0700 Subject: [PATCH] Stringify op tokens. --- src/comp/fe/token.rs | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/src/comp/fe/token.rs b/src/comp/fe/token.rs index 8896b6f7767..5e8171bccc0 100644 --- a/src/comp/fe/token.rs +++ b/src/comp/fe/token.rs @@ -152,10 +152,37 @@ type token = tag BRACEQUOTE(str), EOF()); +fn op_to_str(op o) -> str { + alt (o) { + case (PLUS()) { ret "+"; } + case (MINUS()) { ret "-"; } + case (STAR()) { ret "*"; } + case (SLASH()) { ret "/"; } + case (PERCENT()) { ret "%"; } + case (EQ()) { ret "="; } + case (LT()) { ret "<"; } + case (LE()) { ret "<="; } + case (EQEQ()) { ret "=="; } + case (NE()) { ret "!="; } + case (GE()) { ret ">="; } + case (GT()) { ret ">"; } + case (NOT()) { ret "!"; } + case (TILDE()) { ret "~"; } + case (CARET()) { ret "^"; } + case (AND()) { ret "&"; } + case (ANDAND()) { ret "&&"; } + case (OR()) { ret "|"; } + case (OROR()) { ret "||"; } + case (LSL()) { ret "<<"; } + case (LSR()) { ret ">>"; } + case (ASR()) { ret ">>>"; } + } +} + fn to_str(token t) -> str { alt (t) { - case (OP(_)) { ret ""; } - case (OPEQ(_)) { ret "="; } + case (OP(op)) { ret op_to_str(op); } + case (OPEQ(op)) { ret op_to_str(op) + "="; } case (AS()) { ret "as"; } case (WITH()) { ret "with"; }