diff options
| author | Graydon Hoare <[email protected]> | 2010-08-20 11:41:34 -0700 |
|---|---|---|
| committer | Graydon Hoare <[email protected]> | 2010-08-20 11:42:44 -0700 |
| commit | 0f224f977d9edeb7f8ca56c052c1202fab384552 (patch) | |
| tree | 2e9b93ce5e4eea139f44c747fd10679c1f4a03df /src/comp/fe/lexer.rs | |
| parent | Add _uint module to std, move some code around. (diff) | |
| download | rust-0f224f977d9edeb7f8ca56c052c1202fab384552.tar.xz rust-0f224f977d9edeb7f8ca56c052c1202fab384552.zip | |
Expand rustc lexer to do almost-nearly-nontrivial stuff.
Diffstat (limited to 'src/comp/fe/lexer.rs')
| -rw-r--r-- | src/comp/fe/lexer.rs | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/src/comp/fe/lexer.rs b/src/comp/fe/lexer.rs index 80b4b676..57a60fe3 100644 --- a/src/comp/fe/lexer.rs +++ b/src/comp/fe/lexer.rs @@ -38,8 +38,36 @@ fn next_token(stdio_reader rdr) -> token.token { if (c == eof) { ret token.EOF(); } if (is_alpha(c)) { - accum += (c as u8); + while (is_alpha(c)) { + accum += (c as u8); + c = rdr.getc() as char; + ret token.IDENT(accum); + } } + + if (is_dec_digit(c)) { + if (c == '0') { + } else { + while (is_dec_digit(c)) { + accum += (c as u8); + ret token.LIT_INT(0); + } + } + } + + // One-byte structural symbols. + if (c == ';') { ret token.SEMI(); } + if (c == '.') { ret token.DOT(); } + if (c == '(') { ret token.LPAREN(); } + if (c == ')') { ret token.RPAREN(); } + if (c == '{') { ret token.LBRACE(); } + if (c == '}') { ret token.RBRACE(); } + if (c == '[') { ret token.LBRACKET(); } + if (c == ']') { ret token.RBRACKET(); } + if (c == '@') { ret token.AT(); } + if (c == '#') { ret token.POUND(); } + + log "lexer stopping at "; log c; ret token.EOF(); } |