1 package org.gnunet.seaspider.parser;
2 /* Generated By:JavaCC: Do not edit this line. SimpleCharStream.java Version 5.0 */
3 /* JavaCCOptions:STATIC=false,SUPPORT_CLASS_VISIBILITY_PUBLIC=true */
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 /** Whether parser is static. */
12 public static final boolean staticFlag = false;
16 /** Position in buffer. */
17 public int bufpos = -1;
18 protected int bufline[];
19 protected int bufcolumn[];
21 protected int column = 0;
22 protected int line = 1;
24 protected boolean prevCharIsCR = false;
25 protected boolean prevCharIsLF = false;
27 protected java.io.Reader inputStream;
29 protected char[] buffer;
30 protected int maxNextCharInd = 0;
31 protected int inBuf = 0;
32 protected int tabSize = 8;
34 protected void setTabSize(int i) { tabSize = i; }
35 protected int getTabSize(int i) { return tabSize; }
38 protected void ExpandBuff(boolean wrapAround)
40 char[] newbuffer = new char[bufsize + 2048];
41 int newbufline[] = new int[bufsize + 2048];
42 int newbufcolumn[] = new int[bufsize + 2048];
48 System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin);
49 System.arraycopy(buffer, 0, newbuffer, bufsize - tokenBegin, bufpos);
52 System.arraycopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin);
53 System.arraycopy(bufline, 0, newbufline, bufsize - tokenBegin, bufpos);
56 System.arraycopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin);
57 System.arraycopy(bufcolumn, 0, newbufcolumn, bufsize - tokenBegin, bufpos);
58 bufcolumn = newbufcolumn;
60 maxNextCharInd = (bufpos += (bufsize - tokenBegin));
64 System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin);
67 System.arraycopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin);
70 System.arraycopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin);
71 bufcolumn = newbufcolumn;
73 maxNextCharInd = (bufpos -= tokenBegin);
78 throw new Error(t.getMessage());
87 protected void FillBuff() throws java.io.IOException
89 if (maxNextCharInd == available)
91 if (available == bufsize)
93 if (tokenBegin > 2048)
95 bufpos = maxNextCharInd = 0;
96 available = tokenBegin;
98 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, available - maxNextCharInd)) == -1)
116 throw new java.io.IOException();
122 catch(java.io.IOException e) {
125 if (tokenBegin == -1)
132 public char BeginToken() throws java.io.IOException
141 protected void UpdateLineColumn(char c)
147 prevCharIsLF = false;
148 line += (column = 1);
150 else if (prevCharIsCR)
152 prevCharIsCR = false;
158 line += (column = 1);
171 column += (tabSize - (column % tabSize));
177 bufline[bufpos] = line;
178 bufcolumn[bufpos] = column;
181 /** Read a character. */
182 public char readChar() throws java.io.IOException
188 if (++bufpos == bufsize)
191 return buffer[bufpos];
194 if (++bufpos >= maxNextCharInd)
197 char c = buffer[bufpos];
209 public int getColumn() {
210 return bufcolumn[bufpos];
219 public int getLine() {
220 return bufline[bufpos];
223 /** Get token end column number. */
224 public int getEndColumn() {
225 return bufcolumn[bufpos];
228 /** Get token end line number. */
229 public int getEndLine() {
230 return bufline[bufpos];
233 /** Get token beginning column number. */
234 public int getBeginColumn() {
235 return bufcolumn[tokenBegin];
238 /** Get token beginning line number. */
239 public int getBeginLine() {
240 return bufline[tokenBegin];
243 /** Backup a number of characters. */
244 public void backup(int amount) {
247 if ((bufpos -= amount) < 0)
252 public SimpleCharStream(java.io.Reader dstream, int startline,
253 int startcolumn, int buffersize)
255 inputStream = dstream;
257 column = startcolumn - 1;
259 available = bufsize = buffersize;
260 buffer = new char[buffersize];
261 bufline = new int[buffersize];
262 bufcolumn = new int[buffersize];
266 public SimpleCharStream(java.io.Reader dstream, int startline,
269 this(dstream, startline, startcolumn, 4096);
273 public SimpleCharStream(java.io.Reader dstream)
275 this(dstream, 1, 1, 4096);
279 public void ReInit(java.io.Reader dstream, int startline,
280 int startcolumn, int buffersize)
282 inputStream = dstream;
284 column = startcolumn - 1;
286 if (buffer == null || buffersize != buffer.length)
288 available = bufsize = buffersize;
289 buffer = new char[buffersize];
290 bufline = new int[buffersize];
291 bufcolumn = new int[buffersize];
293 prevCharIsLF = prevCharIsCR = false;
294 tokenBegin = inBuf = maxNextCharInd = 0;
299 public void ReInit(java.io.Reader dstream, int startline,
302 ReInit(dstream, startline, startcolumn, 4096);
306 public void ReInit(java.io.Reader dstream)
308 ReInit(dstream, 1, 1, 4096);
311 public SimpleCharStream(java.io.InputStream dstream, String encoding, int startline,
312 int startcolumn, int buffersize) throws java.io.UnsupportedEncodingException
314 this(encoding == null ? new java.io.InputStreamReader(dstream) : new java.io.InputStreamReader(dstream, encoding), startline, startcolumn, buffersize);
318 public SimpleCharStream(java.io.InputStream dstream, int startline,
319 int startcolumn, int buffersize)
321 this(new java.io.InputStreamReader(dstream), startline, startcolumn, buffersize);
325 public SimpleCharStream(java.io.InputStream dstream, String encoding, int startline,
326 int startcolumn) throws java.io.UnsupportedEncodingException
328 this(dstream, encoding, startline, startcolumn, 4096);
332 public SimpleCharStream(java.io.InputStream dstream, int startline,
335 this(dstream, startline, startcolumn, 4096);
339 public SimpleCharStream(java.io.InputStream dstream, String encoding) throws java.io.UnsupportedEncodingException
341 this(dstream, encoding, 1, 1, 4096);
345 public SimpleCharStream(java.io.InputStream dstream)
347 this(dstream, 1, 1, 4096);
351 public void ReInit(java.io.InputStream dstream, String encoding, int startline,
352 int startcolumn, int buffersize) throws java.io.UnsupportedEncodingException
354 ReInit(encoding == null ? new java.io.InputStreamReader(dstream) : new java.io.InputStreamReader(dstream, encoding), startline, startcolumn, buffersize);
358 public void ReInit(java.io.InputStream dstream, int startline,
359 int startcolumn, int buffersize)
361 ReInit(new java.io.InputStreamReader(dstream), startline, startcolumn, buffersize);
365 public void ReInit(java.io.InputStream dstream, String encoding) throws java.io.UnsupportedEncodingException
367 ReInit(dstream, encoding, 1, 1, 4096);
371 public void ReInit(java.io.InputStream dstream)
373 ReInit(dstream, 1, 1, 4096);
376 public void ReInit(java.io.InputStream dstream, String encoding, int startline,
377 int startcolumn) throws java.io.UnsupportedEncodingException
379 ReInit(dstream, encoding, startline, startcolumn, 4096);
382 public void ReInit(java.io.InputStream dstream, int startline,
385 ReInit(dstream, startline, startcolumn, 4096);
387 /** Get token literal value. */
388 public String GetImage()
390 if (bufpos >= tokenBegin)
391 return new String(buffer, tokenBegin, bufpos - tokenBegin + 1);
393 return new String(buffer, tokenBegin, bufsize - tokenBegin) +
394 new String(buffer, 0, bufpos + 1);
397 /** Get the suffix. */
398 public char[] GetSuffix(int len)
400 char[] ret = new char[len];
402 if ((bufpos + 1) >= len)
403 System.arraycopy(buffer, bufpos - len + 1, ret, 0, len);
406 System.arraycopy(buffer, bufsize - (len - bufpos - 1), ret, 0,
408 System.arraycopy(buffer, 0, ret, len - bufpos - 1, bufpos + 1);
414 /** Reset buffer when finished. */
423 * Method to adjust line and column numbers for the start of a token.
425 public void adjustBeginLineColumn(int newLine, int newCol)
427 int start = tokenBegin;
430 if (bufpos >= tokenBegin)
432 len = bufpos - tokenBegin + inBuf + 1;
436 len = bufsize - tokenBegin + bufpos + 1 + inBuf;
439 int i = 0, j = 0, k = 0;
440 int nextColDiff = 0, columnDiff = 0;
442 while (i < len && bufline[j = start % bufsize] == bufline[k = ++start % bufsize])
444 bufline[j] = newLine;
445 nextColDiff = columnDiff + bufcolumn[k] - bufcolumn[j];
446 bufcolumn[j] = newCol + columnDiff;
447 columnDiff = nextColDiff;
453 bufline[j] = newLine++;
454 bufcolumn[j] = newCol + columnDiff;
458 if (bufline[j = start % bufsize] != bufline[++start % bufsize])
459 bufline[j] = newLine++;
461 bufline[j] = newLine;
466 column = bufcolumn[j];
470 /* JavaCC - OriginalChecksum=b0bce35239226f00f9dd0fa14ab3ad17 (do not edit this line) */