01: package persistence.antlr;
02:
03: /* ANTLR Translator Generator
04: * Project led by Terence Parr at http://www.jGuru.com
05: * Software rights: http://www.antlr.org/license.html
06: *
07: */
08:
09: /**A Stream of characters fed to the lexer from a InputStream that can
10: * be rewound via mark()/rewind() methods.
11: * <p>
12: * A dynamic array is used to buffer up all the input characters. Normally,
13: * "k" characters are stored in the buffer. More characters may be stored during
14: * guess mode (testing syntactic predicate), or when LT(i>k) is referenced.
15: * Consumption of characters is deferred. In other words, reading the next
16: * character is not done by conume(), but deferred until needed by LA or LT.
17: * <p>
18: *
19: * @see persistence.antlr.CharQueue
20: */
21:
22: import java.io.Reader; // SAS: changed to properly read text files
23: import java.io.IOException;
24:
25: // SAS: Move most functionality into InputBuffer -- just the file-specific
26: // stuff is in here
27:
28: public class CharBuffer extends InputBuffer {
29: // char source
30: transient Reader input;
31:
32: /** Create a character buffer */
33: public CharBuffer(Reader input_) { // SAS: for proper text i/o
34: super ();
35: input = input_;
36: }
37:
38: /** Ensure that the character buffer is sufficiently full */
39: public void fill(int amount) throws CharStreamException {
40: try {
41: syncConsume();
42: // Fill the buffer sufficiently to hold needed characters
43: while (queue.nbrEntries < amount + markerOffset) {
44: // Append the next character
45: queue.append((char) input.read());
46: }
47: } catch (IOException io) {
48: throw new CharStreamIOException(io);
49: }
50: }
51: }
|