Skip to content

Commit 1b4ced8

Browse files
committed
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
1 parent 9f8d30a commit 1b4ced8

File tree

5 files changed

+34
-58
lines changed

5 files changed

+34
-58
lines changed

src/libsyntax/ast_util.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,10 @@ pub fn operator_prec(op: ast::binop) -> uint {
355355
}
356356
}
357357
358+
/// Precedence of the `as` operator, which is a binary operator
359+
/// not appearing in the prior table.
360+
pub static as_prec: uint = 11u;
361+
358362
pub fn dtor_ty() -> @ast::Ty {
359363
@ast::Ty {id: 0, node: ty_nil, span: dummy_sp()}
360364
}

src/libsyntax/parse/mod.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,6 @@ pub mod attr;
3636
/// Common routines shared by parser mods
3737
pub mod common;
3838

39-
/// Functions dealing with operator precedence
40-
pub mod prec;
41-
4239
/// Routines the parser uses to classify AST nodes
4340
pub mod classify;
4441

src/libsyntax/parse/parser.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ use ast::{view_item_, view_item_extern_mod, view_item_use};
5858
use ast::{view_path, view_path_glob, view_path_list, view_path_simple};
5959
use ast::visibility;
6060
use ast;
61-
use ast_util::{ident_to_path, operator_prec};
61+
use ast_util::{as_prec, ident_to_path, operator_prec};
6262
use ast_util;
6363
use codemap::{span, BytePos, spanned, mk_sp};
6464
use codemap;
@@ -82,9 +82,8 @@ use parse::obsolete::ObsoleteMode;
8282
use parse::obsolete::{ObsoleteLifetimeNotation, ObsoleteConstManagedPointer};
8383
use parse::obsolete::{ObsoletePurity, ObsoleteStaticMethod};
8484
use parse::obsolete::{ObsoleteConstItem, ObsoleteFixedLengthVectorType};
85-
use parse::prec::{as_prec, token_to_binop};
8685
use parse::token::{can_begin_expr, is_ident, is_ident_or_path};
87-
use parse::token::{is_plain_ident, INTERPOLATED, special_idents};
86+
use parse::token::{is_plain_ident, INTERPOLATED, special_idents, token_to_binop};
8887
use parse::token;
8988
use parse::{new_sub_parser_from_file, next_node_id, ParseSess};
9089
use opt_vec;

src/libsyntax/parse/prec.rs

Lines changed: 0 additions & 52 deletions
This file was deleted.

src/libsyntax/parse/token.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,34 @@ impl<'self> to_bytes::IterBytes for StringRef<'self> {
364364
}
365365
}
366366
367+
/**
368+
* Maps a token to a record specifying the corresponding binary
369+
* operator
370+
*/
371+
pub fn token_to_binop(tok: Token) -> Option<ast::binop> {
372+
match tok {
373+
BINOP(STAR) => Some(ast::mul),
374+
BINOP(SLASH) => Some(ast::quot),
375+
BINOP(PERCENT) => Some(ast::rem),
376+
BINOP(PLUS) => Some(ast::add),
377+
BINOP(MINUS) => Some(ast::subtract),
378+
BINOP(SHL) => Some(ast::shl),
379+
BINOP(SHR) => Some(ast::shr),
380+
BINOP(AND) => Some(ast::bitand),
381+
BINOP(CARET) => Some(ast::bitxor),
382+
BINOP(OR) => Some(ast::bitor),
383+
LT => Some(ast::lt),
384+
LE => Some(ast::le),
385+
GE => Some(ast::ge),
386+
GT => Some(ast::gt),
387+
EQEQ => Some(ast::eq),
388+
NE => Some(ast::ne),
389+
ANDAND => Some(ast::and),
390+
OROR => Some(ast::or),
391+
_ => None
392+
}
393+
}
394+
367395
pub struct ident_interner {
368396
priv interner: Interner<@~str>,
369397
}

0 commit comments

Comments
 (0)