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
This commit is contained in:
John Clements 2013-03-29 10:04:48 -07:00
parent 9f8d30a128
commit 1b4ced8bcb
5 changed files with 34 additions and 58 deletions

View File

@ -355,6 +355,10 @@ pub fn operator_prec(op: ast::binop) -> uint {
}
}
/// Precedence of the `as` operator, which is a binary operator
/// not appearing in the prior table.
pub static as_prec: uint = 11u;
pub fn dtor_ty() -> @ast::Ty {
@ast::Ty {id: 0, node: ty_nil, span: dummy_sp()}
}

View File

@ -36,9 +36,6 @@ pub mod attr;
/// Common routines shared by parser mods
pub mod common;
/// Functions dealing with operator precedence
pub mod prec;
/// Routines the parser uses to classify AST nodes
pub mod classify;

View File

@ -58,7 +58,7 @@ use ast::{view_item_, view_item_extern_mod, view_item_use};
use ast::{view_path, view_path_glob, view_path_list, view_path_simple};
use ast::visibility;
use ast;
use ast_util::{ident_to_path, operator_prec};
use ast_util::{as_prec, ident_to_path, operator_prec};
use ast_util;
use codemap::{span, BytePos, spanned, mk_sp};
use codemap;
@ -82,9 +82,8 @@ use parse::obsolete::ObsoleteMode;
use parse::obsolete::{ObsoleteLifetimeNotation, ObsoleteConstManagedPointer};
use parse::obsolete::{ObsoletePurity, ObsoleteStaticMethod};
use parse::obsolete::{ObsoleteConstItem, ObsoleteFixedLengthVectorType};
use parse::prec::{as_prec, token_to_binop};
use parse::token::{can_begin_expr, is_ident, is_ident_or_path};
use parse::token::{is_plain_ident, INTERPOLATED, special_idents};
use parse::token::{is_plain_ident, INTERPOLATED, special_idents, token_to_binop};
use parse::token;
use parse::{new_sub_parser_from_file, next_node_id, ParseSess};
use opt_vec;

View File

@ -1,52 +0,0 @@
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use ast;
use ast::*;
use parse::token::*;
use parse::token::Token;
/// Unary operators have higher precedence than binary
pub static unop_prec: uint = 100u;
/**
* Precedence of the `as` operator, which is a binary operator
* but is not represented in the precedence table.
*/
pub static as_prec: uint = 11u;
/**
* Maps a token to a record specifying the corresponding binary
* operator and its precedence
*/
pub fn token_to_binop(tok: Token) -> Option<ast::binop> {
match tok {
BINOP(STAR) => Some(mul),
BINOP(SLASH) => Some(quot),
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
}
}

View File

@ -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>,
}