01: package persistence.antlr.debug;
02:
03: import persistence.antlr.InputBuffer;
04: import persistence.antlr.CharStreamException;
05: import java.util.Vector;
06: import java.io.IOException;
07:
08: public class DebuggingInputBuffer extends InputBuffer {
09: private InputBuffer buffer;
10: private InputBufferEventSupport inputBufferEventSupport;
11: private boolean debugMode = true;
12:
13: public DebuggingInputBuffer(InputBuffer buffer) {
14: this .buffer = buffer;
15: inputBufferEventSupport = new InputBufferEventSupport(this );
16: }
17:
18: public void addInputBufferListener(InputBufferListener l) {
19: inputBufferEventSupport.addInputBufferListener(l);
20: }
21:
22: public void consume() {
23: char la = ' ';
24: try {
25: la = buffer.LA(1);
26: } catch (CharStreamException e) {
27: } // vaporize it...
28: buffer.consume();
29: if (debugMode)
30: inputBufferEventSupport.fireConsume(la);
31: }
32:
33: public void fill(int a) throws CharStreamException {
34: buffer.fill(a);
35: }
36:
37: public Vector getInputBufferListeners() {
38: return inputBufferEventSupport.getInputBufferListeners();
39: }
40:
41: public boolean isDebugMode() {
42: return debugMode;
43: }
44:
45: public boolean isMarked() {
46: return buffer.isMarked();
47: }
48:
49: public char LA(int i) throws CharStreamException {
50: char la = buffer.LA(i);
51: if (debugMode)
52: inputBufferEventSupport.fireLA(la, i);
53: return la;
54: }
55:
56: public int mark() {
57: int m = buffer.mark();
58: inputBufferEventSupport.fireMark(m);
59: return m;
60: }
61:
62: public void removeInputBufferListener(InputBufferListener l) {
63: if (inputBufferEventSupport != null)
64: inputBufferEventSupport.removeInputBufferListener(l);
65: }
66:
67: public void rewind(int mark) {
68: buffer.rewind(mark);
69: inputBufferEventSupport.fireRewind(mark);
70: }
71:
72: public void setDebugMode(boolean value) {
73: debugMode = value;
74: }
75: }
|