KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > antlr > CharBuffer


1 package antlr;
2
3 /* ANTLR Translator Generator
4  * Project led by Terence Parr at http://www.jGuru.com
5  * Software rights: http://www.antlr.org/RIGHTS.html
6  *
7  * $Id: //depot/code/org.antlr/main/main/antlr/CharBuffer.java#4 $
8  */

9
10 /**A Stream of characters fed to the lexer from a InputStream that can
11  * be rewound via mark()/rewind() methods.
12  * <p>
13  * A dynamic array is used to buffer up all the input characters. Normally,
14  * "k" characters are stored in the buffer. More characters may be stored during
15  * guess mode (testing syntactic predicate), or when LT(i>k) is referenced.
16  * Consumption of characters is deferred. In other words, reading the next
17  * character is not done by conume(), but deferred until needed by LA or LT.
18  * <p>
19  *
20  * @see antlr.CharQueue
21  */

22
23 import java.io.Reader JavaDoc; // SAS: changed to properly read text files
24
import java.io.IOException JavaDoc;
25
26 // SAS: Move most functionality into InputBuffer -- just the file-specific
27
// stuff is in here
28

29 public class CharBuffer extends InputBuffer {
30     // char source
31
transient Reader JavaDoc input;
32
33     /** Create a character buffer */
34     public CharBuffer(Reader JavaDoc input_) { // SAS: for proper text i/o
35
super();
36         input = input_;
37     }
38
39     /** Ensure that the character buffer is sufficiently full */
40     public void fill(int amount) throws CharStreamException {
41         try {
42             syncConsume();
43             // Fill the buffer sufficiently to hold needed characters
44
while (queue.nbrEntries < amount + markerOffset) {
45                 // Append the next character
46
queue.append((char)input.read());
47             }
48         }
49         catch (IOException JavaDoc io) {
50             throw new CharStreamIOException(io);
51         }
52     }
53 }
54
Popular Tags