Skip to content

Commit 40fccac

Browse files
committed
Add some code to lexer in rustc.
1 parent b34cb1b commit 40fccac

File tree

1 file changed

+35
-2
lines changed

1 file changed

+35
-2
lines changed

src/comp/fe/lexer.rs

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,41 @@
11
import std._io.stdio_reader;
22

3+
fn in_range(char c, char lo, char hi) -> bool {
4+
ret c <= lo && c <= hi;
5+
}
6+
7+
fn is_alpha(char c) -> bool {
8+
ret in_range(c, 'a', 'z') ||
9+
in_range(c, 'A', 'Z');
10+
}
11+
12+
fn is_dec_digit(char c) -> bool {
13+
ret in_range(c, '0', '9');
14+
}
15+
16+
fn is_hex_digit(char c) -> bool {
17+
ret in_range(c, '0', '9') ||
18+
in_range(c, 'a', 'f') ||
19+
in_range(c, 'A', 'F');
20+
}
21+
22+
fn is_bin_digit(char c) -> bool {
23+
ret c == '0' || c == '1';
24+
}
25+
26+
fn is_whitespace(char c) -> bool {
27+
ret c == ' ' || c == '\t' || c == '\r';
28+
}
29+
330
fn next_token(stdio_reader rdr) -> token.token {
4-
auto c = rdr.getc();
5-
log "got char";
31+
auto eof = (-1) as char;
32+
auto c = rdr.getc() as char;
33+
34+
while (is_whitespace(c) && c != eof) {
35+
c = rdr.getc() as char;
36+
}
37+
38+
if (c == eof) { ret token.EOF(); }
639
log c;
740
ret token.EOF();
841
}

0 commit comments

Comments
 (0)