diff options
| author | Graydon Hoare <[email protected]> | 2010-08-19 18:42:17 -0700 |
|---|---|---|
| committer | Graydon Hoare <[email protected]> | 2010-08-19 18:42:32 -0700 |
| commit | 40fccac7fb347f75536ad5c48420692e36f839e8 (patch) | |
| tree | 02419f72489fd323ef73166e79af76dc040b6d7b /src | |
| parent | Fix a bunch of typestate bugs in handling if and while statement wirings. (diff) | |
| download | rust-40fccac7fb347f75536ad5c48420692e36f839e8.tar.xz rust-40fccac7fb347f75536ad5c48420692e36f839e8.zip | |
Add some code to lexer in rustc.
Diffstat (limited to 'src')
| -rw-r--r-- | src/comp/fe/lexer.rs | 37 |
1 files changed, 35 insertions, 2 deletions
diff --git a/src/comp/fe/lexer.rs b/src/comp/fe/lexer.rs index f1589e7f..ee0b16f9 100644 --- a/src/comp/fe/lexer.rs +++ b/src/comp/fe/lexer.rs @@ -1,8 +1,41 @@ import std._io.stdio_reader; +fn in_range(char c, char lo, char hi) -> bool { + ret c <= lo && c <= hi; +} + +fn is_alpha(char c) -> bool { + ret in_range(c, 'a', 'z') || + in_range(c, 'A', 'Z'); +} + +fn is_dec_digit(char c) -> bool { + ret in_range(c, '0', '9'); +} + +fn is_hex_digit(char c) -> bool { + ret in_range(c, '0', '9') || + in_range(c, 'a', 'f') || + in_range(c, 'A', 'F'); +} + +fn is_bin_digit(char c) -> bool { + ret c == '0' || c == '1'; +} + +fn is_whitespace(char c) -> bool { + ret c == ' ' || c == '\t' || c == '\r'; +} + fn next_token(stdio_reader rdr) -> token.token { - auto c = rdr.getc(); - log "got char"; + auto eof = (-1) as char; + auto c = rdr.getc() as char; + + while (is_whitespace(c) && c != eof) { + c = rdr.getc() as char; + } + + if (c == eof) { ret token.EOF(); } log c; ret token.EOF(); } |