Skip to content

Commit f83d1e1

Browse files
committed
---
yaml --- r: 574 b: refs/heads/master c: 07d355d h: refs/heads/master v: v3
1 parent 109c43f commit f83d1e1

File tree

2 files changed

+90
-1
lines changed

2 files changed

+90
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: 47501f16596d2eaac9ce1a27b43b386b8496c66f
2+
refs/heads/master: 07d355d1afe0ff832e78f496bc98337c22822752

trunk/src/comp/fe/lexer.rs

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,93 @@
11
import std._io.stdio_reader;
2+
import std._str;
3+
import std.map;
4+
import std.map.hashmap;
5+
6+
fn new_str_hash[V]() -> map.hashmap[str,V] {
7+
let map.hashfn[str] hasher = _str.hash;
8+
let map.eqfn[str] eqer = _str.eq;
9+
ret map.mk_hashmap[str,V](hasher, eqer);
10+
}
11+
12+
type reader = obj {
13+
fn is_eof() -> bool;
14+
fn peek() -> char;
15+
fn bump();
16+
fn get_pos() -> tup(str,uint,uint);
17+
fn get_keywords() -> hashmap[str,token.token];
18+
fn get_reserved() -> hashmap[str,()];
19+
};
20+
21+
fn new_reader(stdio_reader rdr, str filename) -> reader
22+
{
23+
obj reader(stdio_reader rdr,
24+
str filename,
25+
mutable char c,
26+
mutable uint line,
27+
mutable uint col,
28+
hashmap[str,token.token] keywords,
29+
hashmap[str,()] reserved)
30+
{
31+
fn is_eof() -> bool {
32+
ret c == (-1) as char;
33+
}
34+
35+
fn get_pos() -> tup(str,uint,uint) {
36+
ret tup(filename, line, col);
37+
}
38+
39+
fn peek() -> char {
40+
ret c;
41+
}
42+
43+
fn bump() {
44+
c = rdr.getc() as char;
45+
if (c == '\n') {
46+
line += 1u;
47+
col = 0u;
48+
} else {
49+
col += 1u;
50+
}
51+
}
52+
53+
fn get_keywords() -> hashmap[str,token.token] {
54+
ret keywords;
55+
}
56+
57+
fn get_reserved() -> hashmap[str,()] {
58+
ret reserved;
59+
}
60+
}
61+
62+
auto keywords = new_str_hash[token.token]();
63+
auto reserved = new_str_hash[()]();
64+
65+
keywords.insert("mod", token.MOD());
66+
keywords.insert("use", token.USE());
67+
keywords.insert("meta", token.META());
68+
keywords.insert("auth", token.AUTH());
69+
70+
keywords.insert("syntax", token.SYNTAX());
71+
72+
keywords.insert("if", token.IF());
73+
keywords.insert("else", token.ELSE());
74+
keywords.insert("while", token.WHILE());
75+
keywords.insert("do", token.DO());
76+
keywords.insert("alt", token.ALT());
77+
keywords.insert("case", token.CASE());
78+
79+
keywords.insert("for", token.FOR());
80+
keywords.insert("each", token.EACH());
81+
keywords.insert("put", token.PUT());
82+
keywords.insert("ret", token.RET());
83+
keywords.insert("be", token.BE());
84+
85+
ret reader(rdr, filename, rdr.getc() as char, 1u, 1u,
86+
keywords, reserved);
87+
}
88+
89+
90+
291

392
fn in_range(char c, char lo, char hi) -> bool {
493
ret lo <= c && c <= hi;

0 commit comments

Comments
 (0)