1 /* Generated By:JavaCC: Do not edit this line. SimpleCharStream.java Version 3.0 */
5 * An implementation of interface CharStream, where the stream is assumed to
6 * contain only ASCII characters (without unicode processing).
9 public class SimpleCharStream
11 public static final boolean staticFlag = false;
15 public int bufpos = -1;
17 protected int beginOffset, endOffset;
19 protected int bufline[];
20 protected int bufcolumn[];
22 protected int column = 0;
23 protected int line = 1;
25 protected boolean prevCharIsCR = false;
26 protected boolean prevCharIsLF = false;
28 protected java.io.Reader inputStream;
30 protected char[] buffer;
31 protected int maxNextCharInd = 0;
32 protected int inBuf = 0;
33 protected StringBuffer currentBuffer = new StringBuffer();
35 protected void ExpandBuff(boolean wrapAround)
37 char[] newbuffer = new char[bufsize + 2048];
38 int newbufline[] = new int[bufsize + 2048];
39 int newbufcolumn[] = new int[bufsize + 2048];
45 System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin);
46 System.arraycopy(buffer, 0, newbuffer,
47 bufsize - tokenBegin, bufpos);
50 System.arraycopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin);
51 System.arraycopy(bufline, 0, newbufline, bufsize - tokenBegin, bufpos);
54 System.arraycopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin);
55 System.arraycopy(bufcolumn, 0, newbufcolumn, bufsize - tokenBegin, bufpos);
56 bufcolumn = newbufcolumn;
58 maxNextCharInd = (bufpos += (bufsize - tokenBegin));
62 System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin);
65 System.arraycopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin);
68 System.arraycopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin);
69 bufcolumn = newbufcolumn;
71 maxNextCharInd = (bufpos -= tokenBegin);
76 throw new Error(t.getMessage());
85 protected void FillBuff() throws java.io.IOException
87 if (maxNextCharInd == available)
89 if (available == bufsize)
91 if (tokenBegin > 2048)
94 bufpos = maxNextCharInd = 0;
95 available = tokenBegin;
97 else if (tokenBegin < 0) {
99 bufpos = maxNextCharInd = 0;
103 else if (available > tokenBegin)
105 else if ((tokenBegin - available) < 2048)
108 available = tokenBegin;
113 if ((i = inputStream.read(buffer, maxNextCharInd,
114 available - maxNextCharInd)) == -1)
117 throw new java.io.IOException();
122 currentBuffer.append(buffer);
125 catch(java.io.IOException e) {
128 if (tokenBegin == -1)
134 public char BeginToken() throws java.io.IOException
136 beginOffset = endOffset;
144 protected void UpdateLineColumn(char c)
150 prevCharIsLF = false;
151 line += (column = 1);
153 else if (prevCharIsCR)
155 prevCharIsCR = false;
161 line += (column = 1);
174 column += (8 - (column & 07));
180 bufline[bufpos] = line;
181 bufcolumn[bufpos] = column;
184 public char readChar() throws java.io.IOException
191 if (++bufpos == bufsize) {
196 return buffer[bufpos];
199 if (++bufpos >= maxNextCharInd)
202 char c = buffer[bufpos];
213 public int getColumn() {
214 return bufcolumn[bufpos];
222 public int getLine() {
223 return bufline[bufpos];
226 public int getEndColumn() {
227 return bufcolumn[bufpos];
230 public int getEndLine() {
231 return bufline[bufpos];
234 public int getBeginColumn() {
235 return bufcolumn[tokenBegin];
238 public int getBeginLine() {
239 return bufline[tokenBegin];
242 public void backup(int amount) {
246 if ((bufpos -= amount) < 0)
250 public SimpleCharStream(java.io.Reader dstream, int startline,
251 int startcolumn, int buffersize)
253 inputStream = dstream;
254 currentBuffer = new StringBuffer();
256 column = startcolumn - 1;
258 available = bufsize = buffersize;
259 buffer = new char[buffersize];
260 bufline = new int[buffersize];
261 bufcolumn = new int[buffersize];
266 public SimpleCharStream(java.io.Reader dstream, int startline,
269 this(dstream, startline, startcolumn, 4096);
272 public SimpleCharStream(java.io.Reader dstream)
274 this(dstream, 1, 1, 4096);
276 public void ReInit(java.io.Reader dstream, int startline,
277 int startcolumn, int buffersize)
279 inputStream = dstream;
280 currentBuffer = new StringBuffer();
282 column = startcolumn - 1;
284 if (buffer == null || buffersize != buffer.length)
286 available = bufsize = buffersize;
287 buffer = new char[buffersize];
288 bufline = new int[buffersize];
289 bufcolumn = new int[buffersize];
291 prevCharIsLF = prevCharIsCR = false;
292 tokenBegin = inBuf = maxNextCharInd = 0;
299 public void ReInit(java.io.Reader dstream, int startline,
302 ReInit(dstream, startline, startcolumn, 4096);
305 public void ReInit(java.io.Reader dstream)
307 ReInit(dstream, 1, 1, 4096);
309 public SimpleCharStream(java.io.InputStream dstream, int startline,
310 int startcolumn, int buffersize)
312 this(new java.io.InputStreamReader(dstream), startline, startcolumn, 4096);
315 public SimpleCharStream(java.io.InputStream dstream, int startline,
318 this(dstream, startline, startcolumn, 4096);
321 public SimpleCharStream(java.io.InputStream dstream)
323 this(dstream, 1, 1, 4096);
326 public void ReInit(java.io.InputStream dstream, int startline,
327 int startcolumn, int buffersize)
329 ReInit(new java.io.InputStreamReader(dstream), startline, startcolumn, 4096);
332 public void ReInit(java.io.InputStream dstream)
334 ReInit(dstream, 1, 1, 4096);
336 public void ReInit(java.io.InputStream dstream, int startline,
339 ReInit(dstream, startline, startcolumn, 4096);
341 public String GetImage()
343 if (bufpos >= tokenBegin)
344 return new String(buffer, tokenBegin, bufpos - tokenBegin + 1);
346 return new String(buffer, tokenBegin, bufsize - tokenBegin) +
347 new String(buffer, 0, bufpos + 1);
350 public char[] GetSuffix(int len)
352 char[] ret = new char[len];
354 if ((bufpos + 1) >= len)
355 System.arraycopy(buffer, bufpos - len + 1, ret, 0, len);
358 System.arraycopy(buffer, bufsize - (len - bufpos - 1), ret, 0,
360 System.arraycopy(buffer, 0, ret, len - bufpos - 1, bufpos + 1);
374 * Method to adjust line and column numbers for the start of a token.<BR>
376 public void adjustBeginLineColumn(int newLine, int newCol)
378 int start = tokenBegin;
381 if (bufpos >= tokenBegin)
383 len = bufpos - tokenBegin + inBuf + 1;
387 len = bufsize - tokenBegin + bufpos + 1 + inBuf;
390 int i = 0, j = 0, k = 0;
391 int nextColDiff = 0, columnDiff = 0;
394 bufline[j = start % bufsize] == bufline[k = ++start % bufsize])
396 bufline[j] = newLine;
397 nextColDiff = columnDiff + bufcolumn[k] - bufcolumn[j];
398 bufcolumn[j] = newCol + columnDiff;
399 columnDiff = nextColDiff;
405 bufline[j] = newLine++;
406 bufcolumn[j] = newCol + columnDiff;
410 if (bufline[j = start % bufsize] != bufline[++start % bufsize])
411 bufline[j] = newLine++;
413 bufline[j] = newLine;
418 column = bufcolumn[j];
421 public StringBuffer getCurrentBuffer() {
422 return currentBuffer;
425 //Added by Matthieu Casanova
426 public int position = 0;
431 public int getPosition() {
432 return position + bufpos;
435 public int getBeginOffset() {
439 public int getEndOffset() {