Magentix2  2.1.1
es.upv.dsic.gti_ia.norms.SimpleCharStream Class Reference

List of all members.

Public Member Functions

char BeginToken () throws java.io.IOException
char readChar () throws java.io.IOException
int getColumn ()
int getLine ()
int getEndColumn ()
int getEndLine ()
int getBeginColumn ()
int getBeginLine ()
void backup (int amount)
 SimpleCharStream (java.io.Reader dstream, int startline, int startcolumn, int buffersize)
 SimpleCharStream (java.io.Reader dstream, int startline, int startcolumn)
 SimpleCharStream (java.io.Reader dstream)
void ReInit (java.io.Reader dstream, int startline, int startcolumn, int buffersize)
void ReInit (java.io.Reader dstream, int startline, int startcolumn)
void ReInit (java.io.Reader dstream)
 SimpleCharStream (java.io.InputStream dstream, String encoding, int startline, int startcolumn, int buffersize) throws java.io.UnsupportedEncodingException
 SimpleCharStream (java.io.InputStream dstream, int startline, int startcolumn, int buffersize)
 SimpleCharStream (java.io.InputStream dstream, String encoding, int startline, int startcolumn) throws java.io.UnsupportedEncodingException
 SimpleCharStream (java.io.InputStream dstream, int startline, int startcolumn)
 SimpleCharStream (java.io.InputStream dstream, String encoding) throws java.io.UnsupportedEncodingException
 SimpleCharStream (java.io.InputStream dstream)
void ReInit (java.io.InputStream dstream, String encoding, int startline, int startcolumn, int buffersize) throws java.io.UnsupportedEncodingException
void ReInit (java.io.InputStream dstream, int startline, int startcolumn, int buffersize)
void ReInit (java.io.InputStream dstream, String encoding) throws java.io.UnsupportedEncodingException
void ReInit (java.io.InputStream dstream)
void ReInit (java.io.InputStream dstream, String encoding, int startline, int startcolumn) throws java.io.UnsupportedEncodingException
void ReInit (java.io.InputStream dstream, int startline, int startcolumn)
String GetImage ()
char[] GetSuffix (int len)
void Done ()
void adjustBeginLineColumn (int newLine, int newCol)

Public Attributes

int bufpos = -1

Static Public Attributes

static final boolean staticFlag = false

Protected Member Functions

void setTabSize (int i)
int getTabSize (int i)
void ExpandBuff (boolean wrapAround)
void FillBuff () throws java.io.IOException
void UpdateLineColumn (char c)

Protected Attributes

int bufline []
int bufcolumn []
int column = 0
int line = 1
boolean prevCharIsCR = false
boolean prevCharIsLF = false
java.io.Reader inputStream
char[] buffer
int maxNextCharInd = 0
int inBuf = 0
int tabSize = 8

Package Attributes

int bufsize
int available
int tokenBegin

Detailed Description

An implementation of interface CharStream, where the stream is assumed to contain only ASCII characters (without unicode processing).

Definition at line 10 of file SimpleCharStream.java.


Constructor & Destructor Documentation

es.upv.dsic.gti_ia.norms.SimpleCharStream.SimpleCharStream ( java.io.Reader  dstream,
int  startline,
int  startcolumn,
int  buffersize 
)

Constructor.

Definition at line 253 of file SimpleCharStream.java.

  {
    inputStream = dstream;
    line = startline;
    column = startcolumn - 1;

    available = bufsize = buffersize;
    buffer = new char[buffersize];
    bufline = new int[buffersize];
    bufcolumn = new int[buffersize];
  }
es.upv.dsic.gti_ia.norms.SimpleCharStream.SimpleCharStream ( java.io.Reader  dstream,
int  startline,
int  startcolumn 
)

Constructor.

Definition at line 267 of file SimpleCharStream.java.

  {
    this(dstream, startline, startcolumn, 4096);
  }

Constructor.

Definition at line 274 of file SimpleCharStream.java.

  {
    this(dstream, 1, 1, 4096);
  }
es.upv.dsic.gti_ia.norms.SimpleCharStream.SimpleCharStream ( java.io.InputStream  dstream,
String  encoding,
int  startline,
int  startcolumn,
int  buffersize 
) throws java.io.UnsupportedEncodingException

Constructor.

Definition at line 312 of file SimpleCharStream.java.

  {
    this(encoding == null ? new java.io.InputStreamReader(dstream) : new java.io.InputStreamReader(dstream, encoding), startline, startcolumn, buffersize);
  }
es.upv.dsic.gti_ia.norms.SimpleCharStream.SimpleCharStream ( java.io.InputStream  dstream,
int  startline,
int  startcolumn,
int  buffersize 
)

Constructor.

Definition at line 319 of file SimpleCharStream.java.

  {
    this(new java.io.InputStreamReader(dstream), startline, startcolumn, buffersize);
  }
es.upv.dsic.gti_ia.norms.SimpleCharStream.SimpleCharStream ( java.io.InputStream  dstream,
String  encoding,
int  startline,
int  startcolumn 
) throws java.io.UnsupportedEncodingException

Constructor.

Definition at line 326 of file SimpleCharStream.java.

  {
    this(dstream, encoding, startline, startcolumn, 4096);
  }
es.upv.dsic.gti_ia.norms.SimpleCharStream.SimpleCharStream ( java.io.InputStream  dstream,
int  startline,
int  startcolumn 
)

Constructor.

Definition at line 333 of file SimpleCharStream.java.

  {
    this(dstream, startline, startcolumn, 4096);
  }
es.upv.dsic.gti_ia.norms.SimpleCharStream.SimpleCharStream ( java.io.InputStream  dstream,
String  encoding 
) throws java.io.UnsupportedEncodingException

Constructor.

Definition at line 340 of file SimpleCharStream.java.

  {
    this(dstream, encoding, 1, 1, 4096);
  }

Constructor.

Definition at line 346 of file SimpleCharStream.java.

  {
    this(dstream, 1, 1, 4096);
  }

Member Function Documentation

Method to adjust line and column numbers for the start of a token.

Definition at line 426 of file SimpleCharStream.java.

  {
    int start = tokenBegin;
    int len;

    if (bufpos >= tokenBegin)
    {
      len = bufpos - tokenBegin + inBuf + 1;
    }
    else
    {
      len = bufsize - tokenBegin + bufpos + 1 + inBuf;
    }

    int i = 0, j = 0, k = 0;
    int nextColDiff = 0, columnDiff = 0;

    while (i < len && bufline[j = start % bufsize] == bufline[k = ++start % bufsize])
    {
      bufline[j] = newLine;
      nextColDiff = columnDiff + bufcolumn[k] - bufcolumn[j];
      bufcolumn[j] = newCol + columnDiff;
      columnDiff = nextColDiff;
      i++;
    }

    if (i < len)
    {
      bufline[j] = newLine++;
      bufcolumn[j] = newCol + columnDiff;

      while (i++ < len)
      {
        if (bufline[j = start % bufsize] != bufline[++start % bufsize])
          bufline[j] = newLine++;
        else
          bufline[j] = newLine;
      }
    }

    line = bufline[j];
    column = bufcolumn[j];
  }

Backup a number of characters.

Definition at line 245 of file SimpleCharStream.java.

                                 {

    inBuf += amount;
    if ((bufpos -= amount) < 0)
      bufpos += bufsize;
  }
char es.upv.dsic.gti_ia.norms.SimpleCharStream.BeginToken ( ) throws java.io.IOException

Start.

Definition at line 133 of file SimpleCharStream.java.

  {
    tokenBegin = -1;
    char c = readChar();
    tokenBegin = bufpos;

    return c;
  }

Reset buffer when finished.

Definition at line 416 of file SimpleCharStream.java.

  {
    buffer = null;
    bufline = null;
    bufcolumn = null;
  }
void es.upv.dsic.gti_ia.norms.SimpleCharStream.ExpandBuff ( boolean  wrapAround) [protected]

Definition at line 39 of file SimpleCharStream.java.

  {
    char[] newbuffer = new char[bufsize + 2048];
    int newbufline[] = new int[bufsize + 2048];
    int newbufcolumn[] = new int[bufsize + 2048];

    try
    {
      if (wrapAround)
      {
        System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin);
        System.arraycopy(buffer, 0, newbuffer, bufsize - tokenBegin, bufpos);
        buffer = newbuffer;

        System.arraycopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin);
        System.arraycopy(bufline, 0, newbufline, bufsize - tokenBegin, bufpos);
        bufline = newbufline;

        System.arraycopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin);
        System.arraycopy(bufcolumn, 0, newbufcolumn, bufsize - tokenBegin, bufpos);
        bufcolumn = newbufcolumn;

        maxNextCharInd = (bufpos += (bufsize - tokenBegin));
      }
      else
      {
        System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin);
        buffer = newbuffer;

        System.arraycopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin);
        bufline = newbufline;

        System.arraycopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin);
        bufcolumn = newbufcolumn;

        maxNextCharInd = (bufpos -= tokenBegin);
      }
    }
    catch (Throwable t)
    {
      throw new Error(t.getMessage());
    }


    bufsize += 2048;
    available = bufsize;
    tokenBegin = 0;
  }
void es.upv.dsic.gti_ia.norms.SimpleCharStream.FillBuff ( ) throws java.io.IOException [protected]

Definition at line 88 of file SimpleCharStream.java.

  {
    if (maxNextCharInd == available)
    {
      if (available == bufsize)
      {
        if (tokenBegin > 2048)
        {
          bufpos = maxNextCharInd = 0;
          available = tokenBegin;
        }
        else if (tokenBegin < 0)
          bufpos = maxNextCharInd = 0;
        else
          ExpandBuff(false);
      }
      else if (available > tokenBegin)
        available = bufsize;
      else if ((tokenBegin - available) < 2048)
        ExpandBuff(true);
      else
        available = tokenBegin;
    }

    int i;
    try {
      if ((i = inputStream.read(buffer, maxNextCharInd, available - maxNextCharInd)) == -1)
      {
        inputStream.close();
        throw new java.io.IOException();
      }
      else
        maxNextCharInd += i;
      return;
    }
    catch(java.io.IOException e) {
      --bufpos;
      backup(0);
      if (tokenBegin == -1)
        tokenBegin = bufpos;
      throw e;
    }
  }

Get token beginning column number.

Definition at line 235 of file SimpleCharStream.java.

                              {
    return bufcolumn[tokenBegin];
  }

Get token beginning line number.

Definition at line 240 of file SimpleCharStream.java.

                            {
    return bufline[tokenBegin];
  }

Get token end column number.

Definition at line 225 of file SimpleCharStream.java.

                            {
    return bufcolumn[bufpos];
  }

Get token end line number.

Definition at line 230 of file SimpleCharStream.java.

                          {
     return bufline[bufpos];
  }

Get token literal value.

Definition at line 389 of file SimpleCharStream.java.

  {
    if (bufpos >= tokenBegin)
      return new String(buffer, tokenBegin, bufpos - tokenBegin + 1);
    else
      return new String(buffer, tokenBegin, bufsize - tokenBegin) +
                            new String(buffer, 0, bufpos + 1);
  }

Get the suffix.

Definition at line 399 of file SimpleCharStream.java.

  {
    char[] ret = new char[len];

    if ((bufpos + 1) >= len)
      System.arraycopy(buffer, bufpos - len + 1, ret, 0, len);
    else
    {
      System.arraycopy(buffer, bufsize - (len - bufpos - 1), ret, 0,
                                                        len - bufpos - 1);
      System.arraycopy(buffer, 0, ret, len - bufpos - 1, bufpos + 1);
    }

    return ret;
  }

Definition at line 36 of file SimpleCharStream.java.

{ return tabSize; }
char es.upv.dsic.gti_ia.norms.SimpleCharStream.readChar ( ) throws java.io.IOException

Read a character.

Definition at line 183 of file SimpleCharStream.java.

  {
    if (inBuf > 0)
    {
      --inBuf;

      if (++bufpos == bufsize)
        bufpos = 0;

      return buffer[bufpos];
    }

    if (++bufpos >= maxNextCharInd)
      FillBuff();

    char c = buffer[bufpos];

    UpdateLineColumn(c);
    return c;
  }
void es.upv.dsic.gti_ia.norms.SimpleCharStream.ReInit ( java.io.Reader  dstream,
int  startline,
int  startcolumn,
int  buffersize 
)

Reinitialise.

Definition at line 280 of file SimpleCharStream.java.

  {
    inputStream = dstream;
    line = startline;
    column = startcolumn - 1;

    if (buffer == null || buffersize != buffer.length)
    {
      available = bufsize = buffersize;
      buffer = new char[buffersize];
      bufline = new int[buffersize];
      bufcolumn = new int[buffersize];
    }
    prevCharIsLF = prevCharIsCR = false;
    tokenBegin = inBuf = maxNextCharInd = 0;
    bufpos = -1;
  }
void es.upv.dsic.gti_ia.norms.SimpleCharStream.ReInit ( java.io.Reader  dstream,
int  startline,
int  startcolumn 
)

Reinitialise.

Definition at line 300 of file SimpleCharStream.java.

  {
    ReInit(dstream, startline, startcolumn, 4096);
  }
void es.upv.dsic.gti_ia.norms.SimpleCharStream.ReInit ( java.io.Reader  dstream)

Reinitialise.

Definition at line 307 of file SimpleCharStream.java.

  {
    ReInit(dstream, 1, 1, 4096);
  }
void es.upv.dsic.gti_ia.norms.SimpleCharStream.ReInit ( java.io.InputStream  dstream,
String  encoding,
int  startline,
int  startcolumn,
int  buffersize 
) throws java.io.UnsupportedEncodingException

Reinitialise.

Definition at line 352 of file SimpleCharStream.java.

  {
    ReInit(encoding == null ? new java.io.InputStreamReader(dstream) : new java.io.InputStreamReader(dstream, encoding), startline, startcolumn, buffersize);
  }
void es.upv.dsic.gti_ia.norms.SimpleCharStream.ReInit ( java.io.InputStream  dstream,
int  startline,
int  startcolumn,
int  buffersize 
)

Reinitialise.

Definition at line 359 of file SimpleCharStream.java.

  {
    ReInit(new java.io.InputStreamReader(dstream), startline, startcolumn, buffersize);
  }
void es.upv.dsic.gti_ia.norms.SimpleCharStream.ReInit ( java.io.InputStream  dstream,
String  encoding 
) throws java.io.UnsupportedEncodingException

Reinitialise.

Definition at line 366 of file SimpleCharStream.java.

  {
    ReInit(dstream, encoding, 1, 1, 4096);
  }
void es.upv.dsic.gti_ia.norms.SimpleCharStream.ReInit ( java.io.InputStream  dstream)

Reinitialise.

Definition at line 372 of file SimpleCharStream.java.

  {
    ReInit(dstream, 1, 1, 4096);
  }
void es.upv.dsic.gti_ia.norms.SimpleCharStream.ReInit ( java.io.InputStream  dstream,
String  encoding,
int  startline,
int  startcolumn 
) throws java.io.UnsupportedEncodingException

Reinitialise.

Definition at line 377 of file SimpleCharStream.java.

  {
    ReInit(dstream, encoding, startline, startcolumn, 4096);
  }
void es.upv.dsic.gti_ia.norms.SimpleCharStream.ReInit ( java.io.InputStream  dstream,
int  startline,
int  startcolumn 
)

Reinitialise.

Definition at line 383 of file SimpleCharStream.java.

  {
    ReInit(dstream, startline, startcolumn, 4096);
  }

Definition at line 35 of file SimpleCharStream.java.

{ tabSize = i; }

Definition at line 142 of file SimpleCharStream.java.

  {
    column++;

    if (prevCharIsLF)
    {
      prevCharIsLF = false;
      line += (column = 1);
    }
    else if (prevCharIsCR)
    {
      prevCharIsCR = false;
      if (c == '\n')
      {
        prevCharIsLF = true;
      }
      else
        line += (column = 1);
    }

    switch (c)
    {
      case '\r' :
        prevCharIsCR = true;
        break;
      case '\n' :
        prevCharIsLF = true;
        break;
      case '\t' :
        column--;
        column += (tabSize - (column % tabSize));
        break;
      default :
        break;
    }

    bufline[bufpos] = line;
    bufcolumn[bufpos] = column;
  }

Member Data Documentation

Definition at line 20 of file SimpleCharStream.java.

Definition at line 30 of file SimpleCharStream.java.

Definition at line 19 of file SimpleCharStream.java.

Position in buffer.

Definition at line 18 of file SimpleCharStream.java.

Definition at line 22 of file SimpleCharStream.java.

Definition at line 32 of file SimpleCharStream.java.

Definition at line 28 of file SimpleCharStream.java.

Definition at line 23 of file SimpleCharStream.java.

Definition at line 25 of file SimpleCharStream.java.

Definition at line 26 of file SimpleCharStream.java.

Whether parser is static.

Definition at line 13 of file SimpleCharStream.java.

Definition at line 33 of file SimpleCharStream.java.


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables