about summary refs log tree commit diff
path: root/src/libsyntax/parse/prec.rs
blob: e2e35447af3f49070bb48fb86e4121fc37e1bc41 (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
export as_prec;
export unop_prec;
export token_to_binop;

import token::*;
import token::token;
import ast::*;

#[doc = "Unary operators have higher precedence than binary"]
const unop_prec: uint = 100u;

#[doc = "
Precedence of the `as` operator, which is a binary operator
but is not represented in the precedence table.
"]
const as_prec: uint = 11u;

#[doc = "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 }
  }
}