blob: 8ea7306e1808787ba284a7c74f38a05d29b12f54 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
export as_prec;
export unop_prec;
export token_to_binop;
import token::*;
import token::token;
import ast::*;
/// Unary operators have higher precedence than binary
const unop_prec: uint = 100u;
/**
* Precedence of the `as` operator, which is a binary operator
* but is not represented in the precedence table.
*/
const as_prec: uint = 11u;
/**
* Maps a token to a record specifying the corresponding binary
* operator and its precedence
*/
fn token_to_binop(tok: token) -> option<ast::binop> {
alt tok {
BINOP(STAR) { some(mul) }
BINOP(SLASH) { some(div) }
BINOP(PERCENT) { some(rem) }
// 'as' sits between here with 11
BINOP(PLUS) { some(add) }
BINOP(MINUS) { some(subtract) }
BINOP(SHL) { some(shl) }
BINOP(SHR) { some(shr) }
BINOP(AND) { some(bitand) }
BINOP(CARET) { some(bitxor) }
BINOP(OR) { some(bitor) }
LT { some(lt) }
LE { some(le) }
GE { some(ge) }
GT { some(gt) }
EQEQ { some(eq) }
NE { some(ne) }
ANDAND { some(and) }
OROR { some(or) }
_ { none }
}
}
|