aboutsummaryrefslogtreecommitdiff
path: root/src/comp/front/token.rs
diff options
context:
space:
mode:
authorMarijn Haverbeke <[email protected]>2011-05-13 21:30:08 +0200
committerMarijn Haverbeke <[email protected]>2011-05-13 22:00:13 +0200
commit57ffa2a487ef12a4abf538efc2dd8192ca308271 (patch)
treef3a82a1076c93c6ad6200391cc838cf2e7e6999d /src/comp/front/token.rs
parentrustc: Fix the type of node_types; stub the write_type function (diff)
downloadrust-57ffa2a487ef12a4abf538efc2dd8192ca308271.tar.xz
rust-57ffa2a487ef12a4abf538efc2dd8192ca308271.zip
Make the parser more careful about keywords
Keywords are now only recognized in contexts where they are valid. The lexer no longer recognizes them, all words are lexed as IDENT tokens, that get interpreted by the parser.
Diffstat (limited to 'src/comp/front/token.rs')
-rw-r--r--src/comp/front/token.rs202
1 files changed, 1 insertions, 201 deletions
diff --git a/src/comp/front/token.rs b/src/comp/front/token.rs
index 60091afc..171fa5f2 100644
--- a/src/comp/front/token.rs
+++ b/src/comp/front/token.rs
@@ -38,9 +38,6 @@ tag token {
BINOP(binop);
BINOPEQ(binop);
- AS;
- WITH;
-
/* Structural symbols */
AT;
DOT;
@@ -59,73 +56,8 @@ tag token {
LBRACE;
RBRACE;
- /* Module and crate keywords */
- MOD;
- USE;
- AUTH;
- META;
-
- /* Metaprogramming keywords */
- SYNTAX;
POUND;
- /* Statement keywords */
- IF;
- ELSE;
- DO;
- WHILE;
- ALT;
- CASE;
-
- BREAK;
- CONT;
-
- FAIL;
- DROP;
-
- IN;
- FOR;
- EACH;
- PUT;
- RET;
- BE;
-
- /* Type and type-state keywords */
- TYPE;
- ASSERT;
- CHECK;
- CLAIM;
- PROVE;
-
- /* Layer keywords */
- STATE;
- GC;
-
- /* Unsafe-block keyword */
- UNSAFE;
-
- /* Type qualifiers */
- NATIVE;
- AUTO;
- MUTABLE;
-
- /* Name management */
- IMPORT;
- EXPORT;
-
- /* Value / stmt declarators */
- LET;
- CONST;
-
- /* Magic runtime services */
- LOG;
- LOG_ERR;
- SPAWN;
- BIND;
- THREAD;
- YIELD;
- JOIN;
-
/* Literals */
LIT_INT(int);
LIT_UINT(uint);
@@ -141,36 +73,6 @@ tag token {
IDX(int);
UNDERSCORE;
- /* Reserved type names */
- BOOL;
- INT;
- UINT;
- FLOAT;
- CHAR;
- STR;
- MACH(ty_mach);
-
- /* Algebraic type constructors */
- REC;
- TUP;
- TAG;
- VEC;
- ANY;
-
- /* Callable type constructors */
- FN;
- PRED;
- ITER;
-
- /* Object type and related keywords */
- OBJ;
- SELF;
-
- /* Comm and task types */
- CHAN;
- PORT;
- TASK;
-
BRACEQUOTE(str_num);
EOF;
}
@@ -209,10 +111,6 @@ fn to_str(lexer::reader r, token t) -> str {
case (BINOP(?op)) { ret binop_to_str(op); }
case (BINOPEQ(?op)) { ret binop_to_str(op) + "="; }
- case (AS) { ret "as"; }
- case (WITH) { ret "with"; }
-
-
/* Structural symbols */
case (AT) { ret "@"; }
case (DOT) { ret "."; }
@@ -231,73 +129,8 @@ fn to_str(lexer::reader r, token t) -> str {
case (LBRACE) { ret "{"; }
case (RBRACE) { ret "}"; }
- /* Module and crate keywords */
- case (MOD) { ret "mod"; }
- case (USE) { ret "use"; }
- case (AUTH) { ret "auth"; }
- case (META) { ret "meta"; }
-
- /* Metaprogramming keywords */
- case (SYNTAX) { ret "syntax"; }
case (POUND) { ret "#"; }
- /* Statement keywords */
- case (IF) { ret "if"; }
- case (ELSE) { ret "else"; }
- case (DO) { ret "do"; }
- case (WHILE) { ret "while"; }
- case (ALT) { ret "alt"; }
- case (CASE) { ret "case"; }
-
- case (BREAK) { ret "break"; }
- case (CONT) { ret "cont"; }
-
- case (FAIL) { ret "fail"; }
- case (DROP) { ret "drop"; }
-
- case (IN) { ret "in"; }
- case (FOR) { ret "for"; }
- case (EACH) { ret "each"; }
- case (PUT) { ret "put"; }
- case (RET) { ret "ret"; }
- case (BE) { ret "be"; }
-
- /* Type and type-state keywords */
- case (TYPE) { ret "type"; }
- case (ASSERT) { ret "assert"; }
- case (CHECK) { ret "check"; }
- case (CLAIM) { ret "claim"; }
- case (PROVE) { ret "prove"; }
-
- /* Layer keywords */
- case (STATE) { ret "state"; }
- case (GC) { ret "gc"; }
-
- /* Unsafe-block keyword */
- case (UNSAFE) { ret "unsafe"; }
-
- /* Type qualifiers */
- case (NATIVE) { ret "native"; }
- case (AUTO) { ret "auto"; }
- case (MUTABLE) { ret "mutable"; }
-
- /* Name management */
- case (IMPORT) { ret "import"; }
- case (EXPORT) { ret "export"; }
-
- /* Value / stmt declarators */
- case (LET) { ret "let"; }
- case (CONST) { ret "const"; }
-
- /* Magic runtime services */
- case (LOG) { ret "log"; }
- case (LOG_ERR) { ret "log_err"; }
- case (SPAWN) { ret "spawn"; }
- case (BIND) { ret "bind"; }
- case (THREAD) { ret "thread"; }
- case (YIELD) { ret "yield"; }
- case (JOIN) { ret "join"; }
-
/* Literals */
case (LIT_INT(?i)) { ret _int::to_str(i, 10u); }
case (LIT_UINT(?u)) { ret _uint::to_str(u, 10u); }
@@ -328,44 +161,11 @@ fn to_str(lexer::reader r, token t) -> str {
/* Name components */
case (IDENT(?s)) {
- auto si = "ident:";
- si += r.get_str(s);
- ret si;
+ ret r.get_str(s);
}
case (IDX(?i)) { ret "_" + _int::to_str(i, 10u); }
case (UNDERSCORE) { ret "_"; }
- /* Reserved type names */
- case (BOOL) { ret "bool"; }
- case (INT) { ret "int"; }
- case (UINT) { ret "uint"; }
- case (FLOAT) { ret "float"; }
- case (CHAR) { ret "char"; }
- case (STR) { ret "str"; }
- case (MACH(?tm)) { ret ty_mach_to_str(tm); }
-
- /* Algebraic type constructors */
- case (REC) { ret "rec"; }
- case (TUP) { ret "tup"; }
- case (TAG) { ret "tag"; }
- case (VEC) { ret "vec"; }
- case (ANY) { ret "any"; }
-
- /* Callable type constructors */
- case (FN) { ret "fn"; }
- case (PRED) { ret "pred"; }
- case (ITER) { ret "iter"; }
-
- /* Object type */
- case (OBJ) { ret "obj"; }
- case (SELF) { ret "self"; }
-
-
- /* Comm and task types */
- case (CHAN) { ret "chan"; }
- case (PORT) { ret "port"; }
- case (TASK) { ret "task"; }
-
case (BRACEQUOTE(_)) { ret "<bracequote>"; }
case (EOF) { ret "<eof>"; }
}