10 local t_concat, t_insert = table.concat, table.insert; |
10 local t_concat, t_insert = table.concat, table.insert; |
11 local type, tonumber, tostring = type, tonumber, tostring; |
11 local type, tonumber, tostring = type, tonumber, tostring; |
12 |
12 |
13 local file = nil; |
13 local file = nil; |
14 local last = nil; |
14 local last = nil; |
|
15 local line = 1; |
15 local function read(expected) |
16 local function read(expected) |
16 local ch; |
17 local ch; |
17 if last then |
18 if last then |
18 ch = last; last = nil; |
19 ch = last; last = nil; |
19 else ch = file:read(1); end |
20 else |
20 if expected and ch ~= expected then error("expected: "..expected.."; got: "..(ch or "nil")); end |
21 ch = file:read(1); |
|
22 if ch == "\n" then line = line + 1; end |
|
23 end |
|
24 if expected and ch ~= expected then error("expected: "..expected.."; got: "..(ch or "nil").." on line "..line); end |
21 return ch; |
25 return ch; |
22 end |
26 end |
23 local function pushback(ch) |
27 local function pushback(ch) |
24 if last then error(); end |
28 if last then error(); end |
25 last = ch; |
29 last = ch; |