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 = true;
 
  14   static int tokenBegin;
 
  15   static public int bufpos = -1;
 
  17   //Added by Matthieu Casanova
 
  18   public static int position = 0;
 
  20   static protected int bufline[];
 
  21   static protected int bufcolumn[];
 
  23   static protected int column = 0;
 
  24   static protected int line = 1;
 
  26   static protected boolean prevCharIsCR = false;
 
  27   static protected boolean prevCharIsLF = false;
 
  29   static protected java.io.Reader inputStream;
 
  31   static protected char[] buffer;
 
  32   static protected int maxNextCharInd = 0;
 
  33   static protected int inBuf = 0;
 
  35   static 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   static 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();
 
 124      catch(java.io.IOException e) {
 
 127         if (tokenBegin == -1)
 
 133   static public char BeginToken() throws java.io.IOException
 
 142   static protected void UpdateLineColumn(char c)
 
 148         prevCharIsLF = false;
 
 149         line += (column = 1);
 
 151      else if (prevCharIsCR)
 
 153         prevCharIsCR = false;
 
 159            line += (column = 1);
 
 172            column += (8 - (column & 07));
 
 178      bufline[bufpos] = line;
 
 179      bufcolumn[bufpos] = column;
 
 182   static public char readChar() throws java.io.IOException
 
 188         if (++bufpos == bufsize) {
 
 193         return buffer[bufpos];
 
 196      if (++bufpos >= maxNextCharInd) {
 
 200      char c = buffer[bufpos];
 
 211   static public int getColumn() {
 
 212      return bufcolumn[bufpos];
 
 220   static public int getLine() {
 
 221      return bufline[bufpos];
 
 224   static public int getEndColumn() {
 
 225      return bufcolumn[bufpos];
 
 228   static public int getEndLine() {
 
 229      return bufline[bufpos];
 
 232   static public int getBeginColumn() {
 
 233      return bufcolumn[tokenBegin];
 
 236   static public int getBeginLine() {
 
 237      return bufline[tokenBegin];
 
 240   static public void backup(int amount) {
 
 243     if ((bufpos -= amount) < 0)
 
 247   public SimpleCharStream(java.io.Reader dstream, int startline,
 
 248   int startcolumn, int buffersize)
 
 250     if (inputStream != null)
 
 251        throw new Error("\n   ERROR: Second call to the constructor of a static SimpleCharStream.  You must\n" +
 
 252        "       either use ReInit() or set the JavaCC option STATIC to false\n" +
 
 253        "       during the generation of this class.");
 
 254     inputStream = dstream;
 
 256     column = startcolumn - 1;
 
 258     available = bufsize = buffersize;
 
 259     buffer = new char[buffersize];
 
 260     bufline = new int[buffersize];
 
 261     bufcolumn = new int[buffersize];
 
 264   public SimpleCharStream(java.io.Reader dstream, int startline,
 
 267      this(dstream, startline, startcolumn, 4096);
 
 270   public SimpleCharStream(java.io.Reader dstream)
 
 272      this(dstream, 1, 1, 4096);
 
 274   public void ReInit(java.io.Reader dstream, int startline,
 
 275   int startcolumn, int buffersize)
 
 277     inputStream = dstream;
 
 279     column = startcolumn - 1;
 
 281     if (buffer == null || buffersize != buffer.length)
 
 283       available = bufsize = buffersize;
 
 284       buffer = new char[buffersize];
 
 285       bufline = new int[buffersize];
 
 286       bufcolumn = new int[buffersize];
 
 288     prevCharIsLF = prevCharIsCR = false;
 
 289     tokenBegin = inBuf = maxNextCharInd = 0;
 
 294   public void ReInit(java.io.Reader dstream, int startline,
 
 297      ReInit(dstream, startline, startcolumn, 4096);
 
 300   public void ReInit(java.io.Reader dstream)
 
 302      ReInit(dstream, 1, 1, 4096);
 
 304   public SimpleCharStream(java.io.InputStream dstream, int startline,
 
 305   int startcolumn, int buffersize)
 
 307      this(new java.io.InputStreamReader(dstream), startline, startcolumn, 4096);
 
 310   public SimpleCharStream(java.io.InputStream dstream, int startline,
 
 313      this(dstream, startline, startcolumn, 4096);
 
 316   public SimpleCharStream(java.io.InputStream dstream)
 
 318      this(dstream, 1, 1, 4096);
 
 321   public void ReInit(java.io.InputStream dstream, int startline,
 
 322                           int startcolumn, int buffersize)
 
 324      ReInit(new java.io.InputStreamReader(dstream), startline, startcolumn, 4096);
 
 327   public void ReInit(java.io.InputStream dstream)
 
 329      ReInit(dstream, 1, 1, 4096);
 
 331   public void ReInit(java.io.InputStream dstream, int startline,
 
 334      ReInit(dstream, startline, startcolumn, 4096);
 
 336   static public String GetImage()
 
 338      if (bufpos >= tokenBegin)
 
 339         return new String(buffer, tokenBegin, bufpos - tokenBegin + 1);
 
 341         return new String(buffer, tokenBegin, bufsize - tokenBegin) +
 
 342                               new String(buffer, 0, bufpos + 1);
 
 345   static public char[] GetSuffix(int len)
 
 347      char[] ret = new char[len];
 
 349      if ((bufpos + 1) >= len)
 
 350         System.arraycopy(buffer, bufpos - len + 1, ret, 0, len);
 
 353         System.arraycopy(buffer, bufsize - (len - bufpos - 1), ret, 0,
 
 355         System.arraycopy(buffer, 0, ret, len - bufpos - 1, bufpos + 1);
 
 361   static public void Done()
 
 369    * Method to adjust line and column numbers for the start of a token.<BR>
 
 371   static public void adjustBeginLineColumn(int newLine, int newCol)
 
 373      int start = tokenBegin;
 
 376      if (bufpos >= tokenBegin)
 
 378         len = bufpos - tokenBegin + inBuf + 1;
 
 382         len = bufsize - tokenBegin + bufpos + 1 + inBuf;
 
 385      int i = 0, j = 0, k = 0;
 
 386      int nextColDiff = 0, columnDiff = 0;
 
 389             bufline[j = start % bufsize] == bufline[k = ++start % bufsize])
 
 391         bufline[j] = newLine;
 
 392         nextColDiff = columnDiff + bufcolumn[k] - bufcolumn[j];
 
 393         bufcolumn[j] = newCol + columnDiff;
 
 394         columnDiff = nextColDiff;
 
 400         bufline[j] = newLine++;
 
 401         bufcolumn[j] = newCol + columnDiff;
 
 405            if (bufline[j = start % bufsize] != bufline[++start % bufsize])
 
 406               bufline[j] = newLine++;
 
 408               bufline[j] = newLine;
 
 413      column = bufcolumn[j];
 
 417   public static int getPosition() {
 
 418     return position + bufpos;