aboutsummaryrefslogtreecommitdiff
path: root/src/comp
diff options
context:
space:
mode:
authorGraydon Hoare <[email protected]>2010-08-20 12:12:37 -0700
committerGraydon Hoare <[email protected]>2010-08-20 12:12:37 -0700
commiteecd1f47d78d2f4144999aa6901f75799e6bcec0 (patch)
treea510c6b0ef028bb32264d8279a689eeeb31ad4dd /src/comp
parentAdd ungetc and re-indent _io.rs. (diff)
downloadrust-eecd1f47d78d2f4144999aa6901f75799e6bcec0.tar.xz
rust-eecd1f47d78d2f4144999aa6901f75799e6bcec0.zip
Fix some lexer bugs in rustc. Beginning to lex stuff now.
Diffstat (limited to 'src/comp')
-rw-r--r--src/comp/fe/lexer.rs10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/comp/fe/lexer.rs b/src/comp/fe/lexer.rs
index 57a60fe3..d13b6f37 100644
--- a/src/comp/fe/lexer.rs
+++ b/src/comp/fe/lexer.rs
@@ -1,7 +1,7 @@
import std._io.stdio_reader;
fn in_range(char c, char lo, char hi) -> bool {
- ret c <= lo && c <= hi;
+ ret lo <= c && c <= hi;
}
fn is_alpha(char c) -> bool {
@@ -37,12 +37,14 @@ fn next_token(stdio_reader rdr) -> token.token {
}
if (c == eof) { ret token.EOF(); }
+
if (is_alpha(c)) {
while (is_alpha(c)) {
accum += (c as u8);
c = rdr.getc() as char;
- ret token.IDENT(accum);
}
+ rdr.ungetc(c as int);
+ ret token.IDENT(accum);
}
if (is_dec_digit(c)) {
@@ -50,8 +52,10 @@ fn next_token(stdio_reader rdr) -> token.token {
} else {
while (is_dec_digit(c)) {
accum += (c as u8);
- ret token.LIT_INT(0);
+ c = rdr.getc() as char;
}
+ rdr.ungetc(c as int);
+ ret token.LIT_INT(0);
}
}