Update of /cvsroot/webmacro/webmacro/src/org/webmacro/parser In directory sc8-pr-cvs1:/tmp/cvs-serv6675/src/org/webmacro/parser Modified Files: ASCII_CharStream.java BackupCharStream.java CharStream.java ParseException.java ParserBlockBuilder.java ParserRuntimeException.java Token.java TokenMgrError.java WMParser.java WMParser_impl.java WMParser_implConstants.java WMParser_implTokenManager.java Log Message: If this doesn't drive our SF "activity" stats through the roof, I don't know what will. Mass re-formatting of all code, following (to the best of my interpertation) the Sun (w/ jakarta tweaks) coding style guidelines defined here: http://java.sun.com/docs/codeconv/html/CodeConvTOC.doc.html and here: http://jakarta.apache.org/turbine/common/code-standards.html I did this reformatting with IDEA 3.0.5, and I am going to commit the style configuration for IDEA (if I can find it). Index: ASCII_CharStream.java =================================================================== RCS file: /cvsroot/webmacro/webmacro/src/org/webmacro/parser/ASCII_CharStream.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** ASCII_CharStream.java 11 Jun 2002 17:43:22 -0000 1.5 --- ASCII_CharStream.java 12 Jun 2003 00:47:45 -0000 1.6 *************** *** 10,317 **** */ ! public final class ASCII_CharStream { ! private static final class Buffer { ! int size; ! int dataLen, curPos; ! char[] buffer; ! int[] bufline, bufcolumn; ! public Buffer(int n) { ! size = n; ! dataLen = 0; ! curPos = -1; ! buffer = new char[n]; ! bufline = new int[n]; ! bufcolumn = new int[n]; ! } ! public void expand(int n) { ! char[] newbuffer = new char[size + n]; ! int newbufline[] = new int[size + n]; ! int newbufcolumn[] = new int[size + n]; ! try { ! System.arraycopy(buffer, 0, newbuffer, 0, size); ! buffer = newbuffer; ! System.arraycopy(bufline, 0, newbufline, 0, size); ! bufline = newbufline; ! System.arraycopy(bufcolumn, 0, newbufcolumn, 0, size); ! bufcolumn = newbufcolumn; ! } ! catch (Throwable t) { ! throw new Error(t.getMessage()); ! } ! size += n; ! } ! } ! private Buffer bufA, bufB, curBuf, otherBuf, tokenBeginBuf; ! private int tokenBeginPos; ! private int backupChars; ! public static final boolean staticFlag = false; ! private int column = 0; ! private int line = 1; ! private boolean prevCharIsCR = false; ! private boolean prevCharIsLF = false; ! private java.io.Reader inputStream; ! private final void swapBuf() { ! Buffer tmp = curBuf; ! curBuf = otherBuf; ! otherBuf = tmp; ! } ! private final void FillBuff() throws java.io.IOException { ! // Buffer fill logic: ! // If there is at least 2K left in this buffer, just read some more ! // Otherwise, if we're processing a token and it either ! // (a) starts in the other buffer (meaning it's filled both part of ! // the other buffer and some of this one, or ! // (b) starts in the first 2K of this buffer (meaning its taken up ! // most of this buffer ! // we expand this buffer. Otherwise, we swap buffers. ! // This guarantees we will be able to back up at least 2K characters. ! if (curBuf.size - curBuf.dataLen < 2048) { ! if (tokenBeginPos >= 0 ! && ((tokenBeginBuf == curBuf && tokenBeginPos < 2048) ! || tokenBeginBuf != curBuf)) { ! curBuf.expand(2048); ! } ! else { ! swapBuf(); ! curBuf.curPos = curBuf.dataLen = 0; ! } ! } ! try { ! int i = inputStream.read(curBuf.buffer, curBuf.dataLen, ! curBuf.size - curBuf.dataLen); ! if (i == -1) { ! inputStream.close(); ! throw new java.io.IOException(); ! } ! else ! curBuf.dataLen += i; ! return; ! } ! catch (java.io.IOException e) { ! if (curBuf.curPos > 0) ! --curBuf.curPos; ! if (tokenBeginPos == -1) { ! tokenBeginPos = curBuf.curPos; ! tokenBeginBuf = curBuf; ! } ! throw e; ! } ! } ! public final char BeginToken() throws java.io.IOException { ! tokenBeginPos = -1; ! char c = readChar(); ! tokenBeginBuf = curBuf; ! tokenBeginPos = curBuf.curPos; ! return c; ! } ! private final void UpdateLineColumn(char c) { ! 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 += (8 - (column & 07)); ! break; ! default : ! break; ! } ! curBuf.bufline[curBuf.curPos] = line; ! curBuf.bufcolumn[curBuf.curPos] = column; ! } ! public final char readChar() throws java.io.IOException { ! // When we hit the end of the buffer, if we're backing up, we just ! // swap, if we're not, we fill. ! if (++curBuf.curPos >= curBuf.dataLen) { ! if (backupChars > 0) { ! --curBuf.curPos; ! swapBuf(); ! } ! else ! FillBuff(); ! } ! ; ! char c = (char) ((char) 0xff & curBuf.buffer[curBuf.curPos]); ! // No need to update line numbers if we've already processed this char ! if (backupChars > 0) ! --backupChars; ! else ! UpdateLineColumn(c); ! return (c); ! } ! /** ! * @deprecated ! * @see #getEndColumn ! */ ! public final int getColumn() { ! return curBuf.bufcolumn[curBuf.curPos]; ! } ! /** ! * @deprecated ! * @see #getEndLine ! */ ! public final int getLine() { ! return curBuf.bufline[curBuf.curPos]; ! } ! public final int getEndColumn() { ! return curBuf.bufcolumn[curBuf.curPos]; ! } ! public final int getEndLine() { ! return curBuf.bufline[curBuf.curPos]; ! } ! public final int getBeginColumn() { ! return tokenBeginBuf.bufcolumn[tokenBeginPos]; ! } ! public final int getBeginLine() { ! return tokenBeginBuf.bufline[tokenBeginPos]; ! } ! public final void backup(int amount) { ! backupChars += amount; ! if (curBuf.curPos - amount < 0) { ! int addlChars = amount - 1 - curBuf.curPos; ! curBuf.curPos = 0; ! swapBuf(); ! curBuf.curPos = curBuf.dataLen - addlChars - 1; ! } ! else { ! curBuf.curPos -= amount; ! } ! } ! public ASCII_CharStream(java.io.Reader dstream, int startline, ! int startcolumn, int buffersize) { ! ReInit(dstream, startline, startcolumn, buffersize); ! } ! public ASCII_CharStream(java.io.Reader dstream, int startline, ! int startcolumn) { ! this(dstream, startline, startcolumn, 4096); ! } ! public void ReInit(java.io.Reader dstream, int startline, ! int startcolumn, int buffersize) { ! inputStream = dstream; ! line = startline; ! column = startcolumn - 1; ! if (bufA == null || bufA.size != buffersize) ! bufA = new Buffer(buffersize); ! if (bufB == null || bufB.size != buffersize) ! bufB = new Buffer(buffersize); ! curBuf = bufA; ! otherBuf = bufB; ! curBuf.curPos = otherBuf.dataLen = -1; ! curBuf.dataLen = otherBuf.dataLen = 0; ! prevCharIsLF = prevCharIsCR = false; ! tokenBeginPos = -1; ! tokenBeginBuf = null; ! backupChars = 0; ! } ! public void ReInit(java.io.Reader dstream, int startline, ! int startcolumn) { ! ReInit(dstream, startline, startcolumn, 4096); ! } ! public ASCII_CharStream(java.io.InputStream dstream, int startline, ! int startcolumn, int buffersize) { ! this(new java.io.InputStreamReader(dstream), startline, startcolumn, 4096); ! } ! public ASCII_CharStream(java.io.InputStream dstream, int startline, ! int startcolumn) { ! this(dstream, startline, startcolumn, 4096); ! } ! public void ReInit(java.io.InputStream dstream, int startline, ! int startcolumn, int buffersize) { ! ReInit(new java.io.InputStreamReader(dstream), startline, startcolumn, ! 4096); ! } ! public void ReInit(java.io.InputStream dstream, int startline, ! int startcolumn) { ! ReInit(dstream, startline, startcolumn, 4096); ! } ! public final String GetImage() { ! if (tokenBeginBuf == curBuf) ! return new String(curBuf.buffer, tokenBeginPos, ! curBuf.curPos - tokenBeginPos + 1); ! else ! return new String(otherBuf.buffer, tokenBeginPos, ! otherBuf.dataLen - tokenBeginPos) ! + new String(curBuf.buffer, 0, curBuf.curPos + 1); ! } ! public final char[] GetSuffix(int len) { ! char[] ret = new char[len]; ! if ((curBuf.curPos + 1) >= len) ! System.arraycopy(curBuf.buffer, curBuf.curPos - len + 1, ret, 0, len); ! else { ! if (otherBuf.dataLen >= len - curBuf.curPos - 1) ! System.arraycopy(otherBuf.buffer, ! otherBuf.dataLen - (len - curBuf.curPos - 1), ret, 0, ! len - curBuf.curPos - 1); ! System.arraycopy(curBuf.buffer, 0, ret, len - curBuf.curPos - 1, ! curBuf.curPos + 1); ! } ! return null; ! } ! public void Done() { ! bufA = bufB = curBuf = otherBuf = null; ! } } --- 10,362 ---- */ ! public final class ASCII_CharStream ! { ! private static final class Buffer ! { ! int size; ! int dataLen, curPos; ! char[] buffer; ! int[] bufline, bufcolumn; ! public Buffer (int n) ! { ! size = n; ! dataLen = 0; ! curPos = -1; ! buffer = new char[n]; ! bufline = new int[n]; ! bufcolumn = new int[n]; ! } ! public void expand (int n) ! { ! char[] newbuffer = new char[size + n]; ! int newbufline[] = new int[size + n]; ! int newbufcolumn[] = new int[size + n]; ! try ! { ! System.arraycopy(buffer, 0, newbuffer, 0, size); ! buffer = newbuffer; ! System.arraycopy(bufline, 0, newbufline, 0, size); ! bufline = newbufline; ! System.arraycopy(bufcolumn, 0, newbufcolumn, 0, size); ! bufcolumn = newbufcolumn; ! } ! catch (Throwable t) ! { ! throw new Error(t.getMessage()); ! } ! size += n; ! } ! } ! private Buffer bufA, bufB, curBuf, otherBuf, tokenBeginBuf; ! private int tokenBeginPos; ! private int backupChars; ! public static final boolean staticFlag = false; ! private int column = 0; ! private int line = 1; ! private boolean prevCharIsCR = false; ! private boolean prevCharIsLF = false; ! private java.io.Reader inputStream; ! private final void swapBuf () ! { ! Buffer tmp = curBuf; ! curBuf = otherBuf; ! otherBuf = tmp; ! } ! private final void FillBuff () throws java.io.IOException ! { ! // Buffer fill logic: ! // If there is at least 2K left in this buffer, just read some more ! // Otherwise, if we're processing a token and it either ! // (a) starts in the other buffer (meaning it's filled both part of ! // the other buffer and some of this one, or ! // (b) starts in the first 2K of this buffer (meaning its taken up ! // most of this buffer ! // we expand this buffer. Otherwise, we swap buffers. ! // This guarantees we will be able to back up at least 2K characters. ! if (curBuf.size - curBuf.dataLen < 2048) ! { ! if (tokenBeginPos >= 0 ! && ((tokenBeginBuf == curBuf && tokenBeginPos < 2048) ! || tokenBeginBuf != curBuf)) ! { ! curBuf.expand(2048); ! } ! else ! { ! swapBuf(); ! curBuf.curPos = curBuf.dataLen = 0; ! } ! } ! try ! { ! int i = inputStream.read(curBuf.buffer, curBuf.dataLen, ! curBuf.size - curBuf.dataLen); ! if (i == -1) ! { ! inputStream.close(); ! throw new java.io.IOException(); ! } ! else ! curBuf.dataLen += i; ! return; ! } ! catch (java.io.IOException e) ! { ! if (curBuf.curPos > 0) ! --curBuf.curPos; ! if (tokenBeginPos == -1) ! { ! tokenBeginPos = curBuf.curPos; ! tokenBeginBuf = curBuf; ! } ! throw e; ! } ! } ! public final char BeginToken () throws java.io.IOException ! { ! tokenBeginPos = -1; ! char c = readChar(); ! tokenBeginBuf = curBuf; ! tokenBeginPos = curBuf.curPos; ! return c; ! } ! private final void UpdateLineColumn (char c) ! { ! 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 += (8 - (column & 07)); ! break; ! default : ! break; ! } ! curBuf.bufline[curBuf.curPos] = line; ! curBuf.bufcolumn[curBuf.curPos] = column; ! } ! public final char readChar () throws java.io.IOException ! { ! // When we hit the end of the buffer, if we're backing up, we just ! // swap, if we're not, we fill. ! if (++curBuf.curPos >= curBuf.dataLen) ! { ! if (backupChars > 0) ! { ! --curBuf.curPos; ! swapBuf(); ! } ! else ! FillBuff(); ! } ! ; ! char c = (char) ((char) 0xff & curBuf.buffer[curBuf.curPos]); ! // No need to update line numbers if we've already processed this char ! if (backupChars > 0) ! --backupChars; ! else ! UpdateLineColumn(c); ! return (c); ! } ! /** ! * @deprecated ! * @see #getEndColumn ! */ ! public final int getColumn () ! { ! return curBuf.bufcolumn[curBuf.curPos]; ! } ! /** ! * @deprecated ! * @see #getEndLine ! */ ! public final int getLine () ! { ! return curBuf.bufline[curBuf.curPos]; ! } ! public final int getEndColumn () ! { ! return curBuf.bufcolumn[curBuf.curPos]; ! } ! public final int getEndLine () ! { ! return curBuf.bufline[curBuf.curPos]; ! } ! public final int getBeginColumn () ! { ! return tokenBeginBuf.bufcolumn[tokenBeginPos]; ! } ! public final int getBeginLine () ! { ! return tokenBeginBuf.bufline[tokenBeginPos]; ! } ! public final void backup (int amount) ! { ! backupChars += amount; ! if (curBuf.curPos - amount < 0) ! { ! int addlChars = amount - 1 - curBuf.curPos; ! curBuf.curPos = 0; ! swapBuf(); ! curBuf.curPos = curBuf.dataLen - addlChars - 1; ! } ! else ! { ! curBuf.curPos -= amount; ! } ! } ! public ASCII_CharStream (java.io.Reader dstream, int startline, ! int startcolumn, int buffersize) ! { ! ReInit(dstream, startline, startcolumn, buffersize); ! } ! public ASCII_CharStream (java.io.Reader dstream, int startline, ! int startcolumn) ! { ! this(dstream, startline, startcolumn, 4096); ! } ! public void ReInit (java.io.Reader dstream, int startline, ! int startcolumn, int buffersize) ! { ! inputStream = dstream; ! line = startline; ! column = startcolumn - 1; ! if (bufA == null || bufA.size != buffersize) ! bufA = new Buffer(buffersize); ! if (bufB == null || bufB.size != buffersize) ! bufB = new Buffer(buffersize); ! curBuf = bufA; ! otherBuf = bufB; ! curBuf.curPos = otherBuf.dataLen = -1; ! curBuf.dataLen = otherBuf.dataLen = 0; ! prevCharIsLF = prevCharIsCR = false; ! tokenBeginPos = -1; ! tokenBeginBuf = null; ! backupChars = 0; ! } ! public void ReInit (java.io.Reader dstream, int startline, ! int startcolumn) ! { ! ReInit(dstream, startline, startcolumn, 4096); ! } ! public ASCII_CharStream (java.io.InputStream dstream, int startline, ! int startcolumn, int buffersize) ! { ! this(new java.io.InputStreamReader(dstream), startline, startcolumn, 4096); ! } ! public ASCII_CharStream (java.io.InputStream dstream, int startline, ! int startcolumn) ! { ! this(dstream, startline, startcolumn, 4096); ! } ! public void ReInit (java.io.InputStream dstream, int startline, ! int startcolumn, int buffersize) ! { ! ReInit(new java.io.InputStreamReader(dstream), startline, startcolumn, ! 4096); ! } ! public void ReInit (java.io.InputStream dstream, int startline, ! int startcolumn) ! { ! ReInit(dstream, startline, startcolumn, 4096); ! } ! public final String GetImage () ! { ! if (tokenBeginBuf == curBuf) ! return new String(curBuf.buffer, tokenBeginPos, ! curBuf.curPos - tokenBeginPos + 1); ! else ! return new String(otherBuf.buffer, tokenBeginPos, ! otherBuf.dataLen - tokenBeginPos) ! + new String(curBuf.buffer, 0, curBuf.curPos + 1); ! } ! public final char[] GetSuffix (int len) ! { ! char[] ret = new char[len]; ! if ((curBuf.curPos + 1) >= len) ! System.arraycopy(curBuf.buffer, curBuf.curPos - len + 1, ret, 0, len); ! else ! { ! if (otherBuf.dataLen >= len - curBuf.curPos - 1) ! System.arraycopy(otherBuf.buffer, ! otherBuf.dataLen - (len - curBuf.curPos - 1), ret, 0, ! len - curBuf.curPos - 1); ! System.arraycopy(curBuf.buffer, 0, ret, len - curBuf.curPos - 1, ! curBuf.curPos + 1); ! } ! return null; ! } ! public void Done () ! { ! bufA = bufB = curBuf = otherBuf = null; ! } } Index: BackupCharStream.java =================================================================== RCS file: /cvsroot/webmacro/webmacro/src/org/webmacro/parser/BackupCharStream.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** BackupCharStream.java 11 Jun 2002 17:43:22 -0000 1.6 --- BackupCharStream.java 12 Jun 2003 00:47:46 -0000 1.7 *************** *** 11,343 **** */ ! public final class BackupCharStream implements CharStream { ! private static final class Buffer { ! int size; ! int dataLen, curPos; ! char[] buffer; ! int[] bufline, bufcolumn; ! public Buffer(int n) { ! size = n; ! dataLen = 0; ! curPos = -1; ! buffer = new char[n]; ! bufline = new int[n]; ! bufcolumn = new int[n]; ! } ! public void expand(int n) { ! char[] newbuffer = new char[size + n]; ! int newbufline[] = new int[size + n]; ! int newbufcolumn[] = new int[size + n]; ! try { ! System.arraycopy(buffer, 0, newbuffer, 0, size); ! buffer = newbuffer; ! System.arraycopy(bufline, 0, newbufline, 0, size); ! bufline = newbufline; ! System.arraycopy(bufcolumn, 0, newbufcolumn, 0, size); ! bufcolumn = newbufcolumn; ! } ! catch (Throwable t) { ! throw new Error(t.getMessage()); ! } ! size += n; ! } ! } ! private Buffer bufA, bufB, curBuf, otherBuf, tokenBeginBuf; ! private int tokenBeginPos; ! private int backupChars; ! public static final boolean staticFlag = false; ! private int column = 0; ! private int line = 1; ! private boolean prevCharIsCR = false; ! private boolean prevCharIsLF = false; ! private java.io.Reader inputStream; ! private boolean inputStreamClosed = false; ! private final void swapBuf() { ! Buffer tmp = curBuf; ! curBuf = otherBuf; ! otherBuf = tmp; ! } ! private final void FillBuff() throws java.io.IOException { ! // Buffer fill logic: ! // If there is at least 2K left in this buffer, just read some more ! // Otherwise, if we're processing a token and it either ! // (a) starts in the other buffer (meaning it's filled both part of ! // the other buffer and some of this one, or ! // (b) starts in the first 2K of this buffer (meaning its taken up ! // most of this buffer ! // we expand this buffer. Otherwise, we swap buffers. ! // This guarantees we will be able to back up at least 2K characters. ! if (curBuf.size - curBuf.dataLen < 2048) { ! if (tokenBeginPos >= 0 ! && ((tokenBeginBuf == curBuf && tokenBeginPos < 2048) ! || tokenBeginBuf != curBuf)) { ! curBuf.expand(2048); ! } ! else { ! swapBuf(); ! curBuf.curPos = curBuf.dataLen = 0; ! } ! } ! try { ! int i = inputStream.read(curBuf.buffer, curBuf.dataLen, ! curBuf.size - curBuf.dataLen); ! if (i == -1) { ! inputStream.close(); ! inputStreamClosed = true; ! throw new java.io.IOException(); ! } ! else ! curBuf.dataLen += i; ! return; ! } ! catch (java.io.IOException e) { ! if (curBuf.curPos > 0) ! --curBuf.curPos; ! if (tokenBeginPos == -1) { ! tokenBeginPos = curBuf.curPos; ! tokenBeginBuf = curBuf; ! } ! if (e.getClass().getName().equals("sun.io.MalformedInputException")) { ! // it's an ugly hack, but we want to pass this exception ! // through the JavaCC parser, since it has a bad ! // exception handling ! throw new ParserRuntimeException("MalformedInput", e); ! } ! throw e; ! } ! } ! public final char BeginToken() throws java.io.IOException { ! tokenBeginPos = -1; ! char c = readChar(); ! tokenBeginBuf = curBuf; ! tokenBeginPos = curBuf.curPos; ! return c; ! } ! private final void UpdateLineColumn(char c) { ! 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 += (8 - (column & 07)); ! break; ! default : ! break; ! } ! curBuf.bufline[curBuf.curPos] = line; ! curBuf.bufcolumn[curBuf.curPos] = column; ! } ! public final char readChar() throws java.io.IOException { ! // When we hit the end of the buffer, if we're backing up, we just ! // swap, if we're not, we fill. ! if (++curBuf.curPos >= curBuf.dataLen) { ! if (backupChars > 0) { ! --curBuf.curPos; ! swapBuf(); ! } ! else ! FillBuff(); ! } ! ; ! // Don't mask off the high byte ! char c = curBuf.buffer[curBuf.curPos]; ! // No need to update line numbers if we've already processed this char ! if (backupChars > 0) ! --backupChars; ! else ! UpdateLineColumn(c); ! return (c); ! } ! /** ! * @deprecated ! * @see #getEndColumn ! */ ! public final int getColumn() { ! return curBuf.bufcolumn[curBuf.curPos]; ! } ! /** ! * @deprecated ! * @see #getEndLine ! */ ! public final int getLine() { ! return curBuf.bufline[curBuf.curPos]; ! } ! public final int getEndColumn() { ! return curBuf.bufcolumn[curBuf.curPos]; ! } ! public final int getEndLine() { ! return curBuf.bufline[curBuf.curPos]; ! } ! public final int getBeginColumn() { ! return tokenBeginBuf.bufcolumn[tokenBeginPos]; ! } ! public final int getBeginLine() { ! return tokenBeginBuf.bufline[tokenBeginPos]; ! } ! public final void backup(int amount) { ! backupChars += amount; ! if (curBuf.curPos - amount < 0) { ! int addlChars = amount - (inputStreamClosed? 0 : 1) - curBuf.curPos; ! curBuf.curPos = 0; ! swapBuf(); ! curBuf.curPos = curBuf.dataLen - addlChars - 1; ! } ! else { ! curBuf.curPos -= amount; ! } ! } ! public BackupCharStream(java.io.Reader dstream) { ! this(dstream, 1, 1, 4096); ! } ! public BackupCharStream(java.io.Reader dstream, int startline, ! int startcolumn, int buffersize) { ! ReInit(dstream, startline, startcolumn, buffersize); ! } ! public BackupCharStream(java.io.Reader dstream, int startline, ! int startcolumn) { ! this(dstream, startline, startcolumn, 4096); ! } ! public void ReInit(java.io.Reader dstream, int startline, ! int startcolumn, int buffersize) { ! inputStream = dstream; ! inputStreamClosed = false; ! line = startline; ! column = startcolumn - 1; ! if (bufA == null || bufA.size != buffersize) ! bufA = new Buffer(buffersize); ! if (bufB == null || bufB.size != buffersize) ! bufB = new Buffer(buffersize); ! curBuf = bufA; ! otherBuf = bufB; ! curBuf.curPos = otherBuf.dataLen = -1; ! curBuf.dataLen = otherBuf.dataLen = 0; ! prevCharIsLF = prevCharIsCR = false; ! tokenBeginPos = -1; ! tokenBeginBuf = null; ! backupChars = 0; ! } ! public void ReInit(java.io.Reader dstream, int startline, ! int startcolumn) { ! ReInit(dstream, startline, startcolumn, 4096); ! } ! public void ReInit(java.io.Reader dstream) { ! ReInit(dstream, 1, 1, 4096); ! } ! public BackupCharStream(java.io.InputStream dstream, int startline, ! int startcolumn, int buffersize) { ! this(new java.io.InputStreamReader(dstream), startline, startcolumn, 4096); ! } ! public BackupCharStream(java.io.InputStream dstream, int startline, ! int startcolumn) { ! this(dstream, startline, startcolumn, 4096); ! } ! public void ReInit(java.io.InputStream dstream, int startline, ! int startcolumn, int buffersize) { ! ReInit(new java.io.InputStreamReader(dstream), startline, startcolumn, ! 4096); ! } ! public void ReInit(java.io.InputStream dstream, int startline, ! int startcolumn) { ! ReInit(dstream, startline, startcolumn, 4096); ! } ! public final String GetImage() { ! String ret; ! if (tokenBeginBuf == curBuf) { ! ret = new String(curBuf.buffer, tokenBeginPos, ! curBuf.curPos - tokenBeginPos + 1); ! } ! else { ! ret = new String(otherBuf.buffer, tokenBeginPos, ! otherBuf.dataLen - tokenBeginPos); ! if (curBuf.curPos < curBuf.dataLen) ! ret += new String(curBuf.buffer, 0, curBuf.curPos + 1); ! } ! return ret; ! } ! public final char[] GetSuffix(int len) { ! char[] ret = new char[len]; ! if ((curBuf.curPos + 1) >= len) ! System.arraycopy(curBuf.buffer, curBuf.curPos - len + 1, ret, 0, len); ! else { ! if (otherBuf.dataLen >= len - curBuf.curPos - 1) ! System.arraycopy(otherBuf.buffer, ! otherBuf.dataLen - (len - curBuf.curPos - 1), ret, 0, ! len - curBuf.curPos - 1); ! System.arraycopy(curBuf.buffer, 0, ret, len - curBuf.curPos - 1, ! curBuf.curPos + 1); ! } ! return null; ! } ! public void Done() { ! bufA = bufB = curBuf = otherBuf = null; ! } } --- 11,393 ---- */ ! public final class BackupCharStream implements CharStream ! { ! private static final class Buffer ! { ! int size; ! int dataLen, curPos; ! char[] buffer; ! int[] bufline, bufcolumn; ! public Buffer (int n) ! { ! size = n; ! dataLen = 0; ! curPos = -1; ! buffer = new char[n]; ! bufline = new int[n]; ! bufcolumn = new int[n]; ! } ! public void expand (int n) ! { ! char[] newbuffer = new char[size + n]; ! int newbufline[] = new int[size + n]; ! int newbufcolumn[] = new int[size + n]; ! try ! { ! System.arraycopy(buffer, 0, newbuffer, 0, size); ! buffer = newbuffer; ! System.arraycopy(bufline, 0, newbufline, 0, size); ! bufline = newbufline; ! System.arraycopy(bufcolumn, 0, newbufcolumn, 0, size); ! bufcolumn = newbufcolumn; ! } ! catch (Throwable t) ! { ! throw new Error(t.getMessage()); ! } ! size += n; ! } ! } ! private Buffer bufA, bufB, curBuf, otherBuf, tokenBeginBuf; ! private int tokenBeginPos; ! private int backupChars; ! public static final boolean staticFlag = false; ! private int column = 0; ! private int line = 1; ! private boolean prevCharIsCR = false; ! private boolean prevCharIsLF = false; ! private java.io.Reader inputStream; ! private boolean inputStreamClosed = false; ! private final void swapBuf () ! { ! Buffer tmp = curBuf; ! curBuf = otherBuf; ! otherBuf = tmp; ! } ! private final void FillBuff () throws java.io.IOException ! { ! // Buffer fill logic: ! // If there is at least 2K left in this buffer, just read some more ! // Otherwise, if we're processing a token and it either ! // (a) starts in the other buffer (meaning it's filled both part of ! // the other buffer and some of this one, or ! // (b) starts in the first 2K of this buffer (meaning its taken up ! // most of this buffer ! // we expand this buffer. Otherwise, we swap buffers. ! // This guarantees we will be able to back up at least 2K characters. ! if (curBuf.size - curBuf.dataLen < 2048) ! { ! if (tokenBeginPos >= 0 ! && ((tokenBeginBuf == curBuf && tokenBeginPos < 2048) ! || tokenBeginBuf != curBuf)) ! { ! curBuf.expand(2048); ! } ! else ! { ! swapBuf(); ! curBuf.curPos = curBuf.dataLen = 0; ! } ! } ! try ! { ! int i = inputStream.read(curBuf.buffer, curBuf.dataLen, ! curBuf.size - curBuf.dataLen); ! if (i == -1) ! { ! inputStream.close(); ! inputStreamClosed = true; ! throw new java.io.IOException(); ! } ! else ! curBuf.dataLen += i; ! return; ! } ! catch (java.io.IOException e) ! { ! if (curBuf.curPos > 0) ! --curBuf.curPos; ! if (tokenBeginPos == -1) ! { ! tokenBeginPos = curBuf.curPos; ! tokenBeginBuf = curBuf; ! } ! if (e.getClass().getName().equals("sun.io.MalformedInputException")) ! { ! // it's an ugly hack, but we want to pass this exception ! // through the JavaCC parser, since it has a bad ! // exception handling ! throw new ParserRuntimeException("MalformedInput", e); ! } ! throw e; ! } ! } ! public final char BeginToken () throws java.io.IOException ! { ! tokenBeginPos = -1; ! char c = readChar(); ! tokenBeginBuf = curBuf; ! tokenBeginPos = curBuf.curPos; ! return c; ! } ! private final void UpdateLineColumn (char c) ! { ! 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 += (8 - (column & 07)); ! break; ! default : ! break; ! } ! curBuf.bufline[curBuf.curPos] = line; ! curBuf.bufcolumn[curBuf.curPos] = column; ! } ! public final char readChar () throws java.io.IOException ! { ! // When we hit the end of the buffer, if we're backing up, we just ! // swap, if we're not, we fill. ! if (++curBuf.curPos >= curBuf.dataLen) ! { ! if (backupChars > 0) ! { ! --curBuf.curPos; ! swapBuf(); ! } ! else ! FillBuff(); ! } ! ; ! // Don't mask off the high byte ! char c = curBuf.buffer[curBuf.curPos]; ! // No need to update line numbers if we've already processed this char ! if (backupChars > 0) ! --backupChars; ! else ! UpdateLineColumn(c); ! return (c); ! } ! /** ! * @deprecated ! * @see #getEndColumn ! */ ! public final int getColumn () ! { ! return curBuf.bufcolumn[curBuf.curPos]; ! } ! /** ! * @deprecated ! * @see #getEndLine ! */ ! public final int getLine () ! { ! return curBuf.bufline[curBuf.curPos]; ! } ! public final int getEndColumn () ! { ! return curBuf.bufcolumn[curBuf.curPos]; ! } ! public final int getEndLine () ! { ! return curBuf.bufline[curBuf.curPos]; ! } ! public final int getBeginColumn () ! { ! return tokenBeginBuf.bufcolumn[tokenBeginPos]; ! } ! public final int getBeginLine () ! { ! return tokenBeginBuf.bufline[tokenBeginPos]; ! } ! public final void backup (int amount) ! { ! backupChars += amount; ! if (curBuf.curPos - amount < 0) ! { ! int addlChars = amount - (inputStreamClosed ? 0 : 1) - curBuf.curPos; ! curBuf.curPos = 0; ! swapBuf(); ! curBuf.curPos = curBuf.dataLen - addlChars - 1; ! } ! else ! { ! curBuf.curPos -= amount; ! } ! } ! public BackupCharStream (java.io.Reader dstream) ! { ! this(dstream, 1, 1, 4096); ! } ! public BackupCharStream (java.io.Reader dstream, int startline, ! int startcolumn, int buffersize) ! { ! ReInit(dstream, startline, startcolumn, buffersize); ! } ! public BackupCharStream (java.io.Reader dstream, int startline, ! int startcolumn) ! { ! this(dstream, startline, startcolumn, 4096); ! } ! public void ReInit (java.io.Reader dstream, int startline, ! int startcolumn, int buffersize) ! { ! inputStream = dstream; ! inputStreamClosed = false; ! line = startline; ! column = startcolumn - 1; ! if (bufA == null || bufA.size != buffersize) ! bufA = new Buffer(buffersize); ! if (bufB == null || bufB.size != buffersize) ! bufB = new Buffer(buffersize); ! curBuf = bufA; ! otherBuf = bufB; ! curBuf.curPos = otherBuf.dataLen = -1; ! curBuf.dataLen = otherBuf.dataLen = 0; ! prevCharIsLF = prevCharIsCR = false; ! tokenBeginPos = -1; ! tokenBeginBuf = null; ! backupChars = 0; ! } ! public void ReInit (java.io.Reader dstream, int startline, ! int startcolumn) ! { ! ReInit(dstream, startline, startcolumn, 4096); ! } ! public void ReInit (java.io.Reader dstream) ! { ! ReInit(dstream, 1, 1, 4096); ! } ! public BackupCharStream (java.io.InputStream dstream, int startline, ! int startcolumn, int buffersize) ! { ! this(new java.io.InputStreamReader(dstream), startline, startcolumn, 4096); ! } ! public BackupCharStream (java.io.InputStream dstream, int startline, ! int startcolumn) ! { ! this(dstream, startline, startcolumn, 4096); ! } ! public void ReInit (java.io.InputStream dstream, int startline, ! int startcolumn, int buffersize) ! { ! ReInit(new java.io.InputStreamReader(dstream), startline, startcolumn, ! 4096); ! } ! public void ReInit (java.io.InputStream dstream, int startline, ! int startcolumn) ! { ! ReInit(dstream, startline, startcolumn, 4096); ! } ! public final String GetImage () ! { ! String ret; ! if (tokenBeginBuf == curBuf) ! { ! ret = new String(curBuf.buffer, tokenBeginPos, ! curBuf.curPos - tokenBeginPos + 1); ! } ! else ! { ! ret = new String(otherBuf.buffer, tokenBeginPos, ! otherBuf.dataLen - tokenBeginPos); ! if (curBuf.curPos < curBuf.dataLen) ! ret += new String(curBuf.buffer, 0, curBuf.curPos + 1); ! } ! return ret; ! } ! public final char[] GetSuffix (int len) ! { ! char[] ret = new char[len]; ! if ((curBuf.curPos + 1) >= len) ! System.arraycopy(curBuf.buffer, curBuf.curPos - len + 1, ret, 0, len); ! else ! { ! if (otherBuf.dataLen >= len - curBuf.curPos - 1) ! System.arraycopy(otherBuf.buffer, ! otherBuf.dataLen - (len - curBuf.curPos - 1), ret, 0, ! len - curBuf.curPos - 1); ! System.arraycopy(curBuf.buffer, 0, ret, len - curBuf.curPos - 1, ! curBuf.curPos + 1); ! } ! return null; ! } ! public void Done () ! { ! bufA = bufB = curBuf = otherBuf = null; ! } } Index: CharStream.java =================================================================== RCS file: /cvsroot/webmacro/webmacro/src/org/webmacro/parser/CharStream.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** CharStream.java 11 Nov 2002 04:53:11 -0000 1.4 --- CharStream.java 12 Jun 2003 00:47:46 -0000 1.5 *************** *** 17,110 **** */ ! public interface CharStream { ! /** ! * Returns the next character from the selected input. The method ! * of selecting the input is the responsibility of the class ! * implementing this interface. Can throw any java.io.IOException. ! */ ! char readChar() throws java.io.IOException; ! /** ! * Returns the column position of the character last read. ! * @deprecated ! * @see #getEndColumn ! */ ! int getColumn(); ! /** ! * Returns the line number of the character last read. ! * @deprecated ! * @see #getEndLine ! */ ! int getLine(); ! /** ! * Returns the column number of the last character for current token (being ! * matched after the last call to BeginTOken). ! */ ! int getEndColumn(); ! /** ! * Returns the line number of the last character for current token (being ! * matched after the last call to BeginTOken). ! */ ! int getEndLine(); ! /** ! * Returns the column number of the first character for current token (being ! * matched after the last call to BeginTOken). ! */ ! int getBeginColumn(); ! /** ! * Returns the line number of the first character for current token (being ! * matched after the last call to BeginTOken). ! */ ! int getBeginLine(); ! /** ! * Backs up the input stream by amount steps. Lexer calls this method if it ! * had already read some characters, but could not use them to match a ! * (longer) token. So, they will be used again as the prefix of the next ! * token and it is the implemetation's responsibility to do this right. ! */ ! void backup(int amount); ! /** ! * Returns the next character that marks the beginning of the next token. ! * All characters must remain in the buffer between two successive calls ! * to this method to implement backup correctly. ! */ ! char BeginToken() throws java.io.IOException; ! /** ! * Returns a string made up of characters from the marked token beginning ! * to the current buffer position. Implementations have the choice of returning ! * anything that they want to. For example, for efficiency, one might decide ! * to just return null, which is a valid implementation. ! */ ! String GetImage(); ! /** ! * Returns an array of characters that make up the suffix of length 'len' for ! * the currently matched token. This is used to build up the matched string ! * for use in actions in the case of MORE. A simple and inefficient ! * implementation of this is as follows : ! * ! * { ! * String t = GetImage(); ! * return t.substring(t.length() - len, t.length()).toCharArray(); ! * } ! */ ! char[] GetSuffix(int len); ! /** ! * The lexer calls this function to indicate that it is done with the stream ! * and hence implementations can free any resources held by this class. ! * Again, the body of this function can be just empty and it will not ! * affect the lexer's operation. ! */ ! void Done(); } --- 17,111 ---- */ ! public interface CharStream ! { ! /** ! * Returns the next character from the selected input. The method ! * of selecting the input is the responsibility of the class ! * implementing this interface. Can throw any java.io.IOException. ! */ ! char readChar () throws java.io.IOException; ! /** ! * Returns the column position of the character last read. ! * @deprecated ! * @see #getEndColumn ! */ ! int getColumn (); ! /** ! * Returns the line number of the character last read. ! * @deprecated ! * @see #getEndLine ! */ ! int getLine (); ! /** ! * Returns the column number of the last character for current token (being ! * matched after the last call to BeginTOken). ! */ ! int getEndColumn (); ! /** ! * Returns the line number of the last character for current token (being ! * matched after the last call to BeginTOken). ! */ ! int getEndLine (); ! /** ! * Returns the column number of the first character for current token (being ! * matched after the last call to BeginTOken). ! */ ! int getBeginColumn (); ! /** ! * Returns the line number of the first character for current token (being ! * matched after the last call to BeginTOken). ! */ ! int getBeginLine (); ! /** ! * Backs up the input stream by amount steps. Lexer calls this method if it ! * had already read some characters, but could not use them to match a ! * (longer) token. So, they will be used again as the prefix of the next ! * token and it is the implemetation's responsibility to do this right. ! */ ! void backup (int amount); ! /** ! * Returns the next character that marks the beginning of the next token. ! * All characters must remain in the buffer between two successive calls ! * to this method to implement backup correctly. ! */ ! char BeginToken () throws java.io.IOException; ! /** ! * Returns a string made up of characters from the marked token beginning ! * to the current buffer position. Implementations have the choice of returning ! * anything that they want to. For example, for efficiency, one might decide ! * to just return null, which is a valid implementation. ! */ ! String GetImage (); ! /** ! * Returns an array of characters that make up the suffix of length 'len' for ! * the currently matched token. This is used to build up the matched string ! * for use in actions in the case of MORE. A simple and inefficient ! * implementation of this is as follows : ! * ! * { ! * String t = GetImage(); ! * return t.substring(t.length() - len, t.length()).toCharArray(); ! * } ! */ ! char[] GetSuffix (int len); ! /** ! * The lexer calls this function to indicate that it is done with the stream ! * and hence implementations can free any resources held by this class. ! * Again, the body of this function can be just empty and it will not ! * affect the lexer's operation. ! */ ! void Done (); } Index: ParseException.java =================================================================== RCS file: /cvsroot/webmacro/webmacro/src/org/webmacro/parser/ParseException.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** ParseException.java 11 Jun 2002 17:43:22 -0000 1.3 --- ParseException.java 12 Jun 2003 00:47:46 -0000 1.4 *************** *** 11,196 **** * mechanisms so long as you retain the public fields. */ ! public class ParseException extends org.webmacro.RethrowableException { ! /** ! * This constructor is used by the method "generateParseException" ! * in the generated parser. Calling this constructor generates ! * a new object of this type with the fields "currentToken", ! * "expectedTokenSequences", and "tokenImage" set. The boolean ! * flag "specialConstructor" is also set to true to indicate that ! * this constructor was used to create this object. ! * This constructor calls its super class with the empty string ! * to force the "toString" method of parent class "Throwable" to ! * print the error message in the form: ! * ParseException: <result of getMessage> ! */ ! public ParseException(Token currentTokenVal, ! int[][] expectedTokenSequencesVal, ! String[] tokenImageVal ! ) { ! super(""); ! specialConstructor = true; ! currentToken = currentTokenVal; ! expectedTokenSequences = expectedTokenSequencesVal; ! tokenImage = tokenImageVal; ! } ! /** ! * The following constructors are for use by you for whatever ! * purpose you can think of. Constructing the exception in this ! * manner makes the exception behave in the normal way - i.e., as ! * documented in the class "Throwable". The fields "errorToken", ! * "expectedTokenSequences", and "tokenImage" do not contain ! * relevant information. The JavaCC generated code does not use ! * these constructors. ! */ ! public ParseException() { ! super(); ! specialConstructor = false; ! } ! public ParseException(String message) { ! super(message); ! specialConstructor = false; ! } ! public ParseException(String message, Exception e) { ! super(message, e); ! specialConstructor = false; ! } ! /** ! * This variable determines which constructor was used to create ! * this object and thereby affects the semantics of the ! * "getMessage" method (see below). ! */ ! protected boolean specialConstructor; ! /** ! * This is the last token that has been consumed successfully. If ! * this object has been created due to a parse error, the token ! * followng this token will (therefore) be the first error token. ! */ ! public Token currentToken; ! /** ! * Each entry in this array is an array of integers. Each array ! * of integers represents a sequence of tokens (by their ordinal ! * values) that is expected at this point of the parse. ! */ ! public int[][] expectedTokenSequences; ! /** ! * This is a reference to the "tokenImage" array of the generated ! * parser within which the parse error occurred. This array is ! * defined in the generated ...Constants interface. ! */ ! public String[] tokenImage; ! /** ! * This method has the standard behavior when this object has been ! * created using the standard constructors. Otherwise, it uses ! * "currentToken" and "expectedTokenSequences" to generate a parse ! * error message and returns it. If this object has been created ! * due to a parse error, and you do not catch it (it gets thrown ! * from the parser), then this method is called during the printing ! * of the final stack trace, and hence the correct error message ! * gets displayed. ! */ ! public String getMessage() { ! if (!specialConstructor) { ! return super.getMessage(); ! } ! String expected = ""; ! int maxSize = 0; ! for (int i = 0; i < expectedTokenSequences.length; i++) { ! if (maxSize < expectedTokenSequences[i].length) { ! maxSize = expectedTokenSequences[i].length; ! } ! for (int j = 0; j < expectedTokenSequences[i].length; j++) { ! expected += tokenImage[expectedTokenSequences[i][j]] + " "; ! } ! if (expectedTokenSequences[i][expectedTokenSequences[i].length - 1] != 0) { ! expected += "..."; ! } ! expected += eol + " "; ! } ! String retval = "Encountered \""; ! Token tok = currentToken.next; ! for (int i = 0; i < maxSize; i++) { ! if (i != 0) retval += " "; ! if (tok.kind == 0) { ! retval += tokenImage[0]; ! break; ! } ! retval += add_escapes(tok.image); ! tok = tok.next; ! } ! retval += "\" at line " + currentToken.next.beginLine + ", column " + currentToken.next.beginColumn + "." + eol; ! if (expectedTokenSequences.length == 1) { ! retval += "Was expecting:" + eol + " "; ! } ! else { ! retval += "Was expecting one of:" + eol + " "; ! } ! retval += expected; ! return retval; ! } ! /** ! * The end of line string for this machine. ! */ ! protected String eol = System.getProperty("line.separator", "\n"); ! /** ! * Used to convert raw characters to their escaped version ! * when these raw version cannot be used as part of an ASCII ! * string literal. ! */ ! protected String add_escapes(String str) { ! StringBuffer retval = new StringBuffer(); ! char ch; ! for (int i = 0; i < str.length(); i++) { ! switch (str.charAt(i)) { ! case 0: ! continue; ! case '\b': ! retval.append("\\b"); ! continue; ! case '\t': ! retval.append("\\t"); ! continue; ! case '\n': ! retval.append("\\n"); ! continue; ! case '\f': ! retval.append("\\f"); ! continue; ! case '\r': ! retval.append("\\r"); ! continue; ! case '\"': ! retval.append("\\\""); ! continue; ! case '\'': ! retval.append("\\\'"); ! continue; ! case '\\': ! retval.append("\\\\"); ! continue; ! default: ! if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) { ! String s = "0000" + Integer.toString(ch, 16); ! retval.append("\\u" + s.substring(s.length() - 4, s.length())); ! } ! else { ! retval.append(ch); ! } ! continue; ! } ! } ! return retval.toString(); ! } } --- 11,216 ---- * mechanisms so long as you retain the public fields. */ ! public class ParseException extends org.webmacro.RethrowableException ! { ! /** ! * This constructor is used by the method "generateParseException" ! * in the generated parser. Calling this constructor generates ! * a new object of this type with the fields "currentToken", ! * "expectedTokenSequences", and "tokenImage" set. The boolean ! * flag "specialConstructor" is also set to true to indicate that ! * this constructor was used to create this object. ! * This constructor calls its super class with the empty string ! * to force the "toString" method of parent class "Throwable" to ! * print the error message in the form: ! * ParseException: <result of getMessage> ! */ ! public ParseException (Token currentTokenVal, ! int[][] expectedTokenSequencesVal, ! String[] tokenImageVal ! ) ! { ! super(""); ! specialConstructor = true; ! currentToken = currentTokenVal; ! expectedTokenSequences = expectedTokenSequencesVal; ! tokenImage = tokenImageVal; ! } ! /** ! * The following constructors are for use by you for whatever ! * purpose you can think of. Constructing the exception in this ! * manner makes the exception behave in the normal way - i.e., as ! * documented in the class "Throwable". The fields "errorToken", ! * "expectedTokenSequences", and "tokenImage" do not contain ! * relevant information. The JavaCC generated code does not use ! * these constructors. ! */ ! public ParseException () ! { ! super(); ! specialConstructor = false; ! } ! public ParseException (String message) ! { ! super(message); ! specialConstructor = false; ! } ! public ParseException (String message, Exception e) ! { ! super(message, e); ! specialConstructor = false; ! } ! /** ! * This variable determines which constructor was used to create ! * this object and thereby affects the semantics of the ! * "getMessage" method (see below). ! */ ! protected boolean specialConstructor; ! /** ! * This is the last token that has been consumed successfully. If ! * this object has been created due to a parse error, the token ! * followng this token will (therefore) be the first error token. ! */ ! public Token currentToken; ! /** ! * Each entry in this array is an array of integers. Each array ! * of integers represents a sequence of tokens (by their ordinal ! * values) that is expected at this point of the parse. ! */ ! public int[][] expectedTokenSequences; ! /** ! * This is a reference to the "tokenImage" array of the generated ! * parser within which the parse error occurred. This array is ! * defined in the generated ...Constants interface. ! */ ! public String[] tokenImage; ! /** ! * This method has the standard behavior when this object has been ! * created using the standard constructors. Otherwise, it uses ! * "currentToken" and "expectedTokenSequences" to generate a parse ! * error message and returns it. If this object has been created ! * due to a parse error, and you do not catch it (it gets thrown ! * from the parser), then this method is called during the printing ! * of the final stack trace, and hence the correct error message ! * gets displayed. ! */ ! public String getMessage () ! { ! if (!specialConstructor) ! { ! return super.getMessage(); ! } ! String expected = ""; ! int maxSize = 0; ! for (int i = 0; i < expectedTokenSequences.length; i++) ! { ! if (maxSize < expectedTokenSequences[i].length) ! { ! maxSize = expectedTokenSequences[i].length; ! } ! for (int j = 0; j < expectedTokenSequences[i].length; j++) ! { ! expected += tokenImage[expectedTokenSequences[i][j]] + " "; ! } ! if (expectedTokenSequences[i][expectedTokenSequences[i].length - 1] != 0) ! { ! expected += "..."; ! } ! expected += eol + " "; ! } ! String retval = "Encountered \""; ! Token tok = currentToken.next; ! for (int i = 0; i < maxSize; i++) ! { ! ... [truncated message content] |