325N/A/*
325N/A * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
325N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
325N/A *
325N/A * This code is free software; you can redistribute it and/or modify it
325N/A * under the terms of the GNU General Public License version 2 only, as
325N/A * published by the Free Software Foundation. Oracle designates this
325N/A * particular file as subject to the "Classpath" exception as provided
325N/A * by Oracle in the LICENSE file that accompanied this code.
325N/A *
325N/A * This code is distributed in the hope that it will be useful, but WITHOUT
325N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
325N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
325N/A * version 2 for more details (a copy is included in the LICENSE file that
325N/A * accompanied this code).
325N/A *
325N/A * You should have received a copy of the GNU General Public License version
325N/A * 2 along with this work; if not, write to the Free Software Foundation,
325N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
325N/A *
325N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
325N/A * or visit www.oracle.com if you need additional information or have any
325N/A * questions.
325N/A */
325N/A/*
325N/A * Copyright (C) 2004-2011
325N/A *
325N/A * Permission is hereby granted, free of charge, to any person obtaining a copy
325N/A * of this software and associated documentation files (the "Software"), to deal
325N/A * in the Software without restriction, including without limitation the rights
325N/A * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
325N/A * copies of the Software, and to permit persons to whom the Software is
325N/A * furnished to do so, subject to the following conditions:
325N/A *
325N/A * The above copyright notice and this permission notice shall be included in
325N/A * all copies or substantial portions of the Software.
325N/A *
325N/A * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
325N/A * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
325N/A * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
325N/A * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
325N/A * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
325N/A * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
325N/A * THE SOFTWARE.
325N/A */
325N/A/* Generated By:JavaCC: Do not edit this line. JavaCharStream.java Version 5.0 */
325N/A/* JavaCCOptions:STATIC=false,SUPPORT_CLASS_VISIBILITY_PUBLIC=true */
325N/Apackage com.sun.xml.internal.rngom.parse.compact;
325N/A
325N/A/**
325N/A * An implementation of interface CharStream, where the stream is assumed to
325N/A * contain only ASCII characters (with java-like unicode escape processing).
325N/A */
325N/A
325N/Apublic
325N/Aclass JavaCharStream
325N/A{
325N/A /** Whether parser is static. */
325N/A public static final boolean staticFlag = false;
325N/A
325N/A static final int hexval(char c) throws java.io.IOException {
325N/A switch(c)
325N/A {
325N/A case '0' :
325N/A return 0;
325N/A case '1' :
325N/A return 1;
325N/A case '2' :
325N/A return 2;
325N/A case '3' :
325N/A return 3;
325N/A case '4' :
325N/A return 4;
325N/A case '5' :
325N/A return 5;
325N/A case '6' :
325N/A return 6;
325N/A case '7' :
325N/A return 7;
325N/A case '8' :
325N/A return 8;
325N/A case '9' :
325N/A return 9;
325N/A
325N/A case 'a' :
325N/A case 'A' :
325N/A return 10;
325N/A case 'b' :
325N/A case 'B' :
325N/A return 11;
325N/A case 'c' :
325N/A case 'C' :
325N/A return 12;
325N/A case 'd' :
325N/A case 'D' :
325N/A return 13;
325N/A case 'e' :
325N/A case 'E' :
325N/A return 14;
325N/A case 'f' :
325N/A case 'F' :
325N/A return 15;
325N/A }
325N/A
325N/A throw new java.io.IOException(); // Should never come here
325N/A }
325N/A
325N/A/** Position in buffer. */
325N/A public int bufpos = -1;
325N/A int bufsize;
325N/A int available;
325N/A int tokenBegin;
325N/A protected int bufline[];
325N/A protected int bufcolumn[];
325N/A
325N/A protected int column = 0;
325N/A protected int line = 1;
325N/A
325N/A protected boolean prevCharIsCR = false;
325N/A protected boolean prevCharIsLF = false;
325N/A
325N/A protected java.io.Reader inputStream;
325N/A
325N/A protected char[] nextCharBuf;
325N/A protected char[] buffer;
325N/A protected int maxNextCharInd = 0;
325N/A protected int nextCharInd = -1;
325N/A protected int inBuf = 0;
325N/A protected int tabSize = 8;
325N/A
325N/A protected void setTabSize(int i) { tabSize = i; }
325N/A protected int getTabSize(int i) { return tabSize; }
325N/A
325N/A protected void ExpandBuff(boolean wrapAround)
325N/A {
325N/A char[] newbuffer = new char[bufsize + 2048];
325N/A int newbufline[] = new int[bufsize + 2048];
325N/A int newbufcolumn[] = new int[bufsize + 2048];
325N/A
325N/A try
325N/A {
325N/A if (wrapAround)
325N/A {
325N/A System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin);
325N/A System.arraycopy(buffer, 0, newbuffer, bufsize - tokenBegin, bufpos);
325N/A buffer = newbuffer;
325N/A
325N/A System.arraycopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin);
325N/A System.arraycopy(bufline, 0, newbufline, bufsize - tokenBegin, bufpos);
325N/A bufline = newbufline;
325N/A
325N/A System.arraycopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin);
325N/A System.arraycopy(bufcolumn, 0, newbufcolumn, bufsize - tokenBegin, bufpos);
325N/A bufcolumn = newbufcolumn;
325N/A
325N/A bufpos += (bufsize - tokenBegin);
325N/A }
325N/A else
325N/A {
325N/A System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin);
325N/A buffer = newbuffer;
325N/A
325N/A System.arraycopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin);
325N/A bufline = newbufline;
325N/A
325N/A System.arraycopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin);
325N/A bufcolumn = newbufcolumn;
325N/A
325N/A bufpos -= tokenBegin;
325N/A }
325N/A }
325N/A catch (Throwable t)
325N/A {
325N/A throw new Error(t.getMessage());
325N/A }
325N/A
325N/A available = (bufsize += 2048);
325N/A tokenBegin = 0;
325N/A }
325N/A
325N/A protected void FillBuff() throws java.io.IOException
325N/A {
325N/A int i;
325N/A if (maxNextCharInd == 4096)
325N/A maxNextCharInd = nextCharInd = 0;
325N/A
325N/A try {
325N/A if ((i = inputStream.read(nextCharBuf, maxNextCharInd,
325N/A 4096 - maxNextCharInd)) == -1)
325N/A {
325N/A inputStream.close();
325N/A throw new java.io.IOException();
325N/A }
325N/A else
325N/A maxNextCharInd += i;
325N/A return;
325N/A }
325N/A catch(java.io.IOException e) {
325N/A if (bufpos != 0)
325N/A {
325N/A --bufpos;
325N/A backup(0);
325N/A }
325N/A else
325N/A {
325N/A bufline[bufpos] = line;
325N/A bufcolumn[bufpos] = column;
325N/A }
325N/A throw e;
325N/A }
325N/A }
325N/A
325N/A protected char ReadByte() throws java.io.IOException
325N/A {
325N/A if (++nextCharInd >= maxNextCharInd)
325N/A FillBuff();
325N/A
325N/A return nextCharBuf[nextCharInd];
325N/A }
325N/A
325N/A/** @return starting character for token. */
325N/A public char BeginToken() throws java.io.IOException
325N/A {
325N/A if (inBuf > 0)
325N/A {
325N/A --inBuf;
325N/A
325N/A if (++bufpos == bufsize)
325N/A bufpos = 0;
325N/A
325N/A tokenBegin = bufpos;
325N/A return buffer[bufpos];
325N/A }
325N/A
325N/A tokenBegin = 0;
325N/A bufpos = -1;
325N/A
325N/A return readChar();
325N/A }
325N/A
325N/A protected void AdjustBuffSize()
325N/A {
325N/A if (available == bufsize)
325N/A {
325N/A if (tokenBegin > 2048)
325N/A {
325N/A bufpos = 0;
325N/A available = tokenBegin;
325N/A }
325N/A else
325N/A ExpandBuff(false);
325N/A }
325N/A else if (available > tokenBegin)
325N/A available = bufsize;
325N/A else if ((tokenBegin - available) < 2048)
325N/A ExpandBuff(true);
325N/A else
325N/A available = tokenBegin;
325N/A }
325N/A
325N/A protected void UpdateLineColumn(char c)
325N/A {
325N/A column++;
325N/A
325N/A if (prevCharIsLF)
325N/A {
325N/A prevCharIsLF = false;
325N/A line += (column = 1);
325N/A }
325N/A else if (prevCharIsCR)
325N/A {
325N/A prevCharIsCR = false;
325N/A if (c == '\n')
325N/A {
325N/A prevCharIsLF = true;
325N/A }
325N/A else
325N/A line += (column = 1);
325N/A }
325N/A
325N/A switch (c)
325N/A {
325N/A case '\r' :
325N/A prevCharIsCR = true;
325N/A break;
325N/A case '\n' :
325N/A prevCharIsLF = true;
325N/A break;
325N/A case '\t' :
325N/A column--;
325N/A column += (tabSize - (column % tabSize));
325N/A break;
325N/A default :
325N/A break;
325N/A }
325N/A
325N/A bufline[bufpos] = line;
325N/A bufcolumn[bufpos] = column;
325N/A }
325N/A
325N/A/** Read a character. */
325N/A public char readChar() throws java.io.IOException
325N/A {
325N/A if (inBuf > 0)
325N/A {
325N/A --inBuf;
325N/A
325N/A if (++bufpos == bufsize)
325N/A bufpos = 0;
325N/A
325N/A return buffer[bufpos];
325N/A }
325N/A
325N/A char c;
325N/A
325N/A if (++bufpos == available)
325N/A AdjustBuffSize();
325N/A
325N/A if ((buffer[bufpos] = c = ReadByte()) == '\\')
325N/A {
325N/A UpdateLineColumn(c);
325N/A
325N/A int backSlashCnt = 1;
325N/A
325N/A for (;;) // Read all the backslashes
325N/A {
325N/A if (++bufpos == available)
325N/A AdjustBuffSize();
325N/A
325N/A try
325N/A {
325N/A if ((buffer[bufpos] = c = ReadByte()) != '\\')
325N/A {
325N/A UpdateLineColumn(c);
325N/A // found a non-backslash char.
325N/A if ((c == 'u') && ((backSlashCnt & 1) == 1))
325N/A {
325N/A if (--bufpos < 0)
325N/A bufpos = bufsize - 1;
325N/A
325N/A break;
325N/A }
325N/A
325N/A backup(backSlashCnt);
325N/A return '\\';
325N/A }
325N/A }
325N/A catch(java.io.IOException e)
325N/A {
325N/A // We are returning one backslash so we should only backup (count-1)
325N/A if (backSlashCnt > 1)
325N/A backup(backSlashCnt-1);
325N/A
325N/A return '\\';
325N/A }
325N/A
325N/A UpdateLineColumn(c);
325N/A backSlashCnt++;
325N/A }
325N/A
325N/A // Here, we have seen an odd number of backslash's followed by a 'u'
325N/A try
325N/A {
325N/A while ((c = ReadByte()) == 'u')
325N/A ++column;
325N/A
325N/A buffer[bufpos] = c = (char)(hexval(c) << 12 |
325N/A hexval(ReadByte()) << 8 |
325N/A hexval(ReadByte()) << 4 |
325N/A hexval(ReadByte()));
325N/A
325N/A column += 4;
325N/A }
325N/A catch(java.io.IOException e)
325N/A {
325N/A throw new Error("Invalid escape character at line " + line +
325N/A " column " + column + ".");
325N/A }
325N/A
325N/A if (backSlashCnt == 1)
325N/A return c;
325N/A else
325N/A {
325N/A backup(backSlashCnt - 1);
325N/A return '\\';
325N/A }
325N/A }
325N/A else
325N/A {
325N/A UpdateLineColumn(c);
325N/A return c;
325N/A }
325N/A }
325N/A
325N/A @Deprecated
325N/A /**
325N/A * @deprecated
325N/A * @see #getEndColumn
325N/A */
325N/A public int getColumn() {
325N/A return bufcolumn[bufpos];
325N/A }
325N/A
325N/A @Deprecated
325N/A /**
325N/A * @deprecated
325N/A * @see #getEndLine
325N/A */
325N/A public int getLine() {
325N/A return bufline[bufpos];
325N/A }
325N/A
325N/A/** Get end column. */
325N/A public int getEndColumn() {
325N/A return bufcolumn[bufpos];
325N/A }
325N/A
325N/A/** Get end line. */
325N/A public int getEndLine() {
325N/A return bufline[bufpos];
325N/A }
325N/A
325N/A/** @return column of token start */
325N/A public int getBeginColumn() {
325N/A return bufcolumn[tokenBegin];
325N/A }
325N/A
325N/A/** @return line number of token start */
325N/A public int getBeginLine() {
325N/A return bufline[tokenBegin];
325N/A }
325N/A
325N/A/** Retreat. */
325N/A public void backup(int amount) {
325N/A
325N/A inBuf += amount;
325N/A if ((bufpos -= amount) < 0)
325N/A bufpos += bufsize;
325N/A }
325N/A
325N/A/** Constructor. */
325N/A public JavaCharStream(java.io.Reader dstream,
325N/A int startline, int startcolumn, int buffersize)
325N/A {
325N/A inputStream = dstream;
325N/A line = startline;
325N/A column = startcolumn - 1;
325N/A
325N/A available = bufsize = buffersize;
325N/A buffer = new char[buffersize];
325N/A bufline = new int[buffersize];
325N/A bufcolumn = new int[buffersize];
325N/A nextCharBuf = new char[4096];
325N/A }
325N/A
325N/A/** Constructor. */
325N/A public JavaCharStream(java.io.Reader dstream,
325N/A int startline, int startcolumn)
325N/A {
325N/A this(dstream, startline, startcolumn, 4096);
325N/A }
325N/A
325N/A/** Constructor. */
325N/A public JavaCharStream(java.io.Reader dstream)
325N/A {
325N/A this(dstream, 1, 1, 4096);
325N/A }
325N/A/** Reinitialise. */
325N/A public void ReInit(java.io.Reader dstream,
325N/A int startline, int startcolumn, int buffersize)
325N/A {
325N/A inputStream = dstream;
325N/A line = startline;
325N/A column = startcolumn - 1;
325N/A
325N/A if (buffer == null || buffersize != buffer.length)
325N/A {
325N/A available = bufsize = buffersize;
325N/A buffer = new char[buffersize];
325N/A bufline = new int[buffersize];
325N/A bufcolumn = new int[buffersize];
325N/A nextCharBuf = new char[4096];
325N/A }
325N/A prevCharIsLF = prevCharIsCR = false;
325N/A tokenBegin = inBuf = maxNextCharInd = 0;
325N/A nextCharInd = bufpos = -1;
325N/A }
325N/A
325N/A/** Reinitialise. */
325N/A public void ReInit(java.io.Reader dstream,
325N/A int startline, int startcolumn)
325N/A {
325N/A ReInit(dstream, startline, startcolumn, 4096);
325N/A }
325N/A
325N/A/** Reinitialise. */
325N/A public void ReInit(java.io.Reader dstream)
325N/A {
325N/A ReInit(dstream, 1, 1, 4096);
325N/A }
325N/A/** Constructor. */
325N/A public JavaCharStream(java.io.InputStream dstream, String encoding, int startline,
325N/A int startcolumn, int buffersize) throws java.io.UnsupportedEncodingException
325N/A {
325N/A this(encoding == null ? new java.io.InputStreamReader(dstream) : new java.io.InputStreamReader(dstream, encoding), startline, startcolumn, buffersize);
325N/A }
325N/A
325N/A/** Constructor. */
325N/A public JavaCharStream(java.io.InputStream dstream, int startline,
325N/A int startcolumn, int buffersize)
325N/A {
325N/A this(new java.io.InputStreamReader(dstream), startline, startcolumn, 4096);
325N/A }
325N/A
325N/A/** Constructor. */
325N/A public JavaCharStream(java.io.InputStream dstream, String encoding, int startline,
325N/A int startcolumn) throws java.io.UnsupportedEncodingException
325N/A {
325N/A this(dstream, encoding, startline, startcolumn, 4096);
325N/A }
325N/A
325N/A/** Constructor. */
325N/A public JavaCharStream(java.io.InputStream dstream, int startline,
325N/A int startcolumn)
325N/A {
325N/A this(dstream, startline, startcolumn, 4096);
325N/A }
325N/A
325N/A/** Constructor. */
325N/A public JavaCharStream(java.io.InputStream dstream, String encoding) throws java.io.UnsupportedEncodingException
325N/A {
325N/A this(dstream, encoding, 1, 1, 4096);
325N/A }
325N/A
325N/A/** Constructor. */
325N/A public JavaCharStream(java.io.InputStream dstream)
325N/A {
325N/A this(dstream, 1, 1, 4096);
325N/A }
325N/A
325N/A/** Reinitialise. */
325N/A public void ReInit(java.io.InputStream dstream, String encoding, int startline,
325N/A int startcolumn, int buffersize) throws java.io.UnsupportedEncodingException
325N/A {
325N/A ReInit(encoding == null ? new java.io.InputStreamReader(dstream) : new java.io.InputStreamReader(dstream, encoding), startline, startcolumn, buffersize);
325N/A }
325N/A
325N/A/** Reinitialise. */
325N/A public void ReInit(java.io.InputStream dstream, int startline,
325N/A int startcolumn, int buffersize)
325N/A {
325N/A ReInit(new java.io.InputStreamReader(dstream), startline, startcolumn, buffersize);
325N/A }
325N/A/** Reinitialise. */
325N/A public void ReInit(java.io.InputStream dstream, String encoding, int startline,
325N/A int startcolumn) throws java.io.UnsupportedEncodingException
325N/A {
325N/A ReInit(dstream, encoding, startline, startcolumn, 4096);
325N/A }
325N/A/** Reinitialise. */
325N/A public void ReInit(java.io.InputStream dstream, int startline,
325N/A int startcolumn)
325N/A {
325N/A ReInit(dstream, startline, startcolumn, 4096);
325N/A }
325N/A/** Reinitialise. */
325N/A public void ReInit(java.io.InputStream dstream, String encoding) throws java.io.UnsupportedEncodingException
325N/A {
325N/A ReInit(dstream, encoding, 1, 1, 4096);
325N/A }
325N/A
325N/A/** Reinitialise. */
325N/A public void ReInit(java.io.InputStream dstream)
325N/A {
325N/A ReInit(dstream, 1, 1, 4096);
325N/A }
325N/A
325N/A /** @return token image as String */
325N/A public String GetImage()
325N/A {
325N/A if (bufpos >= tokenBegin)
325N/A return new String(buffer, tokenBegin, bufpos - tokenBegin + 1);
325N/A else
325N/A return new String(buffer, tokenBegin, bufsize - tokenBegin) +
325N/A new String(buffer, 0, bufpos + 1);
325N/A }
325N/A
325N/A /** @return suffix */
325N/A public char[] GetSuffix(int len)
325N/A {
325N/A char[] ret = new char[len];
325N/A
325N/A if ((bufpos + 1) >= len)
325N/A System.arraycopy(buffer, bufpos - len + 1, ret, 0, len);
325N/A else
325N/A {
325N/A System.arraycopy(buffer, bufsize - (len - bufpos - 1), ret, 0,
325N/A len - bufpos - 1);
325N/A System.arraycopy(buffer, 0, ret, len - bufpos - 1, bufpos + 1);
325N/A }
325N/A
325N/A return ret;
325N/A }
325N/A
325N/A /** Set buffers back to null when finished. */
325N/A public void Done()
325N/A {
325N/A nextCharBuf = null;
325N/A buffer = null;
325N/A bufline = null;
325N/A bufcolumn = null;
325N/A }
325N/A
325N/A /**
325N/A * Method to adjust line and column numbers for the start of a token.
325N/A */
325N/A public void adjustBeginLineColumn(int newLine, int newCol)
325N/A {
325N/A int start = tokenBegin;
325N/A int len;
325N/A
325N/A if (bufpos >= tokenBegin)
325N/A {
325N/A len = bufpos - tokenBegin + inBuf + 1;
325N/A }
325N/A else
325N/A {
325N/A len = bufsize - tokenBegin + bufpos + 1 + inBuf;
325N/A }
325N/A
325N/A int i = 0, j = 0, k = 0;
325N/A int nextColDiff = 0, columnDiff = 0;
325N/A
325N/A while (i < len && bufline[j = start % bufsize] == bufline[k = ++start % bufsize])
325N/A {
325N/A bufline[j] = newLine;
325N/A nextColDiff = columnDiff + bufcolumn[k] - bufcolumn[j];
325N/A bufcolumn[j] = newCol + columnDiff;
325N/A columnDiff = nextColDiff;
325N/A i++;
325N/A }
325N/A
325N/A if (i < len)
325N/A {
325N/A bufline[j] = newLine++;
325N/A bufcolumn[j] = newCol + columnDiff;
325N/A
325N/A while (i++ < len)
325N/A {
325N/A if (bufline[j = start % bufsize] != bufline[++start % bufsize])
325N/A bufline[j] = newLine++;
325N/A else
325N/A bufline[j] = newLine;
325N/A }
325N/A }
325N/A
325N/A line = bufline[j];
325N/A column = bufcolumn[j];
325N/A }
325N/A
325N/A}
325N/A/* JavaCC - OriginalChecksum=d4510307ecc248a96e4d3455ebf92ff3 (do not edit this line) */