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;
 
  30   static protected StringBuffer currentBuffer = new StringBuffer();
 
  32   static protected char[] buffer;
 
  33   static protected int maxNextCharInd = 0;
 
  34   static protected int inBuf = 0;
 
  36   static protected void ExpandBuff(boolean wrapAround)
 
  38      char[] newbuffer = new char[bufsize + 2048];
 
  39      int newbufline[] = new int[bufsize + 2048];
 
  40      int newbufcolumn[] = new int[bufsize + 2048];
 
  46            System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin);
 
  47            System.arraycopy(buffer, 0, newbuffer,
 
  48                                              bufsize - tokenBegin, bufpos);
 
  51            System.arraycopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin);
 
  52            System.arraycopy(bufline, 0, newbufline, bufsize - tokenBegin, bufpos);
 
  55            System.arraycopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin);
 
  56            System.arraycopy(bufcolumn, 0, newbufcolumn, bufsize - tokenBegin, bufpos);
 
  57            bufcolumn = newbufcolumn;
 
  59            maxNextCharInd = (bufpos += (bufsize - tokenBegin));
 
  63            System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin);
 
  66            System.arraycopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin);
 
  69            System.arraycopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin);
 
  70            bufcolumn = newbufcolumn;
 
  72            maxNextCharInd = (bufpos -= tokenBegin);
 
  77         throw new Error(t.getMessage());
 
  86   static protected void FillBuff() throws java.io.IOException
 
  88      if (maxNextCharInd == available)
 
  90         if (available == bufsize)
 
  92            if (tokenBegin > 2048)
 
  95               bufpos = maxNextCharInd = 0;
 
  96               available = tokenBegin;
 
  98            else if (tokenBegin < 0) {
 
 100               bufpos = maxNextCharInd = 0;
 
 104         else if (available > tokenBegin)
 
 106         else if ((tokenBegin - available) < 2048)
 
 109            available = tokenBegin;
 
 114         if ((i = inputStream.read(buffer, maxNextCharInd,
 
 115                                     available - maxNextCharInd)) == -1)
 
 118            throw new java.io.IOException();
 
 123         currentBuffer.append(buffer);
 
 126      catch(java.io.IOException e) {
 
 129         if (tokenBegin == -1)
 
 135   static public char BeginToken() throws java.io.IOException
 
 144   static 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   static public char readChar() throws java.io.IOException
 
 190         if (++bufpos == bufsize) {
 
 195         return buffer[bufpos];
 
 198      if (++bufpos >= maxNextCharInd) {
 
 202      char c = buffer[bufpos];
 
 213   static public int getColumn() {
 
 214      return bufcolumn[bufpos];
 
 222   static public int getLine() {
 
 223      return bufline[bufpos];
 
 226   static public int getEndColumn() {
 
 227      return bufcolumn[bufpos];
 
 230   static public int getEndLine() {
 
 231      return bufline[bufpos];
 
 234   static public int getBeginColumn() {
 
 235      return bufcolumn[tokenBegin];
 
 238   static public int getBeginLine() {
 
 239      return bufline[tokenBegin];
 
 242   static public void backup(int amount) {
 
 245     if ((bufpos -= amount) < 0)
 
 249   public SimpleCharStream(java.io.Reader dstream, int startline,
 
 250   int startcolumn, int buffersize)
 
 252     if (inputStream != null)
 
 253        throw new Error("\n   ERROR: Second call to the constructor of a static SimpleCharStream.  You must\n" +
 
 254        "       either use ReInit() or set the JavaCC option STATIC to false\n" +
 
 255        "       during the generation of this class.");
 
 256     inputStream = dstream;
 
 257     currentBuffer = new StringBuffer();
 
 259     column = startcolumn - 1;
 
 261     available = bufsize = buffersize;
 
 262     buffer = new char[buffersize];
 
 263     bufline = new int[buffersize];
 
 264     bufcolumn = new int[buffersize];
 
 267   public SimpleCharStream(java.io.Reader dstream, int startline,
 
 270      this(dstream, startline, startcolumn, 4096);
 
 273   public SimpleCharStream(java.io.Reader dstream)
 
 275      this(dstream, 1, 1, 4096);
 
 277   public void ReInit(java.io.Reader dstream, int startline,
 
 278   int startcolumn, int buffersize)
 
 280     inputStream = dstream;
 
 281     currentBuffer = new StringBuffer();
 
 283     column = startcolumn - 1;
 
 285     if (buffer == null || buffersize != buffer.length)
 
 287       available = bufsize = buffersize;
 
 288       buffer = new char[buffersize];
 
 289       bufline = new int[buffersize];
 
 290       bufcolumn = new int[buffersize];
 
 292     prevCharIsLF = prevCharIsCR = false;
 
 293     tokenBegin = inBuf = maxNextCharInd = 0;
 
 298   public void ReInit(java.io.Reader dstream, int startline,
 
 301      ReInit(dstream, startline, startcolumn, 4096);
 
 304   public void ReInit(java.io.Reader dstream)
 
 306      ReInit(dstream, 1, 1, 4096);
 
 308   public SimpleCharStream(java.io.InputStream dstream, int startline,
 
 309   int startcolumn, int buffersize)
 
 311      this(new java.io.InputStreamReader(dstream), startline, startcolumn, 4096);
 
 314   public SimpleCharStream(java.io.InputStream dstream, int startline,
 
 317      this(dstream, startline, startcolumn, 4096);
 
 320   public SimpleCharStream(java.io.InputStream dstream)
 
 322      this(dstream, 1, 1, 4096);
 
 325   public void ReInit(java.io.InputStream dstream, int startline,
 
 326                           int startcolumn, int buffersize)
 
 328      ReInit(new java.io.InputStreamReader(dstream), startline, startcolumn, 4096);
 
 331   public void ReInit(java.io.InputStream dstream)
 
 333      ReInit(dstream, 1, 1, 4096);
 
 335   public void ReInit(java.io.InputStream dstream, int startline,
 
 338      ReInit(dstream, startline, startcolumn, 4096);
 
 340   static public String GetImage()
 
 342      if (bufpos >= tokenBegin)
 
 343         return new String(buffer, tokenBegin, bufpos - tokenBegin + 1);
 
 345         return new String(buffer, tokenBegin, bufsize - tokenBegin) +
 
 346                               new String(buffer, 0, bufpos + 1);
 
 349   static public char[] GetSuffix(int len)
 
 351      char[] ret = new char[len];
 
 353      if ((bufpos + 1) >= len)
 
 354         System.arraycopy(buffer, bufpos - len + 1, ret, 0, len);
 
 357         System.arraycopy(buffer, bufsize - (len - bufpos - 1), ret, 0,
 
 359         System.arraycopy(buffer, 0, ret, len - bufpos - 1, bufpos + 1);
 
 365   static public void Done()
 
 373    * Method to adjust line and column numbers for the start of a token.<BR>
 
 375   static public void adjustBeginLineColumn(int newLine, int newCol)
 
 377      int start = tokenBegin;
 
 380      if (bufpos >= tokenBegin)
 
 382         len = bufpos - tokenBegin + inBuf + 1;
 
 386         len = bufsize - tokenBegin + bufpos + 1 + inBuf;
 
 389      int i = 0, j = 0, k = 0;
 
 390      int nextColDiff = 0, columnDiff = 0;
 
 393             bufline[j = start % bufsize] == bufline[k = ++start % bufsize])
 
 395         bufline[j] = newLine;
 
 396         nextColDiff = columnDiff + bufcolumn[k] - bufcolumn[j];
 
 397         bufcolumn[j] = newCol + columnDiff;
 
 398         columnDiff = nextColDiff;
 
 404         bufline[j] = newLine++;
 
 405         bufcolumn[j] = newCol + columnDiff;
 
 409            if (bufline[j = start % bufsize] != bufline[++start % bufsize])
 
 410               bufline[j] = newLine++;
 
 412               bufline[j] = newLine;
 
 417      column = bufcolumn[j];
 
 421   public static int getPosition() {
 
 422     return position + bufpos;