KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > persistence > antlr > debug > DebuggingInputBuffer


1 package persistence.antlr.debug;
2
3 import persistence.antlr.InputBuffer;
4 import persistence.antlr.CharStreamException;
5 import java.util.Vector JavaDoc;
6 import java.io.IOException JavaDoc;
7
8 public class DebuggingInputBuffer extends InputBuffer {
9     private InputBuffer buffer;
10     private InputBufferEventSupport inputBufferEventSupport;
11     private boolean debugMode = true;
12
13
14     public DebuggingInputBuffer(InputBuffer buffer) {
15         this.buffer = buffer;
16         inputBufferEventSupport = new InputBufferEventSupport(this);
17     }
18     public void addInputBufferListener(InputBufferListener l) {
19       inputBufferEventSupport.addInputBufferListener(l);
20     }
21     public void consume() {
22         char la = ' ';
23         try {la = buffer.LA(1);}
24         catch (CharStreamException e) {} // vaporize it...
25
buffer.consume();
26         if (debugMode)
27             inputBufferEventSupport.fireConsume(la);
28     }
29     public void fill(int a) throws CharStreamException {
30         buffer.fill(a);
31     }
32     public Vector JavaDoc getInputBufferListeners() {
33         return inputBufferEventSupport.getInputBufferListeners();
34     }
35     public boolean isDebugMode() {
36         return debugMode;
37     }
38     public boolean isMarked() {
39         return buffer.isMarked();
40     }
41     public char LA(int i) throws CharStreamException {
42         char la = buffer.LA(i);
43         if (debugMode)
44             inputBufferEventSupport.fireLA(la,i);
45         return la;
46     }
47     public int mark() {
48         int m = buffer.mark();
49         inputBufferEventSupport.fireMark(m);
50         return m;
51     }
52     public void removeInputBufferListener(InputBufferListener l) {
53       if (inputBufferEventSupport != null)
54         inputBufferEventSupport.removeInputBufferListener(l);
55     }
56     public void rewind(int mark) {
57         buffer.rewind(mark);
58         inputBufferEventSupport.fireRewind(mark);
59     }
60     public void setDebugMode(boolean value) {
61         debugMode = value;
62     }
63 }
64
Popular Tags