summary refs log tree commit diff
path: root/src/libsyntax/parse/token.rs
diff options
context:
space:
mode:
authorJohn Clements <clements@racket-lang.org>2013-03-29 10:04:48 -0700
committerJohn Clements <clements@racket-lang.org>2013-04-28 09:51:14 -0700
commit1b4ced8bcb39ab29ba1caaea0a44e881ccbbc9e1 (patch)
treef4be55a431eebc2f610f986fff3b57146c56c8c0 /src/libsyntax/parse/token.rs
parent9f8d30a128aa8a75a3304e0e91178dcfb5535554 (diff)
downloadrust-1b4ced8bcb39ab29ba1caaea0a44e881ccbbc9e1.tar.gz
rust-1b4ced8bcb39ab29ba1caaea0a44e881ccbbc9e1.zip
get rid of prec.rs
prec.rs no longer had much to do with precedence; the token->binop
function fits better in token.rs, and the one-liner defining the
precedence of 'as' can go next to the other precedence stuff in
ast_util.rs
Diffstat (limited to 'src/libsyntax/parse/token.rs')
-rw-r--r--src/libsyntax/parse/token.rs28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs
index 2f8acbcece7..0327a3b80da 100644
--- a/src/libsyntax/parse/token.rs
+++ b/src/libsyntax/parse/token.rs
@@ -364,6 +364,34 @@ impl<'self> to_bytes::IterBytes for StringRef<'self> {
     }
 }
 
+/**
+ * Maps a token to a record specifying the corresponding binary
+ * operator
+ */
+pub fn token_to_binop(tok: Token) -> Option<ast::binop> {
+  match tok {
+      BINOP(STAR)    => Some(ast::mul),
+      BINOP(SLASH)   => Some(ast::quot),
+      BINOP(PERCENT) => Some(ast::rem),
+      BINOP(PLUS)    => Some(ast::add),
+      BINOP(MINUS)   => Some(ast::subtract),
+      BINOP(SHL)     => Some(ast::shl),
+      BINOP(SHR)     => Some(ast::shr),
+      BINOP(AND)     => Some(ast::bitand),
+      BINOP(CARET)   => Some(ast::bitxor),
+      BINOP(OR)      => Some(ast::bitor),
+      LT             => Some(ast::lt),
+      LE             => Some(ast::le),
+      GE             => Some(ast::ge),
+      GT             => Some(ast::gt),
+      EQEQ           => Some(ast::eq),
+      NE             => Some(ast::ne),
+      ANDAND         => Some(ast::and),
+      OROR           => Some(ast::or),
+      _              => None
+  }
+}
+
 pub struct ident_interner {
     priv interner: Interner<@~str>,
 }