2012-09-04 13:37:29 -05:00
|
|
|
use util::interner;
|
|
|
|
use util::interner::interner;
|
|
|
|
use std::map::{hashmap, str_hash};
|
|
|
|
use std::serialization::{serializer,
|
2012-05-21 12:45:56 -05:00
|
|
|
deserializer,
|
|
|
|
serialize_uint,
|
|
|
|
deserialize_uint,
|
|
|
|
serialize_i64,
|
|
|
|
deserialize_i64,
|
|
|
|
serialize_u64,
|
|
|
|
deserialize_u64,
|
|
|
|
serialize_bool,
|
|
|
|
deserialize_bool};
|
2010-08-18 13:35:12 -05:00
|
|
|
|
2012-05-21 12:45:56 -05:00
|
|
|
#[auto_serialize]
|
2011-05-09 16:17:28 -05:00
|
|
|
type str_num = uint;
|
|
|
|
|
2012-05-21 12:45:56 -05:00
|
|
|
#[auto_serialize]
|
2012-01-19 16:24:03 -06:00
|
|
|
enum binop {
|
2012-01-19 19:56:05 -06:00
|
|
|
PLUS,
|
|
|
|
MINUS,
|
|
|
|
STAR,
|
|
|
|
SLASH,
|
|
|
|
PERCENT,
|
|
|
|
CARET,
|
|
|
|
AND,
|
|
|
|
OR,
|
2012-05-22 16:59:15 -05:00
|
|
|
SHL,
|
|
|
|
SHR,
|
2010-09-09 17:59:29 -05:00
|
|
|
}
|
|
|
|
|
2012-05-21 12:45:56 -05:00
|
|
|
#[auto_serialize]
|
2012-01-19 16:24:03 -06:00
|
|
|
enum token {
|
2010-09-09 17:59:29 -05:00
|
|
|
/* Expression-operator symbols. */
|
2012-01-19 19:56:05 -06:00
|
|
|
EQ,
|
|
|
|
LT,
|
|
|
|
LE,
|
|
|
|
EQEQ,
|
|
|
|
NE,
|
|
|
|
GE,
|
|
|
|
GT,
|
|
|
|
ANDAND,
|
|
|
|
OROR,
|
|
|
|
NOT,
|
|
|
|
TILDE,
|
|
|
|
BINOP(binop),
|
|
|
|
BINOPEQ(binop),
|
2010-09-09 17:59:29 -05:00
|
|
|
|
|
|
|
/* Structural symbols */
|
2012-01-19 19:56:05 -06:00
|
|
|
AT,
|
|
|
|
DOT,
|
2012-08-03 20:01:30 -05:00
|
|
|
DOTDOT,
|
2012-01-19 19:56:05 -06:00
|
|
|
ELLIPSIS,
|
|
|
|
COMMA,
|
|
|
|
SEMI,
|
|
|
|
COLON,
|
|
|
|
MOD_SEP,
|
|
|
|
RARROW,
|
|
|
|
LARROW,
|
|
|
|
DARROW,
|
2012-06-04 20:34:10 -05:00
|
|
|
FAT_ARROW,
|
2012-01-19 19:56:05 -06:00
|
|
|
LPAREN,
|
|
|
|
RPAREN,
|
|
|
|
LBRACKET,
|
|
|
|
RBRACKET,
|
|
|
|
LBRACE,
|
|
|
|
RBRACE,
|
|
|
|
POUND,
|
2012-04-22 18:58:04 -05:00
|
|
|
DOLLAR,
|
2012-01-25 17:38:09 -06:00
|
|
|
|
2010-09-09 17:59:29 -05:00
|
|
|
/* Literals */
|
2012-01-19 19:56:05 -06:00
|
|
|
LIT_INT(i64, ast::int_ty),
|
|
|
|
LIT_UINT(u64, ast::uint_ty),
|
2012-06-14 21:41:40 -05:00
|
|
|
LIT_INT_UNSUFFIXED(i64),
|
2012-01-19 19:56:05 -06:00
|
|
|
LIT_FLOAT(str_num, ast::float_ty),
|
|
|
|
LIT_STR(str_num),
|
2010-09-09 17:59:29 -05:00
|
|
|
|
|
|
|
/* Name components */
|
2012-01-19 19:56:05 -06:00
|
|
|
IDENT(str_num, bool),
|
|
|
|
UNDERSCORE,
|
2012-06-12 12:50:17 -05:00
|
|
|
|
2012-06-29 20:26:34 -05:00
|
|
|
/* For interpolation */
|
2012-07-27 21:14:46 -05:00
|
|
|
INTERPOLATED(nonterminal),
|
2012-06-12 12:50:17 -05:00
|
|
|
|
2012-06-30 05:54:54 -05:00
|
|
|
DOC_COMMENT(str_num),
|
2012-01-19 19:56:05 -06:00
|
|
|
EOF,
|
2010-09-09 17:59:29 -05:00
|
|
|
}
|
2010-08-18 13:35:12 -05:00
|
|
|
|
2012-06-12 12:50:17 -05:00
|
|
|
#[auto_serialize]
|
2012-07-04 16:53:12 -05:00
|
|
|
/// For interpolation during macro expansion.
|
2012-07-27 21:14:46 -05:00
|
|
|
enum nonterminal {
|
|
|
|
nt_item(@ast::item),
|
|
|
|
nt_block(ast::blk),
|
|
|
|
nt_stmt(@ast::stmt),
|
|
|
|
nt_pat( @ast::pat),
|
|
|
|
nt_expr(@ast::expr),
|
|
|
|
nt_ty( @ast::ty),
|
|
|
|
nt_ident(str_num, bool),
|
|
|
|
nt_path(@ast::path),
|
|
|
|
nt_tt( @ast::token_tree), //needs @ed to break a circularity
|
|
|
|
nt_matchers(~[ast::matcher])
|
2012-06-12 12:50:17 -05:00
|
|
|
}
|
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
fn binop_to_str(o: binop) -> ~str {
|
2012-08-06 14:34:08 -05:00
|
|
|
match o {
|
2012-08-03 21:59:04 -05:00
|
|
|
PLUS => ~"+",
|
|
|
|
MINUS => ~"-",
|
|
|
|
STAR => ~"*",
|
|
|
|
SLASH => ~"/",
|
|
|
|
PERCENT => ~"%",
|
|
|
|
CARET => ~"^",
|
|
|
|
AND => ~"&",
|
|
|
|
OR => ~"|",
|
|
|
|
SHL => ~"<<",
|
|
|
|
SHR => ~">>"
|
2010-08-20 17:57:59 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
fn to_str(in: interner<@~str>, t: token) -> ~str {
|
2012-08-06 14:34:08 -05:00
|
|
|
match t {
|
2012-08-03 21:59:04 -05:00
|
|
|
EQ => ~"=",
|
|
|
|
LT => ~"<",
|
|
|
|
LE => ~"<=",
|
|
|
|
EQEQ => ~"==",
|
|
|
|
NE => ~"!=",
|
|
|
|
GE => ~">=",
|
|
|
|
GT => ~">",
|
|
|
|
NOT => ~"!",
|
|
|
|
TILDE => ~"~",
|
|
|
|
OROR => ~"||",
|
|
|
|
ANDAND => ~"&&",
|
|
|
|
BINOP(op) => binop_to_str(op),
|
|
|
|
BINOPEQ(op) => binop_to_str(op) + ~"=",
|
2011-09-02 17:34:58 -05:00
|
|
|
|
2011-07-27 07:19:39 -05:00
|
|
|
/* Structural symbols */
|
2012-08-03 21:59:04 -05:00
|
|
|
AT => ~"@",
|
|
|
|
DOT => ~".",
|
|
|
|
DOTDOT => ~"..",
|
|
|
|
ELLIPSIS => ~"...",
|
|
|
|
COMMA => ~",",
|
|
|
|
SEMI => ~";",
|
|
|
|
COLON => ~":",
|
|
|
|
MOD_SEP => ~"::",
|
|
|
|
RARROW => ~"->",
|
|
|
|
LARROW => ~"<-",
|
|
|
|
DARROW => ~"<->",
|
|
|
|
FAT_ARROW => ~"=>",
|
|
|
|
LPAREN => ~"(",
|
|
|
|
RPAREN => ~")",
|
|
|
|
LBRACKET => ~"[",
|
|
|
|
RBRACKET => ~"]",
|
|
|
|
LBRACE => ~"{",
|
|
|
|
RBRACE => ~"}",
|
|
|
|
POUND => ~"#",
|
|
|
|
DOLLAR => ~"$",
|
2012-01-25 17:38:09 -06:00
|
|
|
|
2011-07-27 07:19:39 -05:00
|
|
|
/* Literals */
|
2012-08-03 21:59:04 -05:00
|
|
|
LIT_INT(c, ast::ty_char) => {
|
2012-07-14 00:57:48 -05:00
|
|
|
~"'" + char::escape_default(c as char) + ~"'"
|
2011-12-07 14:06:12 -06:00
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
LIT_INT(i, t) => {
|
2012-06-11 18:49:35 -05:00
|
|
|
int::to_str(i as int, 10u) + ast_util::int_ty_to_str(t)
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
LIT_UINT(u, t) => {
|
2012-06-11 18:49:35 -05:00
|
|
|
uint::to_str(u as uint, 10u) + ast_util::uint_ty_to_str(t)
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
LIT_INT_UNSUFFIXED(i) => {
|
2012-06-14 21:41:40 -05:00
|
|
|
int::to_str(i as int, 10u)
|
2012-06-11 18:31:03 -05:00
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
LIT_FLOAT(s, t) => {
|
2012-07-31 13:49:20 -05:00
|
|
|
let mut body = *in.get(s);
|
2012-08-03 13:22:35 -05:00
|
|
|
if body.ends_with(~".") {
|
|
|
|
body = body + ~"0"; // `10.f` is not a float literal
|
2012-07-31 13:49:20 -05:00
|
|
|
}
|
|
|
|
body + ast_util::float_ty_to_str(t)
|
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
LIT_STR(s) => { ~"\"" + str::escape_default( *in.get(s)) + ~"\"" }
|
2012-06-30 05:54:54 -05:00
|
|
|
|
2011-07-27 07:19:39 -05:00
|
|
|
/* Name components */
|
2012-08-03 21:59:04 -05:00
|
|
|
IDENT(s, _) => *in.get(s),
|
2012-07-17 13:22:11 -05:00
|
|
|
|
2012-08-03 21:59:04 -05:00
|
|
|
UNDERSCORE => ~"_",
|
2012-06-30 05:54:54 -05:00
|
|
|
|
|
|
|
/* Other */
|
2012-08-03 21:59:04 -05:00
|
|
|
DOC_COMMENT(s) => *in.get(s),
|
|
|
|
EOF => ~"<eof>",
|
|
|
|
INTERPOLATED(nt) => {
|
2012-07-14 00:57:48 -05:00
|
|
|
~"an interpolated " +
|
2012-08-06 14:34:08 -05:00
|
|
|
match nt {
|
2012-08-03 21:59:04 -05:00
|
|
|
nt_item(*) => ~"item",
|
|
|
|
nt_block(*) => ~"block",
|
|
|
|
nt_stmt(*) => ~"statement",
|
|
|
|
nt_pat(*) => ~"pattern",
|
|
|
|
nt_expr(*) => ~"expression",
|
|
|
|
nt_ty(*) => ~"type",
|
|
|
|
nt_ident(*) => ~"identifier",
|
|
|
|
nt_path(*) => ~"path",
|
|
|
|
nt_tt(*) => ~"tt",
|
|
|
|
nt_matchers(*) => ~"matcher sequence"
|
2012-07-06 16:48:01 -05:00
|
|
|
}
|
2012-06-29 20:26:34 -05:00
|
|
|
}
|
2010-08-20 13:41:34 -05:00
|
|
|
}
|
|
|
|
}
|
2011-07-03 13:48:14 -05:00
|
|
|
|
2011-08-24 15:41:50 -05:00
|
|
|
pure fn can_begin_expr(t: token) -> bool {
|
2012-08-06 14:34:08 -05:00
|
|
|
match t {
|
2012-08-03 21:59:04 -05:00
|
|
|
LPAREN => true,
|
|
|
|
LBRACE => true,
|
|
|
|
LBRACKET => true,
|
|
|
|
IDENT(_, _) => true,
|
|
|
|
UNDERSCORE => true,
|
|
|
|
TILDE => true,
|
|
|
|
LIT_INT(_, _) => true,
|
|
|
|
LIT_UINT(_, _) => true,
|
|
|
|
LIT_INT_UNSUFFIXED(_) => true,
|
|
|
|
LIT_FLOAT(_, _) => true,
|
|
|
|
LIT_STR(_) => true,
|
|
|
|
POUND => true,
|
|
|
|
AT => true,
|
|
|
|
NOT => true,
|
|
|
|
BINOP(MINUS) => true,
|
|
|
|
BINOP(STAR) => true,
|
|
|
|
BINOP(AND) => true,
|
|
|
|
BINOP(OR) => true, // in lambda syntax
|
|
|
|
OROR => true, // in lambda syntax
|
|
|
|
MOD_SEP => true,
|
2012-07-27 21:14:46 -05:00
|
|
|
INTERPOLATED(nt_expr(*))
|
|
|
|
| INTERPOLATED(nt_ident(*))
|
|
|
|
| INTERPOLATED(nt_block(*))
|
2012-08-03 21:59:04 -05:00
|
|
|
| INTERPOLATED(nt_path(*)) => true,
|
|
|
|
_ => false
|
2011-07-03 13:48:14 -05:00
|
|
|
}
|
|
|
|
}
|
2011-10-07 09:22:53 -05:00
|
|
|
|
2012-07-31 15:53:00 -05:00
|
|
|
/// what's the opposite delimiter?
|
|
|
|
fn flip_delimiter(&t: token::token) -> token::token {
|
2012-08-06 14:34:08 -05:00
|
|
|
match t {
|
2012-08-03 21:59:04 -05:00
|
|
|
token::LPAREN => token::RPAREN,
|
|
|
|
token::LBRACE => token::RBRACE,
|
|
|
|
token::LBRACKET => token::RBRACKET,
|
|
|
|
token::RPAREN => token::LPAREN,
|
|
|
|
token::RBRACE => token::LBRACE,
|
|
|
|
token::RBRACKET => token::LBRACKET,
|
|
|
|
_ => fail
|
2012-07-31 15:53:00 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-06-11 18:49:35 -05:00
|
|
|
fn is_lit(t: token) -> bool {
|
2012-08-06 14:34:08 -05:00
|
|
|
match t {
|
2012-08-03 21:59:04 -05:00
|
|
|
LIT_INT(_, _) => true,
|
|
|
|
LIT_UINT(_, _) => true,
|
|
|
|
LIT_INT_UNSUFFIXED(_) => true,
|
|
|
|
LIT_FLOAT(_, _) => true,
|
|
|
|
LIT_STR(_) => true,
|
|
|
|
_ => false
|
2012-06-11 18:49:35 -05:00
|
|
|
}
|
2012-04-22 16:59:04 -05:00
|
|
|
}
|
|
|
|
|
2012-06-11 18:49:35 -05:00
|
|
|
pure fn is_ident(t: token) -> bool {
|
2012-08-06 14:34:08 -05:00
|
|
|
match t { IDENT(_, _) => true, _ => false }
|
2012-04-17 23:14:40 -05:00
|
|
|
}
|
|
|
|
|
2012-08-06 15:09:10 -05:00
|
|
|
pure fn is_ident_or_path(t: token) -> bool {
|
2012-08-06 14:34:08 -05:00
|
|
|
match t {
|
2012-08-06 15:09:10 -05:00
|
|
|
IDENT(_, _) | INTERPOLATED(nt_path(*)) => true,
|
|
|
|
_ => false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-11 18:49:35 -05:00
|
|
|
pure fn is_plain_ident(t: token) -> bool {
|
2012-08-06 14:34:08 -05:00
|
|
|
match t { IDENT(_, false) => true, _ => false }
|
2012-04-17 23:14:40 -05:00
|
|
|
}
|
|
|
|
|
2012-06-11 18:49:35 -05:00
|
|
|
pure fn is_bar(t: token) -> bool {
|
2012-08-06 14:34:08 -05:00
|
|
|
match t { BINOP(OR) | OROR => true, _ => false }
|
2012-04-17 23:14:40 -05:00
|
|
|
}
|
|
|
|
|
2012-08-02 16:33:26 -05:00
|
|
|
|
2012-08-02 17:34:13 -05:00
|
|
|
mod special_idents {
|
2012-07-18 18:18:02 -05:00
|
|
|
import ast::ident;
|
|
|
|
const underscore : ident = 0u;
|
|
|
|
const anon : ident = 1u;
|
|
|
|
const dtor : ident = 2u; // 'drop', but that's reserved
|
|
|
|
const invalid : ident = 3u; // ''
|
|
|
|
const unary : ident = 4u;
|
|
|
|
const not_fn : ident = 5u;
|
|
|
|
const idx_fn : ident = 6u;
|
|
|
|
const unary_minus_fn : ident = 7u;
|
|
|
|
const clownshoes_extensions : ident = 8u;
|
|
|
|
|
|
|
|
const self_ : ident = 9u; // 'self'
|
|
|
|
|
|
|
|
/* for matcher NTs */
|
|
|
|
const item : ident = 10u;
|
|
|
|
const block : ident = 11u;
|
|
|
|
const stmt : ident = 12u;
|
|
|
|
const pat : ident = 13u;
|
|
|
|
const expr : ident = 14u;
|
|
|
|
const ty : ident = 15u;
|
|
|
|
const ident : ident = 16u;
|
|
|
|
const path : ident = 17u;
|
|
|
|
const tt : ident = 18u;
|
|
|
|
const matchers : ident = 19u;
|
|
|
|
|
|
|
|
const str : ident = 20u; // for the type
|
|
|
|
|
|
|
|
/* outside of libsyntax */
|
|
|
|
const ty_visitor : ident = 21u;
|
|
|
|
const arg : ident = 22u;
|
|
|
|
const descrim : ident = 23u;
|
|
|
|
const clownshoe_abi : ident = 24u;
|
|
|
|
const clownshoe_stack_shim : ident = 25u;
|
|
|
|
const tydesc : ident = 26u;
|
|
|
|
const literally_dtor : ident = 27u;
|
|
|
|
const main : ident = 28u;
|
|
|
|
const opaque : ident = 29u;
|
|
|
|
const blk : ident = 30u;
|
|
|
|
const static : ident = 31u;
|
|
|
|
const intrinsic : ident = 32u;
|
2012-08-29 14:22:05 -05:00
|
|
|
const clownshoes_foreign_mod: ident = 33;
|
2012-08-02 17:34:13 -05:00
|
|
|
}
|
|
|
|
|
2012-07-18 18:18:02 -05:00
|
|
|
type ident_interner = util::interner::interner<@~str>;
|
|
|
|
|
|
|
|
/** Key for thread-local data for sneaking interner information to the
|
2012-08-24 14:19:19 -05:00
|
|
|
* serializer/deserializer. It sounds like a hack because it is one.
|
|
|
|
* Bonus ultra-hack: functions as keys don't work across crates,
|
|
|
|
* so we have to use a unique number. See taskgroup_key! in task.rs
|
|
|
|
* for another case of this. */
|
|
|
|
macro_rules! interner_key (
|
|
|
|
() => (unsafe::transmute::<(uint, uint), &fn(+@@token::ident_interner)>(
|
|
|
|
(-3 as uint, 0u)))
|
|
|
|
)
|
2012-07-18 18:18:02 -05:00
|
|
|
|
2012-08-02 16:33:26 -05:00
|
|
|
fn mk_ident_interner() -> ident_interner {
|
2012-08-02 17:34:13 -05:00
|
|
|
/* the indices here must correspond to the numbers in special_idents */
|
2012-07-18 18:18:02 -05:00
|
|
|
let init_vec = ~[@~"_", @~"anon", @~"drop", @~"", @~"unary", @~"!",
|
|
|
|
@~"[]", @~"unary-", @~"__extensions__", @~"self",
|
|
|
|
@~"item", @~"block", @~"stmt", @~"pat", @~"expr",
|
|
|
|
@~"ty", @~"ident", @~"path", @~"tt", @~"matchers",
|
2012-09-02 17:19:52 -05:00
|
|
|
@~"str", @~"TyVisitor", @~"arg", @~"descrim",
|
|
|
|
@~"__rust_abi", @~"__rust_stack_shim", @~"TyDesc",
|
2012-07-18 18:18:02 -05:00
|
|
|
@~"dtor", @~"main", @~"<opaque>", @~"blk", @~"static",
|
2012-08-29 14:22:05 -05:00
|
|
|
@~"intrinsic", @~"__foreign_mod__"];
|
2012-08-02 17:34:13 -05:00
|
|
|
|
2012-09-07 19:24:02 -05:00
|
|
|
let rv = interner::mk_prefill::<@~str>(init_vec);
|
2012-07-18 18:18:02 -05:00
|
|
|
|
|
|
|
/* having multiple interners will just confuse the serializer */
|
2012-08-27 18:26:35 -05:00
|
|
|
unsafe{ assert task::local_data_get(interner_key!()).is_none() };
|
2012-08-24 14:19:19 -05:00
|
|
|
unsafe{ task::local_data_set(interner_key!(), @rv) };
|
2012-08-02 16:33:26 -05:00
|
|
|
rv
|
|
|
|
}
|
|
|
|
|
2012-07-18 18:18:02 -05:00
|
|
|
/* for when we don't care about the contents; doesn't interact with TLD or
|
|
|
|
serialization */
|
|
|
|
fn mk_fake_ident_interner() -> ident_interner {
|
2012-09-07 19:24:02 -05:00
|
|
|
interner::mk::<@~str>()
|
2012-07-18 18:18:02 -05:00
|
|
|
}
|
|
|
|
|
2012-07-04 16:53:12 -05:00
|
|
|
/**
|
|
|
|
* All the valid words that have meaning in the Rust language.
|
|
|
|
*
|
|
|
|
* Rust keywords are either 'contextual' or 'restricted'. Contextual
|
|
|
|
* keywords may be used as identifiers because their appearance in
|
|
|
|
* the grammar is unambiguous. Restricted keywords may not appear
|
|
|
|
* in positions that might otherwise contain _value identifiers_.
|
|
|
|
*/
|
2012-07-14 00:57:48 -05:00
|
|
|
fn keyword_table() -> hashmap<~str, ()> {
|
2012-04-19 18:44:24 -05:00
|
|
|
let keywords = str_hash();
|
2012-06-30 18:19:07 -05:00
|
|
|
for contextual_keyword_table().each_key |word| {
|
2012-04-25 00:33:49 -05:00
|
|
|
keywords.insert(word, ());
|
|
|
|
}
|
2012-06-30 18:19:07 -05:00
|
|
|
for restricted_keyword_table().each_key |word| {
|
2012-04-19 18:44:24 -05:00
|
|
|
keywords.insert(word, ());
|
|
|
|
}
|
2012-06-11 18:49:35 -05:00
|
|
|
keywords
|
2012-04-25 00:33:49 -05:00
|
|
|
}
|
|
|
|
|
2012-07-04 16:53:12 -05:00
|
|
|
/// Keywords that may be used as identifiers
|
2012-07-14 00:57:48 -05:00
|
|
|
fn contextual_keyword_table() -> hashmap<~str, ()> {
|
2012-04-25 00:33:49 -05:00
|
|
|
let words = str_hash();
|
2012-06-29 18:26:56 -05:00
|
|
|
let keys = ~[
|
2012-07-14 00:57:48 -05:00
|
|
|
~"as",
|
|
|
|
~"else",
|
|
|
|
~"move",
|
|
|
|
~"priv", ~"pub",
|
2012-09-07 16:52:28 -05:00
|
|
|
~"self", ~"static",
|
2012-09-04 15:29:32 -05:00
|
|
|
~"use"
|
2012-06-29 18:26:56 -05:00
|
|
|
];
|
2012-06-30 18:19:07 -05:00
|
|
|
for keys.each |word| {
|
2012-04-25 00:33:49 -05:00
|
|
|
words.insert(word, ());
|
2012-04-19 18:44:24 -05:00
|
|
|
}
|
2012-04-25 00:33:49 -05:00
|
|
|
words
|
2012-04-19 18:44:24 -05:00
|
|
|
}
|
|
|
|
|
2012-07-04 16:53:12 -05:00
|
|
|
/**
|
|
|
|
* Keywords that may not appear in any position that might otherwise contain a
|
|
|
|
* _value identifier_. Restricted keywords may still be used as other types of
|
|
|
|
* identifiers.
|
|
|
|
*
|
|
|
|
* Reasons:
|
|
|
|
*
|
|
|
|
* * For some (most?), if used at the start of a line, they will cause the
|
|
|
|
* line to be interpreted as a specific kind of statement, which would be
|
|
|
|
* confusing.
|
|
|
|
*
|
|
|
|
* * `true` or `false` as identifiers would always be shadowed by
|
|
|
|
* the boolean constants
|
|
|
|
*/
|
2012-07-14 00:57:48 -05:00
|
|
|
fn restricted_keyword_table() -> hashmap<~str, ()> {
|
2012-04-17 23:14:40 -05:00
|
|
|
let words = str_hash();
|
2012-06-29 18:26:56 -05:00
|
|
|
let keys = ~[
|
2012-09-07 17:32:04 -05:00
|
|
|
~"assert",
|
2012-07-14 00:57:48 -05:00
|
|
|
~"break",
|
2012-09-04 17:43:46 -05:00
|
|
|
~"const", ~"copy",
|
2012-07-14 00:57:48 -05:00
|
|
|
~"do", ~"drop",
|
|
|
|
~"else", ~"enum", ~"export", ~"extern",
|
|
|
|
~"fail", ~"false", ~"fn", ~"for",
|
2012-08-17 14:27:57 -05:00
|
|
|
~"if", ~"impl", ~"import",
|
2012-07-14 00:57:48 -05:00
|
|
|
~"let", ~"log", ~"loop",
|
2012-09-07 17:59:44 -05:00
|
|
|
~"match", ~"mod", ~"move", ~"mut",
|
2012-07-11 17:00:40 -05:00
|
|
|
~"pure",
|
2012-08-01 19:30:05 -05:00
|
|
|
~"ref", ~"return",
|
2012-07-11 17:00:40 -05:00
|
|
|
~"struct",
|
2012-07-14 00:57:48 -05:00
|
|
|
~"true", ~"trait", ~"type",
|
|
|
|
~"unchecked", ~"unsafe",
|
|
|
|
~"while"
|
2012-06-29 18:26:56 -05:00
|
|
|
];
|
2012-06-30 18:19:07 -05:00
|
|
|
for keys.each |word| {
|
2012-04-17 23:14:40 -05:00
|
|
|
words.insert(word, ());
|
|
|
|
}
|
|
|
|
words
|
|
|
|
}
|
|
|
|
|
2012-08-27 18:26:35 -05:00
|
|
|
impl binop : cmp::Eq {
|
|
|
|
pure fn eq(&&other: binop) -> bool {
|
|
|
|
(self as uint) == (other as uint)
|
|
|
|
}
|
2012-09-07 14:06:02 -05:00
|
|
|
pure fn ne(&&other: binop) -> bool { !self.eq(other) }
|
2012-08-27 18:26:35 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
impl token : cmp::Eq {
|
|
|
|
pure fn eq(&&other: token) -> bool {
|
|
|
|
match self {
|
|
|
|
EQ => {
|
|
|
|
match other {
|
|
|
|
EQ => true,
|
|
|
|
_ => false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
LT => {
|
|
|
|
match other {
|
|
|
|
LT => true,
|
|
|
|
_ => false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
LE => {
|
|
|
|
match other {
|
|
|
|
LE => true,
|
|
|
|
_ => false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
EQEQ => {
|
|
|
|
match other {
|
|
|
|
EQEQ => true,
|
|
|
|
_ => false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
NE => {
|
|
|
|
match other {
|
|
|
|
NE => true,
|
|
|
|
_ => false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
GE => {
|
|
|
|
match other {
|
|
|
|
GE => true,
|
|
|
|
_ => false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
GT => {
|
|
|
|
match other {
|
|
|
|
GT => true,
|
|
|
|
_ => false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ANDAND => {
|
|
|
|
match other {
|
|
|
|
ANDAND => true,
|
|
|
|
_ => false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
OROR => {
|
|
|
|
match other {
|
|
|
|
OROR => true,
|
|
|
|
_ => false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
NOT => {
|
|
|
|
match other {
|
|
|
|
NOT => true,
|
|
|
|
_ => false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
TILDE => {
|
|
|
|
match other {
|
|
|
|
TILDE => true,
|
|
|
|
_ => false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
BINOP(e0a) => {
|
|
|
|
match other {
|
|
|
|
BINOP(e0b) => e0a == e0b,
|
|
|
|
_ => false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
BINOPEQ(e0a) => {
|
|
|
|
match other {
|
|
|
|
BINOPEQ(e0b) => e0a == e0b,
|
|
|
|
_ => false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
AT => {
|
|
|
|
match other {
|
|
|
|
AT => true,
|
|
|
|
_ => false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
DOT => {
|
|
|
|
match other {
|
|
|
|
DOT => true,
|
|
|
|
_ => false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
DOTDOT => {
|
|
|
|
match other {
|
|
|
|
DOTDOT => true,
|
|
|
|
_ => false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ELLIPSIS => {
|
|
|
|
match other {
|
|
|
|
ELLIPSIS => true,
|
|
|
|
_ => false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
COMMA => {
|
|
|
|
match other {
|
|
|
|
COMMA => true,
|
|
|
|
_ => false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SEMI => {
|
|
|
|
match other {
|
|
|
|
SEMI => true,
|
|
|
|
_ => false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
COLON => {
|
|
|
|
match other {
|
|
|
|
COLON => true,
|
|
|
|
_ => false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
MOD_SEP => {
|
|
|
|
match other {
|
|
|
|
MOD_SEP => true,
|
|
|
|
_ => false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
RARROW => {
|
|
|
|
match other {
|
|
|
|
RARROW => true,
|
|
|
|
_ => false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
LARROW => {
|
|
|
|
match other {
|
|
|
|
LARROW => true,
|
|
|
|
_ => false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
DARROW => {
|
|
|
|
match other {
|
|
|
|
DARROW => true,
|
|
|
|
_ => false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
FAT_ARROW => {
|
|
|
|
match other {
|
|
|
|
FAT_ARROW => true,
|
|
|
|
_ => false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
LPAREN => {
|
|
|
|
match other {
|
|
|
|
LPAREN => true,
|
|
|
|
_ => false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
RPAREN => {
|
|
|
|
match other {
|
|
|
|
RPAREN => true,
|
|
|
|
_ => false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
LBRACKET => {
|
|
|
|
match other {
|
|
|
|
LBRACKET => true,
|
|
|
|
_ => false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
RBRACKET => {
|
|
|
|
match other {
|
|
|
|
RBRACKET => true,
|
|
|
|
_ => false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
LBRACE => {
|
|
|
|
match other {
|
|
|
|
LBRACE => true,
|
|
|
|
_ => false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
RBRACE => {
|
|
|
|
match other {
|
|
|
|
RBRACE => true,
|
|
|
|
_ => false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
POUND => {
|
|
|
|
match other {
|
|
|
|
POUND => true,
|
|
|
|
_ => false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
DOLLAR => {
|
|
|
|
match other {
|
|
|
|
DOLLAR => true,
|
|
|
|
_ => false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
LIT_INT(e0a, e1a) => {
|
|
|
|
match other {
|
|
|
|
LIT_INT(e0b, e1b) => e0a == e0b && e1a == e1b,
|
|
|
|
_ => false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
LIT_UINT(e0a, e1a) => {
|
|
|
|
match other {
|
|
|
|
LIT_UINT(e0b, e1b) => e0a == e0b && e1a == e1b,
|
|
|
|
_ => false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
LIT_INT_UNSUFFIXED(e0a) => {
|
|
|
|
match other {
|
|
|
|
LIT_INT_UNSUFFIXED(e0b) => e0a == e0b,
|
|
|
|
_ => false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
LIT_FLOAT(e0a, e1a) => {
|
|
|
|
match other {
|
|
|
|
LIT_FLOAT(e0b, e1b) => e0a == e0b && e1a == e1b,
|
|
|
|
_ => false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
LIT_STR(e0a) => {
|
|
|
|
match other {
|
|
|
|
LIT_STR(e0b) => e0a == e0b,
|
|
|
|
_ => false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
IDENT(e0a, e1a) => {
|
|
|
|
match other {
|
|
|
|
IDENT(e0b, e1b) => e0a == e0b && e1a == e1b,
|
|
|
|
_ => false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
UNDERSCORE => {
|
|
|
|
match other {
|
|
|
|
UNDERSCORE => true,
|
|
|
|
_ => false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
INTERPOLATED(_) => {
|
|
|
|
match other {
|
|
|
|
INTERPOLATED(_) => true,
|
|
|
|
_ => false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
DOC_COMMENT(e0a) => {
|
|
|
|
match other {
|
|
|
|
DOC_COMMENT(e0b) => e0a == e0b,
|
|
|
|
_ => false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
EOF => {
|
|
|
|
match other {
|
|
|
|
EOF => true,
|
|
|
|
_ => false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-09-07 14:06:02 -05:00
|
|
|
pure fn ne(&&other: token) -> bool { !self.eq(other) }
|
2012-08-27 18:26:35 -05:00
|
|
|
}
|
|
|
|
|
2010-08-18 13:35:12 -05:00
|
|
|
// Local Variables:
|
|
|
|
// fill-column: 78;
|
|
|
|
// indent-tabs-mode: nil
|
|
|
|
// c-basic-offset: 4
|
|
|
|
// buffer-file-coding-system: utf-8-unix
|
|
|
|
// End:
|