]> git.proxmox.com Git - rustc.git/blob - src/libsyntax/parse/prec.rs
Imported Upstream version 0.6
[rustc.git] / src / libsyntax / parse / prec.rs
1 // Copyright 2012 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 use ast;
12 use ast::*;
13 use parse::token::*;
14 use parse::token::Token;
15
16 use core::prelude::*;
17
18 /// Unary operators have higher precedence than binary
19 pub static unop_prec: uint = 100u;
20
21 /**
22 * Precedence of the `as` operator, which is a binary operator
23 * but is not represented in the precedence table.
24 */
25 pub static as_prec: uint = 11u;
26
27 /**
28 * Maps a token to a record specifying the corresponding binary
29 * operator and its precedence
30 */
31 pub fn token_to_binop(tok: Token) -> Option<ast::binop> {
32 match tok {
33 BINOP(STAR) => Some(mul),
34 BINOP(SLASH) => Some(div),
35 BINOP(PERCENT) => Some(rem),
36 // 'as' sits between here with 11
37 BINOP(PLUS) => Some(add),
38 BINOP(MINUS) => Some(subtract),
39 BINOP(SHL) => Some(shl),
40 BINOP(SHR) => Some(shr),
41 BINOP(AND) => Some(bitand),
42 BINOP(CARET) => Some(bitxor),
43 BINOP(OR) => Some(bitor),
44 LT => Some(lt),
45 LE => Some(le),
46 GE => Some(ge),
47 GT => Some(gt),
48 EQEQ => Some(eq),
49 NE => Some(ne),
50 ANDAND => Some(and),
51 OROR => Some(or),
52 _ => None
53 }
54 }