diff --git a/udunits/build.gradle b/udunits/build.gradle index 2ce87646f2..2a38b721a5 100644 --- a/udunits/build.gradle +++ b/udunits/build.gradle @@ -1,3 +1,7 @@ +plugins { + id "org.javacc.javacc" version "4.0.1" +} + description = 'The ucar.units Java package is for decoding and encoding formatted unit specifications ' + '(e.g. "m/s"), converting numeric values between compatible units (e.g. between "m/s" ' + 'and "knot"), and for performing arithmetic operations on units (e.g. dividing one unit ' + diff --git a/udunits/src/main/java/ucar/units/ASCII_CharStream.java b/udunits/src/main/java/ucar/units/ASCII_CharStream.java deleted file mode 100644 index 0905ac32ad..0000000000 --- a/udunits/src/main/java/ucar/units/ASCII_CharStream.java +++ /dev/null @@ -1,323 +0,0 @@ -/* - * Copyright (c) 1998-2018 University Corporation for Atmospheric Research/Unidata - * See LICENSE for license information. - */ -/* Generated By:JavaCC: Do not edit this line. ASCII_CharStream.java Version 0.7pre6 */ -package ucar.units; - -/** - * An implementation of interface CharStream, where the stream is assumed to - * contain only ASCII characters (without unicode processing). - */ - -public final class ASCII_CharStream { - int bufsize; - int available; - int tokenBegin; - public int bufpos = -1; - private int[] bufline; - private int[] bufcolumn; - - private int column; - private int line; - - private boolean prevCharIsCR = false; - private boolean prevCharIsLF = false; - - private java.io.Reader inputStream; - - private char[] buffer; - private int maxNextCharInd = 0; - private int inBuf = 0; - - private void ExpandBuff(boolean wrapAround) { - 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; - } - - private void FillBuff() throws java.io.IOException { - 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; - } catch (java.io.IOException e) { - --bufpos; - backup(0); - if (tokenBegin == -1) - tokenBegin = bufpos; - throw e; - } - } - - public final char BeginToken() throws java.io.IOException { - tokenBegin = -1; - char c = readChar(); - tokenBegin = bufpos; - - return c; - } - - private 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; - } - - bufline[bufpos] = line; - bufcolumn[bufpos] = column; - } - - public final char readChar() throws java.io.IOException { - if (inBuf > 0) { - --inBuf; - return (char) ((char) 0xff & buffer[(bufpos == bufsize - 1) ? (bufpos = 0) : ++bufpos]); - } - - if (++bufpos >= maxNextCharInd) - FillBuff(); - - char c = (char) ((char) 0xff & buffer[bufpos]); - - UpdateLineColumn(c); - return (c); - } - - /** - * @deprecated - * @see #getEndColumn - */ - - public final int getColumn() { - return bufcolumn[bufpos]; - } - - /** - * @deprecated - * @see #getEndLine - */ - - public final int getLine() { - return bufline[bufpos]; - } - - public final int getEndColumn() { - return bufcolumn[bufpos]; - } - - public final int getEndLine() { - return bufline[bufpos]; - } - - public final int getBeginColumn() { - return bufcolumn[tokenBegin]; - } - - public final int getBeginLine() { - return bufline[tokenBegin]; - } - - public final void backup(int amount) { - - inBuf += amount; - if ((bufpos -= amount) < 0) - bufpos += bufsize; - } - - public ASCII_CharStream(java.io.Reader dstream, int startline, int startcolumn, int buffersize) { - inputStream = dstream; - line = startline; - column = startcolumn - 1; - - available = bufsize = buffersize; - buffer = new char[buffersize]; - bufline = new int[buffersize]; - bufcolumn = new int[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 (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; - } - - 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 (bufpos >= tokenBegin) - return new String(buffer, tokenBegin, bufpos - tokenBegin + 1); - else - return new String(buffer, tokenBegin, bufsize - tokenBegin) + new String(buffer, 0, bufpos + 1); - } - - public final char[] GetSuffix(int len) { - 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; - } - - public void Done() { - buffer = null; - bufline = null; - bufcolumn = null; - } - - /** - * Method to adjust line and column numbers for the start of a token. - */ - public void adjustBeginLineColumn(int newLine, int newCol) { - 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; - int nextColDiff, 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]; - } - -} diff --git a/udunits/src/main/java/ucar/units/ParseException.java b/udunits/src/main/java/ucar/units/ParseException.java deleted file mode 100644 index 761f1549f1..0000000000 --- a/udunits/src/main/java/ucar/units/ParseException.java +++ /dev/null @@ -1,199 +0,0 @@ -/* - * Copyright (c) 1998-2018 University Corporation for Atmospheric Research/Unidata - * See LICENSE for license information. - */ - -/* Generated By:JavaCC: Do not edit this line. ParseException.java Version 4.1 */ -/* JavaCCOptions:KEEP_LINE_COL=null */ -package ucar.units; - -/** - * This exception is thrown when parse errors are encountered. - * You can explicitly create objects of this exception type by - * calling the method generateParseException in the generated - * parser. - * - * You can modify this class to customize your error reporting - * mechanisms so long as you retain the public fields. - */ -public class ParseException extends Exception { - - /** - * 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: - */ - 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; - } - - /** Constructor with message. */ - public ParseException(String message) { - super(message); - 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(); - } - StringBuilder expected = new StringBuilder(); - int maxSize = 0; - for (int[] expectedTokenSequence : expectedTokenSequences) { - if (maxSize < expectedTokenSequence.length) { - maxSize = expectedTokenSequence.length; - } - for (int anExpectedTokenSequence : expectedTokenSequence) { - expected.append(tokenImage[anExpectedTokenSequence]).append(' '); - } - if (expectedTokenSequence[expectedTokenSequence.length - 1] != 0) { - expected.append("..."); - } - expected.append(eol).append(" "); - } - - StringBuilder b = new StringBuilder("Encountered \""); - Token tok = currentToken.next; - for (int i = 0; i < maxSize; i++) { - if (i != 0) - b.append(" "); - if (tok.kind == 0) { - b.append(tokenImage[0]); - break; - } - b.append(" ").append(tokenImage[tok.kind]).append(" \""); - b.append(add_escapes(tok.image)); - b.append(" \""); - tok = tok.next; - } - b.append("\" at line ").append(currentToken.next.beginLine).append(", column ") - .append(currentToken.next.beginColumn); - b.append(".").append(eol); - if (expectedTokenSequences.length == 1) { - b.append("Was expecting:").append(eol).append(" "); - } else { - b.append("Was expecting one of:").append(eol).append(" "); - } - b.append(expected.toString()); - return b.toString(); - } - - /** - * 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) { - StringBuilder retval = new StringBuilder(); - 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").append(s.substring(s.length() - 4)); - } else { - retval.append(ch); - } - } - } - return retval.toString(); - } - -} -/* JavaCC - OriginalChecksum=c12c8e2ab928ca7687b02f2580b4469a (do not edit this line) */ diff --git a/udunits/src/main/java/ucar/units/SimpleCharStream.java b/udunits/src/main/java/ucar/units/SimpleCharStream.java deleted file mode 100644 index 7d61971665..0000000000 --- a/udunits/src/main/java/ucar/units/SimpleCharStream.java +++ /dev/null @@ -1,419 +0,0 @@ -/* - * Copyright (c) 1998-2018 University Corporation for Atmospheric Research/Unidata - * See LICENSE for license information. - */ - -/* Generated By:JavaCC: Do not edit this line. SimpleCharStream.java Version 4.1 */ -/* JavaCCOptions:STATIC=false */ -package ucar.units; - -import java.io.InputStreamReader; - -/** - * An implementation of interface CharStream, where the stream is assumed to - * contain only ASCII characters (without unicode processing). - */ - -public class SimpleCharStream { - /** Whether parser is static. */ - public static final boolean staticFlag = false; - int bufsize; - int available; - int tokenBegin; - /** Position in buffer. */ - public int bufpos = -1; - protected int[] bufline; - protected int[] bufcolumn; - - protected int column; - protected int line; - - protected boolean prevCharIsCR = false; - protected boolean prevCharIsLF = false; - - protected java.io.Reader inputStream; - - protected char[] buffer; - protected int maxNextCharInd = 0; - protected int inBuf = 0; - protected int tabSize = 8; - - protected void setTabSize(int i) { - tabSize = i; - } - - protected int getTabSize(int i) { - return tabSize; - } - - - protected void ExpandBuff(boolean wrapAround) { - 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; - } - - protected void FillBuff() throws java.io.IOException { - 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; - } catch (java.io.IOException e) { - --bufpos; - backup(0); - if (tokenBegin == -1) - tokenBegin = bufpos; - throw e; - } - } - - /** Start. */ - public char BeginToken() throws java.io.IOException { - tokenBegin = -1; - char c = readChar(); - tokenBegin = bufpos; - - return c; - } - - protected 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 += (tabSize - (column % tabSize)); - break; - default: - break; - } - - bufline[bufpos] = line; - bufcolumn[bufpos] = column; - } - - /** Read a character. */ - public char readChar() throws java.io.IOException { - if (inBuf > 0) { - --inBuf; - - if (++bufpos == bufsize) - bufpos = 0; - - return buffer[bufpos]; - } - - if (++bufpos >= maxNextCharInd) - FillBuff(); - - char c = buffer[bufpos]; - - UpdateLineColumn(c); - return c; - } - - /** - * @deprecated - * @see #getEndColumn - */ - - public int getColumn() { - return bufcolumn[bufpos]; - } - - /** - * @deprecated - * @see #getEndLine - */ - - public int getLine() { - return bufline[bufpos]; - } - - /** Get token end column number. */ - public int getEndColumn() { - return bufcolumn[bufpos]; - } - - /** Get token end line number. */ - public int getEndLine() { - return bufline[bufpos]; - } - - /** Get token beginning column number. */ - public int getBeginColumn() { - return bufcolumn[tokenBegin]; - } - - /** Get token beginning line number. */ - public int getBeginLine() { - return bufline[tokenBegin]; - } - - /** Backup a number of characters. */ - public void backup(int amount) { - - inBuf += amount; - if ((bufpos -= amount) < 0) - bufpos += bufsize; - } - - /** Constructor. */ - public SimpleCharStream(java.io.Reader dstream, int startline, int startcolumn, int buffersize) { - inputStream = dstream; - line = startline; - column = startcolumn - 1; - - available = bufsize = buffersize; - buffer = new char[buffersize]; - bufline = new int[buffersize]; - bufcolumn = new int[buffersize]; - } - - /** Constructor. */ - public SimpleCharStream(java.io.Reader dstream, int startline, int startcolumn) { - this(dstream, startline, startcolumn, 4096); - } - - /** Constructor. */ - public SimpleCharStream(java.io.Reader dstream) { - this(dstream, 1, 1, 4096); - } - - /** Reinitialise. */ - public void ReInit(java.io.Reader dstream, int startline, int startcolumn, int buffersize) { - 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; - } - - /** Reinitialise. */ - public void ReInit(java.io.Reader dstream, int startline, int startcolumn) { - ReInit(dstream, startline, startcolumn, 4096); - } - - /** Reinitialise. */ - public void ReInit(java.io.Reader dstream) { - ReInit(dstream, 1, 1, 4096); - } - - /** Constructor. */ - public SimpleCharStream(java.io.InputStream dstream, String encoding, int startline, int startcolumn, int buffersize) - throws java.io.UnsupportedEncodingException { - this(encoding == null ? new InputStreamReader(dstream) : new InputStreamReader(dstream, encoding), startline, - startcolumn, buffersize); - } - - /** Constructor. */ - public SimpleCharStream(java.io.InputStream dstream, int startline, int startcolumn, int buffersize) { - this(new InputStreamReader(dstream), startline, startcolumn, buffersize); - } - - /** Constructor. */ - public SimpleCharStream(java.io.InputStream dstream, String encoding, int startline, int startcolumn) - throws java.io.UnsupportedEncodingException { - this(dstream, encoding, startline, startcolumn, 4096); - } - - /** Constructor. */ - public SimpleCharStream(java.io.InputStream dstream, int startline, int startcolumn) { - this(dstream, startline, startcolumn, 4096); - } - - /** Constructor. */ - public SimpleCharStream(java.io.InputStream dstream, String encoding) throws java.io.UnsupportedEncodingException { - this(dstream, encoding, 1, 1, 4096); - } - - /** Constructor. */ - public SimpleCharStream(java.io.InputStream dstream) { - this(dstream, 1, 1, 4096); - } - - /** Reinitialise. */ - public void ReInit(java.io.InputStream dstream, String encoding, int startline, int startcolumn, int buffersize) - throws java.io.UnsupportedEncodingException { - ReInit(encoding == null ? new InputStreamReader(dstream) : new InputStreamReader(dstream, encoding), startline, - startcolumn, buffersize); - } - - /** Reinitialise. */ - public void ReInit(java.io.InputStream dstream, int startline, int startcolumn, int buffersize) { - ReInit(new InputStreamReader(dstream), startline, startcolumn, buffersize); - } - - /** Reinitialise. */ - public void ReInit(java.io.InputStream dstream, String encoding) throws java.io.UnsupportedEncodingException { - ReInit(dstream, encoding, 1, 1, 4096); - } - - /** Reinitialise. */ - public void ReInit(java.io.InputStream dstream) { - ReInit(dstream, 1, 1, 4096); - } - - /** Reinitialise. */ - public void ReInit(java.io.InputStream dstream, String encoding, int startline, int startcolumn) - throws java.io.UnsupportedEncodingException { - ReInit(dstream, encoding, startline, startcolumn, 4096); - } - - /** Reinitialise. */ - public void ReInit(java.io.InputStream dstream, int startline, int startcolumn) { - ReInit(dstream, startline, startcolumn, 4096); - } - - /** Get token literal value. */ - public String GetImage() { - 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. */ - public char[] GetSuffix(int len) { - 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; - } - - /** Reset buffer when finished. */ - public void Done() { - buffer = null; - bufline = null; - bufcolumn = null; - } - - /** - * Method to adjust line and column numbers for the start of a token. - */ - public void adjustBeginLineColumn(int newLine, int newCol) { - 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; - int nextColDiff, 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]; - } - -} -/* JavaCC - OriginalChecksum=6d06d33fe604d39a71a89ee1da7d8e05 (do not edit this line) */ diff --git a/udunits/src/main/java/ucar/units/StandardUnitFormat.java b/udunits/src/main/java/ucar/units/StandardUnitFormat.java deleted file mode 100644 index 2d184d8d27..0000000000 --- a/udunits/src/main/java/ucar/units/StandardUnitFormat.java +++ /dev/null @@ -1,1895 +0,0 @@ -/* - * Copyright (c) 1998-2018 University Corporation for Atmospheric Research/Unidata - * See LICENSE for license information. - */ - -/* Generated By:JavaCC: Do not edit this line. StandardUnitFormat.java */ -package ucar.units; - -import java.io.StringReader; -import java.text.DateFormat; -import java.text.SimpleDateFormat; -import java.util.Arrays; -import java.util.Calendar; -import java.util.Comparator; -import java.util.Date; -import java.util.Locale; -import java.util.TimeZone; - -/** - * Standard formatter/parser for unit specifications. - *

- * Instances of this class are thread-compatible but not thread-safe. - * - * @author Steven R. Emmerson - */ -public final class StandardUnitFormat extends UnitFormatImpl implements StandardUnitFormatConstants { - private static final long serialVersionUID = 2L; - - /** - * The singleton instance of this class. - * - * @serial - */ - private static StandardUnitFormat _instance; - - /** - * The date formatter. - * - * @serial - */ - private static final SimpleDateFormat dateFormat; - - /** - * The Comparator for ordering base units for printing. Orders - * Factor-s by decreasing exponent (major) and lexically (minor). - * - * @serial - */ - private static final Comparator factorComparator = new Comparator() { - public int compare(Factor f1, Factor f2) { - int comp = f2.getExponent() - f1.getExponent(); - if (comp == 0) - comp = f1.getID().compareTo(f2.getID()); - return comp; - } - }; - - static { - dateFormat = (SimpleDateFormat) DateFormat.getDateInstance(DateFormat.SHORT, Locale.US); - dateFormat.setTimeZone(TimeZone.getTimeZone("UTC")); - dateFormat.applyPattern(" '@' yyyy-MM-dd HH:mm:ss.SSS 'UTC'"); - } - - /** - * Constructs from nothing. - */ - private StandardUnitFormat() { - this(new StringReader("")); - } - - - /** - * Returns an instance of this class. - * - * @return An instance of this class. - */ - public static synchronized StandardUnitFormat instance() { - if (_instance == null) - _instance = new StandardUnitFormat(); - return _instance; - } - - - /** - * Indicates if a unit is a time unit. - * - * @param unit The unit in question. - * @return {@code true} if and only if {@code unit} is a time unit. - * @Throws UnitSystemException if the unit system can't be initialized. - */ - private static boolean isTimeUnit(final Unit unit) throws UnitSystemException { - return unit.isCompatible(UnitSystemManager.instance().getBaseUnit(BaseQuantity.TIME)); - } - - - /** - * Decodes a unit specification. An unrecognized unit is made into - * an UnknownUnit. - * - * @param spec The unit specification to be decoded. - * @param unitDB The unit database to use. - * @return The unit corresponding to the specification. - * @throws UnitParseException The unit specification syntax is - * invalid. - * @throws SpecificationException Something's wrong with the - * specification. - * @throws UnitDBException Something's wrong with the unit - * database. - * @throws PrefixDBException Something's wrong with the unit prefix - * database. - * @throws UnitSystemException Something's wrong with the underlying - * system of units. - */ - public Unit parse(String spec, UnitDB unitDB) - throws UnitParseException, SpecificationException, UnitDBException, PrefixDBException, UnitSystemException { - if (spec == null) - throw new UnitParseException(spec); - - ReInit(new StringReader(spec.trim())); - - try { - Unit unit = unitSpec(unitDB); - return unit; - } catch (TokenMgrError e) { - throw new UnitParseException(spec, e); - } catch (ParseException e) { - throw new UnitParseException(spec, e); - } catch (OperationException e) { - throw new SpecificationException(spec, e); - } - } - - - /** - * Formats a Factor. - * - * @param factor The factor to be formatted. - * @param buf The buffer to append to. - * @return The appended-to buffer. - */ - public StringBuffer format(Factor factor, StringBuffer buf) { - return buf.append(factor.toString()); - } - - - /** - * Formats a unit. The symbol or name will be used if available; - * otherwise, a specification in terms of underlying units will be - * returned. - * - * @param unit The unit to be formatted. - * @param buf The buffer to append to. - * @return The appended-to buffer. - * @throws UnitClassException The class of the unit is unknown. - */ - public StringBuffer format(Unit unit, StringBuffer buf) throws UnitClassException { - return format(unit, buf, true); - } - - - /** - * Formats a unit in the underlying system of units. - * - * @param unit The unit to be formatted. - * @param buf The buffer to append to. - * @return The appended-to buffer. - * @throws UnitClassException The class of the unit is unknown. - */ - public StringBuffer longFormat(Unit unit, StringBuffer buf) throws UnitClassException { - return format(unit, buf, false); - } - - - /** - * Formats a unit. - * - * @param unit The unit to be formatted. - * @param buf The buffer to append to. - * @param normalize Whether or not to reduce the unit. - * @return The appended-to buffer. - * @throws UnitClassException The class of the unit is unknown. - */ - private StringBuffer format(Unit unit, StringBuffer buf, boolean normalize) throws UnitClassException { - boolean done = false; - if (!normalize) { - String id = unit.getSymbol(); - if (id == null) - id = unit.getName(); - if (id != null) { - buf.append(id.replace(' ', '_')); - done = true; - } - } - if (!done) { - if (unit instanceof BaseUnit) - format((BaseUnit) unit, buf); - else if (unit instanceof DerivedUnit) - format((DerivedUnit) unit, buf); - else if (unit instanceof ScaledUnit) - format((ScaledUnit) unit, buf, normalize); - else if (unit instanceof OffsetUnit) - format((OffsetUnit) unit, buf, normalize); - else if (unit instanceof TimeScaleUnit) - format((TimeScaleUnit) unit, buf, normalize); - else - throw new UnitClassException(unit); - } - return buf; - } - - - private StringBuffer format(BaseUnit baseUnit, StringBuffer buf) { - return buf.append(baseUnit.getSymbol()); - } - - - private StringBuffer format(DerivedUnit unit, StringBuffer buf) { - Factor[] factors = unit.getDimension().getFactors(); - Arrays.sort(factors, factorComparator); - for (int i = 0; i < factors.length; i++) - format(factors[i], buf).append('.'); - if (factors.length != 0) - buf.setLength(buf.length() - 1); - return buf; - } - - - private StringBuffer format(ScaledUnit unit, StringBuffer buf, boolean normalize) throws UnitClassException { - double scale = unit.getScale(); - if (scale != 0.0) { - if (scale == 1) { - format(unit.getUnit(), buf, normalize); - } else { - buf.append(scale).append(' '); - int start = buf.length(); - format(unit.getUnit(), buf, normalize); - if (start == buf.length()) - buf.setLength(start - 1); - } - } - return buf; - } - - - private StringBuffer format(OffsetUnit unit, StringBuffer buf, boolean normalize) throws UnitClassException { - double offset = unit.getOffset(); - if (offset == 0.0) { - format(unit.getUnit(), buf, normalize); - } else { - int start = buf.length(); - format(unit.getUnit(), buf, normalize); - return (isBlackSpace(buf, start) ? buf : buf.insert(start, '(').append(')')).append(" @ ").append(offset); - } - return buf; - } - - - private static boolean isBlackSpace(StringBuffer buf, int start) { - return buf.substring(start).indexOf(' ') == -1; - } - - - private StringBuffer format(TimeScaleUnit unit, StringBuffer buf, boolean normalize) throws UnitClassException { - return format(unit.getUnit(), buf, normalize).append(dateFormat.format(unit.getOrigin())); - } - - - /** - * Gets a unit from a unit database. - */ - private static Unit getUnit(UnitDB unitDB, String string) throws UnitDBAccessException { - return unitDB.get(string); - } - - - /** - * Gets a prefix from the prefix database. - */ - private static Prefix getPrefix(String string) throws PrefixDBException { - PrefixDB prefixDB = PrefixDBManager.instance(); - Prefix prefix = prefixDB.getPrefixByName(string); - if (prefix == null) - prefix = prefixDB.getPrefixBySymbol(string); - return prefix; - } - - public final Unit unitSpec(UnitDB unitDB) - throws ParseException, OperationException, UnitSystemException, PrefixDBException, UnitDBException { - Unit unit = DerivedUnitImpl.DIMENSIONLESS; - switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) { - case PLUS: - case MINUS: - case UINT: - case LPAREN: - case PERIOD: - case SYMBOL: - case T: - case NAME: - case LB: - case LN: - case LG: - unit = shiftExpr(unitDB); - break; - default: - jj_la1[0] = jj_gen;; - } - jj_consume_token(0); - { - if (true) - return unit; - } - throw new Error("Missing return statement in function"); - } - - public final Unit shiftExpr(UnitDB unitDB) - throws ParseException, OperationException, UnitSystemException, PrefixDBException, UnitDBException { - Unit unit; - Date timestamp; - double origin; - unit = productExpr(unitDB); - switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) { - case SHIFT: - jj_consume_token(SHIFT); - if (isTimeUnit(unit)) { - timestamp = timeOriginExpr(); - unit = unit.shiftTo(timestamp); - } else { - switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) { - case PLUS: - case MINUS: - case UINT: - case PERIOD: - origin = number(); - unit = unit.shiftTo(origin); - break; - default: - jj_la1[1] = jj_gen; - jj_consume_token(-1); - throw new ParseException(); - } - } - break; - default: - jj_la1[2] = jj_gen;; - } - { - if (true) - return unit; - } - throw new Error("Missing return statement in function"); - } - - public final Unit productExpr(UnitDB unitDB) - throws ParseException, OperationException, UnitSystemException, PrefixDBException, UnitDBException { - Unit unit; - Unit unit2; - unit = powerExpr(unitDB); - label_1: while (true) { - switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) { - case SP: - case PLUS: - case MINUS: - case UINT: - case LPAREN: - case PERIOD: - case STAR: - case DIVIDE: - case SYMBOL: - case T: - case NAME: - case LB: - case LN: - case LG:; - break; - default: - jj_la1[3] = jj_gen; - break label_1; - } - switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) { - case DIVIDE: - jj_consume_token(DIVIDE); - unit2 = powerExpr(unitDB); - unit = unit.divideBy(unit2); - break; - default: - jj_la1[6] = jj_gen; - if (jj_2_1(2)) { - switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) { - case SP: - case PERIOD: - case STAR: - switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) { - case PERIOD: - jj_consume_token(PERIOD); - break; - case STAR: - jj_consume_token(STAR); - break; - case SP: - jj_consume_token(SP); - break; - default: - jj_la1[4] = jj_gen; - jj_consume_token(-1); - throw new ParseException(); - } - break; - default: - jj_la1[5] = jj_gen;; - } - unit2 = powerExpr(unitDB); - unit = unit.multiplyBy(unit2); - } else { - jj_consume_token(-1); - throw new ParseException(); - } - } - } - { - if (true) - return unit; - } - throw new Error("Missing return statement in function"); - } - - public final Unit powerExpr(UnitDB unitDB) - throws ParseException, OperationException, UnitSystemException, PrefixDBException, UnitDBException { - Unit unit; - int exponent; - unit = basicExpr(unitDB); - switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) { - case PLUS: - case MINUS: - case UINT: - case RAISE: - switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) { - case RAISE: - jj_consume_token(RAISE); - break; - default: - jj_la1[7] = jj_gen;; - } - exponent = integer(); - unit = unit.raiseTo(exponent); - break; - default: - jj_la1[8] = jj_gen;; - } - { - if (true) - return unit; - } - throw new Error("Missing return statement in function"); - } - - public final Unit basicExpr(UnitDB unitDB) - throws ParseException, OperationException, UnitSystemException, PrefixDBException, UnitDBException { - Unit unit; - double number; - switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) { - case PLUS: - case MINUS: - case UINT: - case PERIOD: - number = number(); - unit = DerivedUnitImpl.DIMENSIONLESS.multiplyBy(number); - break; - case SYMBOL: - case T: - case NAME: - unit = unitIdentifier(unitDB); - break; - case LB: - case LN: - case LG: - unit = logExpr(unitDB); - break; - case LPAREN: - jj_consume_token(LPAREN); - switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) { - case SP: - jj_consume_token(SP); - break; - default: - jj_la1[9] = jj_gen;; - } - unit = shiftExpr(unitDB); - switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) { - case SP: - jj_consume_token(SP); - break; - default: - jj_la1[10] = jj_gen;; - } - jj_consume_token(RPAREN); - break; - default: - jj_la1[11] = jj_gen; - jj_consume_token(-1); - throw new ParseException(); - } - { - if (true) - return unit; - } - throw new Error("Missing return statement in function"); - } - - public final Unit logExpr(UnitDB unitDB) - throws ParseException, OperationException, UnitSystemException, PrefixDBException, UnitDBException { - double base; - Unit ref; - switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) { - case LB: - jj_consume_token(LB); - base = 2; - break; - case LN: - jj_consume_token(LN); - base = Math.E; - break; - case LG: - jj_consume_token(LG); - base = 10; - break; - default: - jj_la1[12] = jj_gen; - jj_consume_token(-1); - throw new ParseException(); - } - ref = productExpr(unitDB); - switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) { - case SP: - jj_consume_token(SP); - break; - default: - jj_la1[13] = jj_gen;; - } - jj_consume_token(RPAREN); - { - if (true) - return ref.log(base); - } - throw new Error("Missing return statement in function"); - } - - public final double number() throws ParseException { - double number; - if (jj_2_2(2147483647)) { - number = real(); - } else { - switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) { - case PLUS: - case MINUS: - case UINT: - number = integer(); - break; - default: - jj_la1[14] = jj_gen; - jj_consume_token(-1); - throw new ParseException(); - } - } - { - if (true) - return number; - } - throw new Error("Missing return statement in function"); - } - - public final double real() throws ParseException { - int sign = 1; - double tenFactor = 1; - double udecimal; - switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) { - case PLUS: - case MINUS: - sign = sign(); - break; - default: - jj_la1[15] = jj_gen;; - } - if (jj_2_3(2)) { - udecimal = unsignedDecimal(); - switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) { - case REAL_EXP: - tenFactor = tenFactor(); - break; - default: - jj_la1[16] = jj_gen;; - } - } else { - switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) { - case UINT: - udecimal = unsignedInteger(); - tenFactor = tenFactor(); - break; - default: - jj_la1[17] = jj_gen; - jj_consume_token(-1); - throw new ParseException(); - } - } - { - if (true) - return sign * udecimal * tenFactor; - } - throw new Error("Missing return statement in function"); - } - - public final int sign() throws ParseException { - switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) { - case PLUS: - jj_consume_token(PLUS); { - if (true) - return 1; - } - break; - case MINUS: - jj_consume_token(MINUS); { - if (true) - return -1; - } - break; - default: - jj_la1[18] = jj_gen; - jj_consume_token(-1); - throw new ParseException(); - } - throw new Error("Missing return statement in function"); - } - - public final double unsignedDecimal() throws ParseException { - int integer = 0; - Token token; - double fraction = 0; - if (jj_2_4(3)) { - switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) { - case UINT: - integer = unsignedInteger(); - break; - default: - jj_la1[19] = jj_gen;; - } - jj_consume_token(PERIOD); - token = jj_consume_token(UINT); - fraction = Double.valueOf("." + token.image); - } else { - switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) { - case UINT: - integer = unsignedInteger(); - jj_consume_token(PERIOD); - break; - default: - jj_la1[20] = jj_gen; - jj_consume_token(-1); - throw new ParseException(); - } - } - { - if (true) - return integer + fraction; - } - throw new Error("Missing return statement in function"); - } - - public final double tenFactor() throws ParseException { - Token token; - token = jj_consume_token(REAL_EXP); - { - if (true) - return Double.valueOf("1" + token.image); - } - throw new Error("Missing return statement in function"); - } - - public final int integer() throws ParseException { - int magnitude; - int sign = 1; - switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) { - case PLUS: - case MINUS: - sign = sign(); - break; - default: - jj_la1[21] = jj_gen;; - } - magnitude = unsignedInteger(); - { - if (true) - return sign * magnitude; - } - throw new Error("Missing return statement in function"); - } - - public final int unsignedInteger() throws ParseException { - Token token; - token = jj_consume_token(UINT); - { - if (true) - return Integer.valueOf(token.image); - } - throw new Error("Missing return statement in function"); - } - - public final Unit unitIdentifier(UnitDB unitDB) - throws ParseException, UnitDBException, UnitSystemException, PrefixDBException, OperationException { - Token token; - Unit unit; - switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) { - case T: - token = jj_consume_token(T); - break; - case NAME: - token = jj_consume_token(NAME); - break; - case SYMBOL: - token = jj_consume_token(SYMBOL); - break; - default: - jj_la1[22] = jj_gen; - jj_consume_token(-1); - throw new ParseException(); - } - String string = token.image; - double scale = 1; - - for (unit = getUnit(unitDB, string); unit == null; unit = getUnit(unitDB, string)) { - Prefix prefix = getPrefix(string); - if (prefix == null) { - try { - // System.err.println("Unknown unit: \"" + string + '"'); - unit = UnknownUnit.create(string); - break; - } catch (NameException e) { - } // shouldn't happen - } - scale *= prefix.getValue(); - string = string.substring(prefix.length()); - } - unit = unit.multiplyBy(scale); - { - if (true) - return unit; - } - throw new Error("Missing return statement in function"); - } - - /* - * See for a discussion of the - * relevant timestamp format or lookup "ISO 8601". - */ - public final Date timeOriginExpr() throws ParseException { - Calendar calendar; - calendar = dateExpr(); - if (jj_2_6(2)) { - switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) { - case T: - jj_consume_token(T); - break; - case SP: - jj_consume_token(SP); - break; - default: - jj_la1[23] = jj_gen; - jj_consume_token(-1); - throw new ParseException(); - } - clockExpr(calendar); - if (jj_2_5(2)) { - switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) { - case SP: - jj_consume_token(SP); - break; - default: - jj_la1[24] = jj_gen;; - } - zoneExpr(calendar); - } else { - ; - } - } else { - ; - } - { - if (true) - return calendar.getTime(); - } - throw new Error("Missing return statement in function"); - } - - public final Calendar dateExpr() throws ParseException { - int sign = 1; - int year; - int month = 1; - int day = 1; - boolean packed = true; - switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) { - case PLUS: - case MINUS: - sign = sign(); - break; - default: - jj_la1[25] = jj_gen;; - } - year = unsignedInteger(); - switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) { - case MINUS: - jj_consume_token(MINUS); - month = unsignedInteger(); - packed = false; - switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) { - case MINUS: - jj_consume_token(MINUS); - day = unsignedInteger(); - break; - default: - jj_la1[26] = jj_gen;; - } - break; - default: - jj_la1[27] = jj_gen;; - } - if (packed) { - if (year >= 10000101) { - day = year % 100; - year /= 100; - } - if (year >= 100001) { - month = year % 100; - year /= 100; - } - if (sign < 0) - year = -year; - } - if (month < 1 || month > 12) { - if (true) - throw new ParseException("invalid month in timestamp"); - } - if (day < 1 || day > 31) { - if (true) - throw new ParseException("invalid day in timestamp"); - } - Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("UTC")); - calendar.clear(); - calendar.set(year, month - 1, day); - { - if (true) - return calendar; - } - throw new Error("Missing return statement in function"); - } - - public final Calendar clockExpr(Calendar calendar) throws ParseException { - double hour; - int minute = 0; - double seconds = 0; - boolean packed = true; - if (jj_2_7(2147483647)) { - hour = unsignedDecimal(); - } else { - switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) { - case UINT: - hour = unsignedInteger(); - break; - default: - jj_la1[28] = jj_gen; - jj_consume_token(-1); - throw new ParseException(); - } - } - switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) { - case COLON: - jj_consume_token(COLON); - minute = unsignedInteger(); - packed = false; - switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) { - case COLON: - jj_consume_token(COLON); - if (jj_2_8(2147483647)) { - seconds = unsignedDecimal(); - } else { - switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) { - case UINT: - seconds = unsignedInteger(); - break; - default: - jj_la1[29] = jj_gen; - jj_consume_token(-1); - throw new ParseException(); - } - } - break; - default: - jj_la1[30] = jj_gen;; - } - break; - default: - jj_la1[31] = jj_gen;; - } - if (packed) { - if (hour >= 100000) { - seconds = hour % 100; - hour /= 100; - } - if (hour >= 1000) { - minute = (int) (hour % 100); - hour /= 100; - } - } - if (hour < 0 || hour > 23) { - if (true) - throw new ParseException("invalid hour in timestamp"); - } - if (minute < 0 || minute > 59) { - if (true) - throw new ParseException("invalid minute in timestamp"); - } - if (seconds < 0 || seconds > 61) { - if (true) - throw new ParseException("invalid seconds in timestamp"); - } - calendar.set(Calendar.HOUR_OF_DAY, (int) Math.round(hour)); - calendar.set(Calendar.MINUTE, minute); - int s = (int) seconds; - calendar.set(Calendar.SECOND, s); - int ms = (int) ((seconds - s) * 1000); - calendar.set(Calendar.MILLISECOND, ms); - { - if (true) - return calendar; - } - throw new Error("Missing return statement in function"); - } - - public final Calendar zoneExpr(Calendar calendar) throws ParseException { - int sign = 1; - int zoneHour; - int zoneMinute = 0; - Token token; - TimeZone timeZone; - switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) { - case PLUS: - case MINUS: - case UINT: - switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) { - case PLUS: - case MINUS: - sign = sign(); - break; - default: - jj_la1[32] = jj_gen;; - } - zoneHour = unsignedInteger(); - switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) { - case COLON: - case UINT: - switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) { - case COLON: - jj_consume_token(COLON); - break; - default: - jj_la1[33] = jj_gen;; - } - zoneMinute = unsignedInteger(); - break; - default: - jj_la1[34] = jj_gen;; - } - if (zoneHour >= 100) { - zoneMinute += zoneHour % 100; - zoneHour /= 100; - } - if (zoneHour > 23 || zoneMinute > 59) { - { - if (true) - throw new ParseException("invalid time-zone in timestamp"); - } - } - timeZone = TimeZone.getTimeZone("UTC"); - timeZone.setRawOffset(sign * (zoneHour * 60 + zoneMinute) * 60 * 1000); - break; - case NAME: - token = jj_consume_token(NAME); - timeZone = TimeZone.getTimeZone(token.image); - break; - default: - jj_la1[35] = jj_gen; - jj_consume_token(-1); - throw new ParseException(); - } - calendar.setTimeZone(timeZone); - { - if (true) - return calendar; - } - throw new Error("Missing return statement in function"); - } - - private boolean jj_2_1(int xla) { - jj_la = xla; - jj_lastpos = jj_scanpos = token; - try { - return !jj_3_1(); - } catch (LookaheadSuccess ls) { - return true; - } finally { - jj_save(0, xla); - } - } - - private boolean jj_2_2(int xla) { - jj_la = xla; - jj_lastpos = jj_scanpos = token; - try { - return !jj_3_2(); - } catch (LookaheadSuccess ls) { - return true; - } finally { - jj_save(1, xla); - } - } - - private boolean jj_2_3(int xla) { - jj_la = xla; - jj_lastpos = jj_scanpos = token; - try { - return !jj_3_3(); - } catch (LookaheadSuccess ls) { - return true; - } finally { - jj_save(2, xla); - } - } - - private boolean jj_2_4(int xla) { - jj_la = xla; - jj_lastpos = jj_scanpos = token; - try { - return !jj_3_4(); - } catch (LookaheadSuccess ls) { - return true; - } finally { - jj_save(3, xla); - } - } - - private boolean jj_2_5(int xla) { - jj_la = xla; - jj_lastpos = jj_scanpos = token; - try { - return !jj_3_5(); - } catch (LookaheadSuccess ls) { - return true; - } finally { - jj_save(4, xla); - } - } - - private boolean jj_2_6(int xla) { - jj_la = xla; - jj_lastpos = jj_scanpos = token; - try { - return !jj_3_6(); - } catch (LookaheadSuccess ls) { - return true; - } finally { - jj_save(5, xla); - } - } - - private boolean jj_2_7(int xla) { - jj_la = xla; - jj_lastpos = jj_scanpos = token; - try { - return !jj_3_7(); - } catch (LookaheadSuccess ls) { - return true; - } finally { - jj_save(6, xla); - } - } - - private boolean jj_2_8(int xla) { - jj_la = xla; - jj_lastpos = jj_scanpos = token; - try { - return !jj_3_8(); - } catch (LookaheadSuccess ls) { - return true; - } finally { - jj_save(7, xla); - } - } - - private boolean jj_3R_40() { - if (jj_scan_token(LG)) - return true; - return false; - } - - private boolean jj_3R_33() { - if (jj_3R_24()) - return true; - return false; - } - - private boolean jj_3R_39() { - if (jj_scan_token(LN)) - return true; - return false; - } - - private boolean jj_3R_41() { - if (jj_3R_3()) - return true; - return false; - } - - private boolean jj_3R_23() { - Token xsp; - xsp = jj_scanpos; - if (jj_3R_33()) - jj_scanpos = xsp; - if (jj_3R_14()) - return true; - return false; - } - - private boolean jj_3R_38() { - if (jj_scan_token(LB)) - return true; - return false; - } - - private boolean jj_3_8() { - if (jj_3R_5()) - return true; - return false; - } - - private boolean jj_3_5() { - Token xsp; - xsp = jj_scanpos; - if (jj_scan_token(1)) - jj_scanpos = xsp; - if (jj_3R_7()) - return true; - return false; - } - - private boolean jj_3R_31() { - Token xsp; - xsp = jj_scanpos; - if (jj_3R_38()) { - jj_scanpos = xsp; - if (jj_3R_39()) { - jj_scanpos = xsp; - if (jj_3R_40()) - return true; - } - } - if (jj_3R_41()) - return true; - return false; - } - - private boolean jj_3R_26() { - if (jj_scan_token(REAL_EXP)) - return true; - return false; - } - - private boolean jj_3_6() { - Token xsp; - xsp = jj_scanpos; - if (jj_scan_token(17)) { - jj_scanpos = xsp; - if (jj_scan_token(1)) - return true; - } - if (jj_3R_8()) - return true; - return false; - } - - private boolean jj_3R_13() { - if (jj_3R_14()) - return true; - if (jj_scan_token(PERIOD)) - return true; - return false; - } - - private boolean jj_3R_22() { - if (jj_scan_token(LPAREN)) - return true; - Token xsp; - xsp = jj_scanpos; - if (jj_scan_token(1)) - jj_scanpos = xsp; - if (jj_3R_32()) - return true; - return false; - } - - private boolean jj_3R_21() { - if (jj_3R_31()) - return true; - return false; - } - - private boolean jj_3R_20() { - if (jj_3R_30()) - return true; - return false; - } - - private boolean jj_3R_6() { - if (jj_3R_14()) - return true; - return false; - } - - private boolean jj_3_7() { - if (jj_3R_5()) - return true; - return false; - } - - private boolean jj_3_4() { - Token xsp; - xsp = jj_scanpos; - if (jj_3R_6()) - jj_scanpos = xsp; - if (jj_scan_token(PERIOD)) - return true; - if (jj_scan_token(UINT)) - return true; - return false; - } - - private boolean jj_3R_19() { - if (jj_3R_29()) - return true; - return false; - } - - private boolean jj_3R_18() { - if (jj_3R_14()) - return true; - return false; - } - - private boolean jj_3R_32() { - if (jj_3R_41()) - return true; - return false; - } - - private boolean jj_3R_17() { - if (jj_3R_5()) - return true; - return false; - } - - private boolean jj_3R_5() { - Token xsp; - xsp = jj_scanpos; - if (jj_3_4()) { - jj_scanpos = xsp; - if (jj_3R_13()) - return true; - } - return false; - } - - private boolean jj_3R_9() { - Token xsp; - xsp = jj_scanpos; - if (jj_3R_19()) { - jj_scanpos = xsp; - if (jj_3R_20()) { - jj_scanpos = xsp; - if (jj_3R_21()) { - jj_scanpos = xsp; - if (jj_3R_22()) - return true; - } - } - } - return false; - } - - private boolean jj_3R_35() { - if (jj_scan_token(MINUS)) - return true; - return false; - } - - private boolean jj_3R_8() { - Token xsp; - xsp = jj_scanpos; - if (jj_3R_17()) { - jj_scanpos = xsp; - if (jj_3R_18()) - return true; - } - return false; - } - - private boolean jj_3R_34() { - if (jj_scan_token(PLUS)) - return true; - return false; - } - - private boolean jj_3R_24() { - Token xsp; - xsp = jj_scanpos; - if (jj_3R_34()) { - jj_scanpos = xsp; - if (jj_3R_35()) - return true; - } - return false; - } - - private boolean jj_3R_12() { - if (jj_3R_14()) - return true; - if (jj_3R_26()) - return true; - return false; - } - - private boolean jj_3R_25() { - if (jj_3R_26()) - return true; - return false; - } - - private boolean jj_3R_16() { - if (jj_scan_token(NAME)) - return true; - return false; - } - - private boolean jj_3R_10() { - Token xsp; - xsp = jj_scanpos; - if (jj_scan_token(11)) - jj_scanpos = xsp; - if (jj_3R_23()) - return true; - return false; - } - - private boolean jj_3_3() { - if (jj_3R_5()) - return true; - Token xsp; - xsp = jj_scanpos; - if (jj_3R_25()) - jj_scanpos = xsp; - return false; - } - - private boolean jj_3R_3() { - if (jj_3R_9()) - return true; - Token xsp; - xsp = jj_scanpos; - if (jj_3R_10()) - jj_scanpos = xsp; - return false; - } - - private boolean jj_3R_11() { - if (jj_3R_24()) - return true; - return false; - } - - private boolean jj_3R_4() { - Token xsp; - xsp = jj_scanpos; - if (jj_3R_11()) - jj_scanpos = xsp; - xsp = jj_scanpos; - if (jj_3_3()) { - jj_scanpos = xsp; - if (jj_3R_12()) - return true; - } - return false; - } - - private boolean jj_3_2() { - if (jj_3R_4()) - return true; - return false; - } - - private boolean jj_3R_30() { - Token xsp; - xsp = jj_scanpos; - if (jj_scan_token(17)) { - jj_scanpos = xsp; - if (jj_scan_token(18)) { - jj_scanpos = xsp; - if (jj_scan_token(16)) - return true; - } - } - return false; - } - - private boolean jj_3R_28() { - Token xsp; - xsp = jj_scanpos; - if (jj_scan_token(4)) - jj_scanpos = xsp; - if (jj_3R_14()) - return true; - return false; - } - - private boolean jj_3R_27() { - if (jj_3R_24()) - return true; - return false; - } - - private boolean jj_3R_15() { - Token xsp; - xsp = jj_scanpos; - if (jj_3R_27()) - jj_scanpos = xsp; - if (jj_3R_14()) - return true; - xsp = jj_scanpos; - if (jj_3R_28()) - jj_scanpos = xsp; - return false; - } - - private boolean jj_3R_37() { - if (jj_3R_23()) - return true; - return false; - } - - private boolean jj_3R_2() { - Token xsp; - xsp = jj_scanpos; - if (jj_scan_token(12)) { - jj_scanpos = xsp; - if (jj_scan_token(13)) { - jj_scanpos = xsp; - if (jj_scan_token(1)) - return true; - } - } - return false; - } - - private boolean jj_3R_36() { - if (jj_3R_4()) - return true; - return false; - } - - private boolean jj_3_1() { - Token xsp; - xsp = jj_scanpos; - if (jj_3R_2()) - jj_scanpos = xsp; - if (jj_3R_3()) - return true; - return false; - } - - private boolean jj_3R_7() { - Token xsp; - xsp = jj_scanpos; - if (jj_3R_15()) { - jj_scanpos = xsp; - if (jj_3R_16()) - return true; - } - return false; - } - - private boolean jj_3R_14() { - if (jj_scan_token(UINT)) - return true; - return false; - } - - private boolean jj_3R_29() { - Token xsp; - xsp = jj_scanpos; - if (jj_3R_36()) { - jj_scanpos = xsp; - if (jj_3R_37()) - return true; - } - return false; - } - - /** - * Generated Token Manager. - */ - public StandardUnitFormatTokenManager token_source; - SimpleCharStream jj_input_stream; - /** - * Current token. - */ - public Token token; - /** - * Next token. - */ - public Token jj_nt; - private int jj_ntk; - private Token jj_scanpos, jj_lastpos; - private int jj_la; - private int jj_gen; - private final int[] jj_la1 = new int[36]; - private static int[] jj_la1_0; - - static { - jj_la1_init_0(); - } - - private static void jj_la1_init_0() { - jj_la1_0 = new int[] {0x3f112c, 0x102c, 0x8000, 0x3f712e, 0x3002, 0x3002, 0x4000, 0x800, 0x82c, 0x2, 0x2, 0x3f112c, - 0x380000, 0x2, 0x2c, 0xc, 0x400, 0x20, 0xc, 0x20, 0x20, 0xc, 0x70000, 0x20002, 0x2, 0xc, 0x8, 0x8, 0x20, 0x20, - 0x10, 0x10, 0xc, 0x10, 0x30, 0x4002c,}; - } - - private final JJCalls[] jj_2_rtns = new JJCalls[8]; - private boolean jj_rescan = false; - private int jj_gc = 0; - - /** - * Constructor with InputStream. - */ - public StandardUnitFormat(java.io.InputStream stream) { - this(stream, null); - } - - /** - * Constructor with InputStream and supplied encoding - */ - public StandardUnitFormat(java.io.InputStream stream, String encoding) { - try { - jj_input_stream = new SimpleCharStream(stream, encoding, 1, 1); - } catch (java.io.UnsupportedEncodingException e) { - throw new RuntimeException(e); - } - token_source = new StandardUnitFormatTokenManager(jj_input_stream); - token = new Token(); - jj_ntk = -1; - jj_gen = 0; - for (int i = 0; i < 36; i++) - jj_la1[i] = -1; - for (int i = 0; i < jj_2_rtns.length; i++) - jj_2_rtns[i] = new JJCalls(); - } - - /** - * Reinitialise. - */ - public void ReInit(java.io.InputStream stream) { - ReInit(stream, null); - } - - /** - * Reinitialise. - */ - public void ReInit(java.io.InputStream stream, String encoding) { - try { - jj_input_stream.ReInit(stream, encoding, 1, 1); - } catch (java.io.UnsupportedEncodingException e) { - throw new RuntimeException(e); - } - token_source.ReInit(jj_input_stream); - token = new Token(); - jj_ntk = -1; - jj_gen = 0; - for (int i = 0; i < 36; i++) - jj_la1[i] = -1; - for (int i = 0; i < jj_2_rtns.length; i++) - jj_2_rtns[i] = new JJCalls(); - } - - /** - * Constructor. - */ - public StandardUnitFormat(java.io.Reader stream) { - jj_input_stream = new SimpleCharStream(stream, 1, 1); - token_source = new StandardUnitFormatTokenManager(jj_input_stream); - token = new Token(); - jj_ntk = -1; - jj_gen = 0; - for (int i = 0; i < 36; i++) - jj_la1[i] = -1; - for (int i = 0; i < jj_2_rtns.length; i++) - jj_2_rtns[i] = new JJCalls(); - } - - /** - * Reinitialise. - */ - public void ReInit(java.io.Reader stream) { - jj_input_stream.ReInit(stream, 1, 1); - token_source.ReInit(jj_input_stream); - token = new Token(); - jj_ntk = -1; - jj_gen = 0; - for (int i = 0; i < 36; i++) - jj_la1[i] = -1; - for (int i = 0; i < jj_2_rtns.length; i++) - jj_2_rtns[i] = new JJCalls(); - } - - /** - * Constructor with generated Token Manager. - */ - public StandardUnitFormat(StandardUnitFormatTokenManager tm) { - token_source = tm; - token = new Token(); - jj_ntk = -1; - jj_gen = 0; - for (int i = 0; i < 36; i++) - jj_la1[i] = -1; - for (int i = 0; i < jj_2_rtns.length; i++) - jj_2_rtns[i] = new JJCalls(); - } - - /** - * Reinitialise. - */ - public void ReInit(StandardUnitFormatTokenManager tm) { - token_source = tm; - token = new Token(); - jj_ntk = -1; - jj_gen = 0; - for (int i = 0; i < 36; i++) - jj_la1[i] = -1; - for (int i = 0; i < jj_2_rtns.length; i++) - jj_2_rtns[i] = new JJCalls(); - } - - private Token jj_consume_token(int kind) throws ParseException { - Token oldToken; - if ((oldToken = token).next != null) - token = token.next; - else - token = token.next = token_source.getNextToken(); - jj_ntk = -1; - if (token.kind == kind) { - jj_gen++; - if (++jj_gc > 100) { - jj_gc = 0; - for (int i = 0; i < jj_2_rtns.length; i++) { - JJCalls c = jj_2_rtns[i]; - while (c != null) { - if (c.gen < jj_gen) - c.first = null; - c = c.next; - } - } - } - return token; - } - token = oldToken; - jj_kind = kind; - throw generateParseException(); - } - - private static final class LookaheadSuccess extends java.lang.Error { - } - - private final LookaheadSuccess jj_ls = new LookaheadSuccess(); - - private boolean jj_scan_token(int kind) { - if (jj_scanpos == jj_lastpos) { - jj_la--; - if (jj_scanpos.next == null) { - jj_lastpos = jj_scanpos = jj_scanpos.next = token_source.getNextToken(); - } else { - jj_lastpos = jj_scanpos = jj_scanpos.next; - } - } else { - jj_scanpos = jj_scanpos.next; - } - if (jj_rescan) { - int i = 0; - Token tok = token; - while (tok != null && tok != jj_scanpos) { - i++; - tok = tok.next; - } - if (tok != null) - jj_add_error_token(kind, i); - } - if (jj_scanpos.kind != kind) - return true; - if (jj_la == 0 && jj_scanpos == jj_lastpos) - throw jj_ls; - return false; - } - - - /** - * Get the next Token. - */ - public final Token getNextToken() { - if (token.next != null) - token = token.next; - else - token = token.next = token_source.getNextToken(); - jj_ntk = -1; - jj_gen++; - return token; - } - - /** - * Get the specific Token. - */ - public final Token getToken(int index) { - Token t = token; - for (int i = 0; i < index; i++) { - if (t.next != null) - t = t.next; - else - t = t.next = token_source.getNextToken(); - } - return t; - } - - private int jj_ntk() { - if ((jj_nt = token.next) == null) - return (jj_ntk = (token.next = token_source.getNextToken()).kind); - else - return (jj_ntk = jj_nt.kind); - } - - private java.util.List jj_expentries = new java.util.ArrayList(); - private int[] jj_expentry; - private int jj_kind = -1; - private int[] jj_lasttokens = new int[100]; - private int jj_endpos; - - private void jj_add_error_token(int kind, int pos) { - if (pos >= 100) - return; - if (pos == jj_endpos + 1) { - jj_lasttokens[jj_endpos++] = kind; - } else if (jj_endpos != 0) { - jj_expentry = new int[jj_endpos]; - for (int i = 0; i < jj_endpos; i++) { - jj_expentry[i] = jj_lasttokens[i]; - } - jj_entries_loop: for (java.util.Iterator it = jj_expentries.iterator(); it.hasNext();) { - int[] oldentry = (int[]) (it.next()); - if (oldentry.length == jj_expentry.length) { - for (int i = 0; i < jj_expentry.length; i++) { - if (oldentry[i] != jj_expentry[i]) { - continue jj_entries_loop; - } - } - jj_expentries.add(jj_expentry); - break jj_entries_loop; - } - } - if (pos != 0) - jj_lasttokens[(jj_endpos = pos) - 1] = kind; - } - } - - /** - * Generate ParseException. - */ - public ParseException generateParseException() { - jj_expentries.clear(); - boolean[] la1tokens = new boolean[22]; - if (jj_kind >= 0) { - la1tokens[jj_kind] = true; - jj_kind = -1; - } - for (int i = 0; i < 36; i++) { - if (jj_la1[i] == jj_gen) { - for (int j = 0; j < 32; j++) { - if ((jj_la1_0[i] & (1 << j)) != 0) { - la1tokens[j] = true; - } - } - } - } - for (int i = 0; i < 22; i++) { - if (la1tokens[i]) { - jj_expentry = new int[1]; - jj_expentry[0] = i; - jj_expentries.add(jj_expentry); - } - } - jj_endpos = 0; - jj_rescan_token(); - jj_add_error_token(0, 0); - int[][] exptokseq = new int[jj_expentries.size()][]; - for (int i = 0; i < jj_expentries.size(); i++) { - exptokseq[i] = jj_expentries.get(i); - } - return new ParseException(token, exptokseq, tokenImage); - } - - /** - * Enable tracing. - */ - public final void enable_tracing() {} - - /** - * Disable tracing. - */ - public final void disable_tracing() {} - - private void jj_rescan_token() { - jj_rescan = true; - for (int i = 0; i < 8; i++) { - try { - JJCalls p = jj_2_rtns[i]; - do { - if (p.gen > jj_gen) { - jj_la = p.arg; - jj_lastpos = jj_scanpos = p.first; - switch (i) { - case 0: - jj_3_1(); - break; - case 1: - jj_3_2(); - break; - case 2: - jj_3_3(); - break; - case 3: - jj_3_4(); - break; - case 4: - jj_3_5(); - break; - case 5: - jj_3_6(); - break; - case 6: - jj_3_7(); - break; - case 7: - jj_3_8(); - break; - } - } - p = p.next; - } while (p != null); - } catch (LookaheadSuccess ls) { - } - } - jj_rescan = false; - } - - private void jj_save(int index, int xla) { - JJCalls p = jj_2_rtns[index]; - while (p.gen > jj_gen) { - if (p.next == null) { - p = p.next = new JJCalls(); - break; - } - p = p.next; - } - p.gen = jj_gen + xla - jj_la; - p.first = token; - p.arg = xla; - } - - static final class JJCalls { - int gen; - Token first; - int arg; - JJCalls next; - } - -} diff --git a/udunits/src/main/java/ucar/units/StandardUnitFormatConstants.java b/udunits/src/main/java/ucar/units/StandardUnitFormatConstants.java deleted file mode 100644 index 55f9d103cc..0000000000 --- a/udunits/src/main/java/ucar/units/StandardUnitFormatConstants.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright (c) 1998-2018 University Corporation for Atmospheric Research/Unidata - * See LICENSE for license information. - */ - -/* Generated By:JavaCC: Do not edit this line. StandardUnitFormatConstants.java */ -package ucar.units; - - -/** - * Token literal values and constants. - * Generated by org.javacc.parser.OtherFilesGen#start() - */ -public interface StandardUnitFormatConstants { - - /** End of File. */ - int EOF = 0; - /** RegularExpression Id. */ - int SP = 1; - /** RegularExpression Id. */ - int PLUS = 2; - /** RegularExpression Id. */ - int MINUS = 3; - /** RegularExpression Id. */ - int COLON = 4; - /** RegularExpression Id. */ - int UINT = 5; - /** RegularExpression Id. */ - int SIGN = 6; - /** RegularExpression Id. */ - int LETTER = 7; - /** RegularExpression Id. */ - int LPAREN = 8; - /** RegularExpression Id. */ - int RPAREN = 9; - /** RegularExpression Id. */ - int REAL_EXP = 10; - /** RegularExpression Id. */ - int RAISE = 11; - /** RegularExpression Id. */ - int PERIOD = 12; - /** RegularExpression Id. */ - int STAR = 13; - /** RegularExpression Id. */ - int DIVIDE = 14; - /** RegularExpression Id. */ - int SHIFT = 15; - /** RegularExpression Id. */ - int SYMBOL = 16; - /** RegularExpression Id. */ - int T = 17; - /** RegularExpression Id. */ - int NAME = 18; - /** RegularExpression Id. */ - int LB = 19; - /** RegularExpression Id. */ - int LN = 20; - /** RegularExpression Id. */ - int LG = 21; - - /** Lexical state. */ - int DEFAULT = 0; - - /** Literal token values. */ - String[] tokenImage = - {"", "", "\"+\"", "\"-\"", "\":\"", "", "", "", "\"(\"", "\")\"", "", - "\"^\"", "\".\"", "\"*\"", "", "", "", "\"t\"", "", "", "", "",}; - -} diff --git a/udunits/src/main/java/ucar/units/StandardUnitFormatTokenManager.java b/udunits/src/main/java/ucar/units/StandardUnitFormatTokenManager.java deleted file mode 100644 index 8a3cfa79ed..0000000000 --- a/udunits/src/main/java/ucar/units/StandardUnitFormatTokenManager.java +++ /dev/null @@ -1,567 +0,0 @@ -/* - * Copyright (c) 1998-2018 University Corporation for Atmospheric Research/Unidata - * See LICENSE for license information. - */ - -/* Generated By:JavaCC: Do not edit this line. StandardUnitFormatTokenManager.java */ -package ucar.units; - -/** Token Manager. */ -public class StandardUnitFormatTokenManager implements StandardUnitFormatConstants { - - /** Debug output. */ - public java.io.PrintStream debugStream = System.out; - - /** Set debug output. */ - public void setDebugStream(java.io.PrintStream ds) { - debugStream = ds; - } - - private final int jjStopStringLiteralDfa_0(int pos, long active0) { - switch (pos) { - default: - return -1; - } - } - - private final int jjStartNfa_0(int pos, long active0) { - return jjMoveNfa_0(jjStopStringLiteralDfa_0(pos, active0), pos + 1); - } - - private int jjStopAtPos(int pos, int kind) { - jjmatchedKind = kind; - jjmatchedPos = pos; - return pos + 1; - } - - private int jjMoveStringLiteralDfa0_0() { - switch (curChar) { - case 40: - return jjStopAtPos(0, 8); - case 41: - return jjStopAtPos(0, 9); - case 42: - return jjStopAtPos(0, 13); - case 43: - return jjStopAtPos(0, 2); - case 45: - return jjStopAtPos(0, 3); - case 46: - return jjStopAtPos(0, 12); - case 58: - return jjStopAtPos(0, 4); - case 84: - return jjStartNfaWithStates_0(0, 17, 49); - case 94: - return jjStopAtPos(0, 11); - case 116: - return jjStartNfaWithStates_0(0, 17, 49); - default: - return jjMoveNfa_0(1, 0); - } - } - - private int jjStartNfaWithStates_0(int pos, int kind, int state) { - jjmatchedKind = kind; - jjmatchedPos = pos; - try { - curChar = input_stream.readChar(); - } catch (java.io.IOException e) { - return pos + 1; - } - return jjMoveNfa_0(state, pos + 1); - } - - private int jjMoveNfa_0(int startState, int curPos) { - int startsAt = 0; - jjnewStateCnt = 49; - int i = 1; - jjstateSet[0] = startState; - int kind = 0x7fffffff; - for (;;) { - if (++jjround == 0x7fffffff) - ReInitRounds(); - if (curChar < 64) { - long l = 1L << curChar; - do { - switch (jjstateSet[--i]) { - case 1: - if ((0x3ff000000000000L & l) != 0L) { - if (kind > 5) - kind = 5; - jjCheckNAdd(0); - } else if ((0x100002600L & l) != 0L) { - if (kind > 1) - kind = 1; - jjCheckNAddStates(0, 7); - } else if ((0xa400000000L & l) != 0L) { - if (kind > 16) - kind = 16; - } else if (curChar == 47) { - if (kind > 14) - kind = 14; - } - break; - case 49: - case 9: - if ((0x3ff000000000000L & l) != 0L) - jjCheckNAddTwoStates(9, 10); - break; - case 0: - if ((0x3ff000000000000L & l) == 0L) - break; - if (kind > 5) - kind = 5; - jjCheckNAdd(0); - break; - case 2: - if ((0x280000000000L & l) != 0L) - jjCheckNAdd(3); - break; - case 3: - if ((0x3ff000000000000L & l) == 0L) - break; - if (kind > 10) - kind = 10; - jjCheckNAdd(3); - break; - case 4: - if (curChar == 47) - kind = 14; - break; - case 6: - if ((0x100002600L & l) == 0L) - break; - if (kind > 15) - kind = 15; - jjstateSet[jjnewStateCnt++] = 6; - break; - case 7: - if ((0xa400000000L & l) != 0L) - kind = 16; - break; - case 11: - if ((0x100002600L & l) == 0L) - break; - if (kind > 1) - kind = 1; - jjCheckNAddStates(0, 7); - break; - case 12: - if ((0x100002600L & l) == 0L) - break; - if (kind > 1) - kind = 1; - jjCheckNAdd(12); - break; - case 13: - if ((0x100002600L & l) != 0L) - jjCheckNAddTwoStates(13, 17); - break; - case 15: - if ((0x100002600L & l) == 0L) - break; - if (kind > 14) - kind = 14; - jjstateSet[jjnewStateCnt++] = 15; - break; - case 18: - if ((0x100002600L & l) != 0L) - jjCheckNAddTwoStates(18, 5); - break; - case 19: - if ((0x100002600L & l) != 0L) - jjCheckNAddStates(8, 10); - break; - case 21: - if ((0x100002600L & l) == 0L) - break; - if (kind > 15) - kind = 15; - jjstateSet[jjnewStateCnt++] = 21; - break; - case 32: - if (curChar != 58) - break; - if (kind > 19) - kind = 19; - jjCheckNAdd(33); - break; - case 33: - if ((0x100002600L & l) == 0L) - break; - if (kind > 19) - kind = 19; - jjCheckNAdd(33); - break; - case 35: - if (curChar == 40) - jjstateSet[jjnewStateCnt++] = 34; - break; - case 38: - if (curChar != 58) - break; - if (kind > 20) - kind = 20; - jjCheckNAdd(39); - break; - case 39: - if ((0x100002600L & l) == 0L) - break; - if (kind > 20) - kind = 20; - jjCheckNAdd(39); - break; - case 41: - if (curChar == 40) - jjstateSet[jjnewStateCnt++] = 40; - break; - case 44: - if (curChar != 58) - break; - if (kind > 21) - kind = 21; - jjCheckNAdd(45); - break; - case 45: - if ((0x100002600L & l) == 0L) - break; - if (kind > 21) - kind = 21; - jjCheckNAdd(45); - break; - case 47: - if (curChar == 40) - jjstateSet[jjnewStateCnt++] = 46; - break; - default: - break; - } - } while (i != startsAt); - } else if (curChar < 128) { - long l = 1L << (curChar & 077); - do { - switch (jjstateSet[--i]) { - case 1: - if ((0x7fffffe87fffffeL & l) != 0L) { - if (kind > 18) - kind = 18; - jjCheckNAddTwoStates(8, 9); - } else if (curChar == 64) { - if (kind > 15) - kind = 15; - jjstateSet[jjnewStateCnt++] = 6; - } - if ((0x100000001000L & l) != 0L) - jjAddStates(11, 13); - else if ((0x2000000020L & l) != 0L) - jjAddStates(14, 15); - break; - case 49: - case 8: - if ((0x7fffffe87fffffeL & l) == 0L) - break; - if (kind > 18) - kind = 18; - jjCheckNAddTwoStates(8, 9); - break; - case 5: - if (curChar != 64) - break; - kind = 15; - jjstateSet[jjnewStateCnt++] = 6; - break; - case 10: - if ((0x7fffffe87fffffeL & l) == 0L) - break; - if (kind > 18) - kind = 18; - jjstateSet[jjnewStateCnt++] = 10; - break; - case 14: - if ((0x4000000040000L & l) != 0L) - jjstateSet[jjnewStateCnt++] = 15; - break; - case 16: - if ((0x2000000020L & l) != 0L) - jjstateSet[jjnewStateCnt++] = 14; - break; - case 17: - if ((0x1000000010000L & l) != 0L) - jjstateSet[jjnewStateCnt++] = 16; - break; - case 20: - if ((0x2000000020L & l) != 0L) - jjCheckNAdd(21); - break; - case 22: - if ((0x800000008L & l) != 0L) - jjstateSet[jjnewStateCnt++] = 20; - break; - case 23: - if ((0x400000004000L & l) != 0L) - jjstateSet[jjnewStateCnt++] = 22; - break; - case 24: - if ((0x20000000200L & l) != 0L) - jjstateSet[jjnewStateCnt++] = 23; - break; - case 25: - if ((0x8000000080000L & l) != 0L) - jjstateSet[jjnewStateCnt++] = 24; - break; - case 26: - if ((0x200000002000L & l) != 0L) - jjCheckNAdd(21); - break; - case 27: - if ((0x800000008000L & l) != 0L) - jjstateSet[jjnewStateCnt++] = 26; - break; - case 28: - if ((0x4000000040000L & l) != 0L) - jjstateSet[jjnewStateCnt++] = 27; - break; - case 29: - if ((0x4000000040L & l) != 0L) - jjstateSet[jjnewStateCnt++] = 28; - break; - case 30: - if ((0x100000001000L & l) != 0L) - jjAddStates(11, 13); - break; - case 31: - if ((0x2000000020L & l) == 0L) - break; - if (kind > 19) - kind = 19; - jjAddStates(16, 17); - break; - case 34: - if ((0x4000000040000L & l) != 0L) - jjstateSet[jjnewStateCnt++] = 31; - break; - case 36: - if ((0x400000004L & l) != 0L) - jjstateSet[jjnewStateCnt++] = 35; - break; - case 37: - if ((0x2000000020L & l) == 0L) - break; - if (kind > 20) - kind = 20; - jjAddStates(18, 19); - break; - case 40: - if ((0x4000000040000L & l) != 0L) - jjstateSet[jjnewStateCnt++] = 37; - break; - case 42: - if ((0x400000004000L & l) != 0L) - jjstateSet[jjnewStateCnt++] = 41; - break; - case 43: - if ((0x2000000020L & l) == 0L) - break; - if (kind > 21) - kind = 21; - jjAddStates(20, 21); - break; - case 46: - if ((0x4000000040000L & l) != 0L) - jjstateSet[jjnewStateCnt++] = 43; - break; - case 48: - if ((0x8000000080L & l) != 0L) - jjstateSet[jjnewStateCnt++] = 47; - break; - default: - break; - } - } while (i != startsAt); - } else { - int i2 = (curChar & 0xff) >> 6; - long l2 = 1L << (curChar & 077); - do { - switch (jjstateSet[--i]) { - default: - break; - } - } while (i != startsAt); - } - if (kind != 0x7fffffff) { - jjmatchedKind = kind; - jjmatchedPos = curPos; - kind = 0x7fffffff; - } - ++curPos; - if ((i = jjnewStateCnt) == (startsAt = 49 - (jjnewStateCnt = startsAt))) - return curPos; - try { - curChar = input_stream.readChar(); - } catch (java.io.IOException e) { - return curPos; - } - } - } - - static final int[] jjnextStates = - {12, 13, 17, 18, 5, 19, 25, 29, 19, 25, 29, 36, 42, 48, 2, 3, 32, 33, 38, 39, 44, 45,}; - - /** Token literal values. */ - public static final String[] jjstrLiteralImages = {"", null, "\53", "\55", "\72", null, null, null, "\50", "\51", - null, "\136", "\56", "\52", null, null, null, null, null, null, null, null,}; - - /** Lexer state names. */ - public static final String[] lexStateNames = {"DEFAULT",}; - protected SimpleCharStream input_stream; - private final int[] jjrounds = new int[49]; - private final int[] jjstateSet = new int[98]; - protected char curChar; - - /** Constructor. */ - public StandardUnitFormatTokenManager(SimpleCharStream stream) { - if (SimpleCharStream.staticFlag) - throw new Error("ERROR: Cannot use a static CharStream class with a non-static lexical analyzer."); - input_stream = stream; - } - - /** Constructor. */ - public StandardUnitFormatTokenManager(SimpleCharStream stream, int lexState) { - this(stream); - SwitchTo(lexState); - } - - /** Reinitialise parser. */ - public void ReInit(SimpleCharStream stream) { - jjmatchedPos = jjnewStateCnt = 0; - curLexState = defaultLexState; - input_stream = stream; - ReInitRounds(); - } - - private void ReInitRounds() { - int i; - jjround = 0x80000001; - for (i = 49; i-- > 0;) - jjrounds[i] = 0x80000000; - } - - /** Reinitialise parser. */ - public void ReInit(SimpleCharStream stream, int lexState) { - ReInit(stream); - SwitchTo(lexState); - } - - /** Switch to specified lex state. */ - public void SwitchTo(int lexState) { - if (lexState >= 1 || lexState < 0) - throw new TokenMgrError("Error: Ignoring invalid lexical state : " + lexState + ". State unchanged.", - TokenMgrError.INVALID_LEXICAL_STATE); - else - curLexState = lexState; - } - - protected Token jjFillToken() { - final Token t; - final String curTokenImage; - final int beginLine; - final int endLine; - final int beginColumn; - final int endColumn; - String im = jjstrLiteralImages[jjmatchedKind]; - curTokenImage = (im == null) ? input_stream.GetImage() : im; - beginLine = input_stream.getBeginLine(); - beginColumn = input_stream.getBeginColumn(); - endLine = input_stream.getEndLine(); - endColumn = input_stream.getEndColumn(); - t = Token.newToken(jjmatchedKind, curTokenImage); - - t.beginLine = beginLine; - t.endLine = endLine; - t.beginColumn = beginColumn; - t.endColumn = endColumn; - - return t; - } - - int curLexState = 0; - int defaultLexState = 0; - int jjnewStateCnt; - int jjround; - int jjmatchedPos; - int jjmatchedKind; - - /** Get the next Token. */ - public Token getNextToken() { - Token matchedToken; - int curPos; - - EOFLoop: for (;;) { - try { - curChar = input_stream.BeginToken(); - } catch (java.io.IOException e) { - jjmatchedKind = 0; - matchedToken = jjFillToken(); - return matchedToken; - } - - jjmatchedKind = 0x7fffffff; - jjmatchedPos = 0; - curPos = jjMoveStringLiteralDfa0_0(); - if (jjmatchedKind != 0x7fffffff) { - if (jjmatchedPos + 1 < curPos) - input_stream.backup(curPos - jjmatchedPos - 1); - matchedToken = jjFillToken(); - return matchedToken; - } - int error_line = input_stream.getEndLine(); - int error_column = input_stream.getEndColumn(); - String error_after = null; - boolean EOFSeen = false; - try { - input_stream.readChar(); - input_stream.backup(1); - } catch (java.io.IOException e1) { - EOFSeen = true; - error_after = curPos <= 1 ? "" : input_stream.GetImage(); - if (curChar == '\n' || curChar == '\r') { - error_line++; - error_column = 0; - } else - error_column++; - } - if (!EOFSeen) { - input_stream.backup(1); - error_after = curPos <= 1 ? "" : input_stream.GetImage(); - } - throw new TokenMgrError(EOFSeen, curLexState, error_line, error_column, error_after, curChar, - TokenMgrError.LEXICAL_ERROR); - } - } - - private void jjCheckNAdd(int state) { - if (jjrounds[state] != jjround) { - jjstateSet[jjnewStateCnt++] = state; - jjrounds[state] = jjround; - } - } - - private void jjAddStates(int start, int end) { - do { - jjstateSet[jjnewStateCnt++] = jjnextStates[start]; - } while (start++ != end); - } - - private void jjCheckNAddTwoStates(int state1, int state2) { - jjCheckNAdd(state1); - jjCheckNAdd(state2); - } - - private void jjCheckNAddStates(int start, int end) { - do { - jjCheckNAdd(jjnextStates[start]); - } while (start++ != end); - } - -} diff --git a/udunits/src/main/java/ucar/units/Token.java b/udunits/src/main/java/ucar/units/Token.java deleted file mode 100644 index a4e4ee40c7..0000000000 --- a/udunits/src/main/java/ucar/units/Token.java +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Copyright (c) 1998-2018 University Corporation for Atmospheric Research/Unidata - * See LICENSE for license information. - */ - -/* Generated By:JavaCC: Do not edit this line. Token.java Version 4.1 */ -/* JavaCCOptions:TOKEN_EXTENDS=,KEEP_LINE_COL=null */ -package ucar.units; - -/** - * Describes the input token stream. - */ - -public class Token { - - /** - * An integer that describes the kind of this token. This numbering - * system is determined by JavaCCParser, and a table of these numbers is - * stored in the file ...Constants.java. - */ - public int kind; - - /** The line number of the first character of this Token. */ - public int beginLine; - /** The column number of the first character of this Token. */ - public int beginColumn; - /** The line number of the last character of this Token. */ - public int endLine; - /** The column number of the last character of this Token. */ - public int endColumn; - - /** - * The string image of the token. - */ - public String image; - - /** - * A reference to the next regular (non-special) token from the input - * stream. If this is the last token from the input stream, or if the - * token manager has not read tokens beyond this one, this field is - * set to null. This is true only if this token is also a regular - * token. Otherwise, see below for a description of the contents of - * this field. - */ - public Token next; - - /** - * This field is used to access special tokens that occur prior to this - * token, but after the immediately preceding regular (non-special) token. - * If there are no such special tokens, this field is set to null. - * When there are more than one such special token, this field refers - * to the last of these special tokens, which in turn refers to the next - * previous special token through its specialToken field, and so on - * until the first special token (whose specialToken field is null). - * The next fields of special tokens refer to other special tokens that - * immediately follow it (without an intervening regular token). If there - * is no such token, this field is null. - */ - public Token specialToken; - - /** - * An optional attribute value of the Token. - * Tokens which are not used as syntactic sugar will often contain - * meaningful values that will be used later on by the compiler or - * interpreter. This attribute value is often different from the image. - * Any subclass of Token that actually wants to return a non-null value can - * override this method as appropriate. - */ - public Object getValue() { - return null; - } - - /** - * No-argument constructor - */ - public Token() {} - - /** - * Constructs a new token for the specified Image. - */ - public Token(int kind) { - this(kind, null); - } - - /** - * Constructs a new token for the specified Image and Kind. - */ - public Token(int kind, String image) { - this.kind = kind; - this.image = image; - } - - /** - * Returns the image. - */ - public String toString() { - return image; - } - - /** - * Returns a new Token object, by default. However, if you want, you - * can create and return subclass objects based on the value of ofKind. - * Simply add the cases to the switch for all those special cases. - * For example, if you have a subclass of Token called IDToken that - * you want to create if ofKind is ID, simply add something like : - * - * case MyParserConstants.ID : return new IDToken(ofKind, image); - * - * to the following switch statement. Then you can cast matchedToken - * variable to the appropriate type and use sit in your lexical actions. - */ - public static Token newToken(int ofKind, String image) { - return new Token(ofKind, image); - } - - public static Token newToken(int ofKind) { - return newToken(ofKind, null); - } - -} -/* JavaCC - OriginalChecksum=0179d71bb863498b02f4977621aeccba (do not edit this line) */ diff --git a/udunits/src/main/java/ucar/units/TokenMgrError.java b/udunits/src/main/java/ucar/units/TokenMgrError.java deleted file mode 100644 index 92f156895f..0000000000 --- a/udunits/src/main/java/ucar/units/TokenMgrError.java +++ /dev/null @@ -1,142 +0,0 @@ -/* - * Copyright (c) 1998-2018 University Corporation for Atmospheric Research/Unidata - * See LICENSE for license information. - */ - -/* Generated By:JavaCC: Do not edit this line. TokenMgrError.java Version 4.1 */ -/* JavaCCOptions: */ -package ucar.units; - -/** Token Manager Error. */ -@SuppressWarnings("serial") -public class TokenMgrError extends Error { - - /* - * Ordinals for various reasons why an Error of this type can be thrown. - */ - - /** - * Lexical error occurred. - */ - static final int LEXICAL_ERROR = 0; - - /** - * An attempt was made to create a second instance of a static token manager. - */ - static final int STATIC_LEXER_ERROR = 1; - - /** - * Tried to change to an invalid lexical state. - */ - static final int INVALID_LEXICAL_STATE = 2; - - /** - * Detected (and bailed out of) an infinite loop in the token manager. - */ - static final int LOOP_DETECTED = 3; - - /** - * Indicates the reason why the exception is thrown. It will have - * one of the above 4 values. - */ - int errorCode; - - /** - * Replaces unprintable characters by their escaped (or unicode escaped) - * equivalents in the given string - */ - protected static String addEscapes(String str) { - StringBuilder retval = new StringBuilder(); - 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)); - } else { - retval.append(ch); - } - } - } - return retval.toString(); - } - - /** - * Returns a detailed message for the Error when it is thrown by the - * token manager to indicate a lexical error. - * Parameters : - * EOFSeen : indicates if EOF caused the lexical error - * curLexState : lexical state in which this error occurred - * errorLine : line number when the error occurred - * errorColumn : column number when the error occurred - * errorAfter : prefix that was seen before this error occurred - * curchar : the offending character - * Note: You can customize the lexical error message by modifying this method. - */ - protected static String LexicalError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, - char curChar) { - return ("Lexical error at line " + errorLine + ", column " + errorColumn + ". Encountered: " - + (EOFSeen ? " " : ("\"" + addEscapes(String.valueOf(curChar)) + "\"") + " (" + (int) curChar + "), ") - + "after : \"" + addEscapes(errorAfter) + "\""); - } - - /** - * You can also modify the body of this method to customize your error messages. - * For example, cases like LOOP_DETECTED and INVALID_LEXICAL_STATE are not - * of end-users concern, so you can return something like : - * - * "Internal Error : Please file a bug report .... " - * - * from this method for such cases in the release version of your parser. - */ - public String getMessage() { - return super.getMessage(); - } - - /* - * Constructors of various flavors follow. - */ - - /** No arg constructor. */ - public TokenMgrError() {} - - /** Constructor with message and reason. */ - public TokenMgrError(String message, int reason) { - super(message); - errorCode = reason; - } - - /** Full Constructor. */ - public TokenMgrError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar, - int reason) { - this(LexicalError(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason); - } -} -/* JavaCC - OriginalChecksum=b8833038a5289044b86194beb351db0f (do not edit this line) */ diff --git a/udunits/src/main/java/ucar/units/StandardUnitFormat.jj b/udunits/src/main/javacc/StandardUnitFormat.jj similarity index 100% rename from udunits/src/main/java/ucar/units/StandardUnitFormat.jj rename to udunits/src/main/javacc/StandardUnitFormat.jj