1 package acl2s.lib.parse;
2
3 import java.io.BufferedReader;
4 import java.io.InputStream;
5 import java.io.InputStreamReader;
6
7
8 public class StreamParser extends Parser {
9 protected Substream pos;
10
11 public StreamParser(IParseContext pc, InputStream is) {
|
Event do_not_call: |
"java.io.InputStreamReader(java.io.InputStream arg1)" implicitly uses the environment's default character set, which might lead to unexpected behavior. Consider using InputStreamReader(InputStream in, String charsetName). |
12 this(pc, new BufferedReader(new InputStreamReader(is)));
13 }
14
15 public StreamParser(IParseContext pc, BufferedReader r) {
16 this(pc, new Substream(r));
17 }
18
19 public StreamParser(IParseContext pc, Substream s) {
20 super(pc);
21 pos = s;
22 }
23
24 public Substream save() {
25 return pos;
26 }
27
28 public void restore(Object o) {
29 pos = (Substream) o;
30 }
31
32 public char peek(int n) {
33 return pos.peek(n);
34 }
35
36 public void advance(int n) {
37 while (n > 0) {
38 pos = pos.getNext();
39 n--;
40 }
41 }
42
43 public void gobble() {
44 while (pos.ready() && !pos.eof()) {
45 pos = pos.getNext();
46 }
47 }
48
49 public boolean ready() {
50 return pos.ready();
51 }
52
53 @Override
54 public boolean eof() { return pos.eof(); }
55 }