equal
deleted
inserted
replaced
19 function parseFile(filename) |
19 function parseFile(filename) |
20 ------ |
20 ------ |
21 |
21 |
22 local file = nil; |
22 local file = nil; |
23 local last = nil; |
23 local last = nil; |
|
24 local line = 1; |
24 local function read(expected) |
25 local function read(expected) |
25 local ch; |
26 local ch; |
26 if last then |
27 if last then |
27 ch = last; last = nil; |
28 ch = last; last = nil; |
28 else ch = file:read(1); end |
29 else |
29 if expected and ch ~= expected then error("expected: "..expected.."; got: "..(ch or "nil")); end |
30 ch = file:read(1); |
|
31 if ch == "\n" then line = line + 1; end |
|
32 end |
|
33 if expected and ch ~= expected then error("expected: "..expected.."; got: "..(ch or "nil").." on line "..line); end |
30 return ch; |
34 return ch; |
31 end |
35 end |
32 local function pushback(ch) |
36 local function pushback(ch) |
33 if last then error(); end |
37 if last then error(); end |
34 last = ch; |
38 last = ch; |