@Override public String toString() { StringBuilder sb = new StringBuilder(64); sb.append(getClass().getName()).append(" ["); sb.append(_rep); sb.append("]"); return sb.toString(); }
private String parseUnquotedIdentifier() { if (look == '\'') { throw expected("unquoted identifier"); } StringBuilder sb = new StringBuilder(); while (Character.isLetterOrDigit(look) || look == '.') { sb.append(look); GetChar(); } if (sb.length() < 1) { return null; } return sb.toString(); }
/** * Parses simple factors that are not primitive ranges or range components i.e. '!', ':'(and equiv * '...') do not appear Examples * * <pre> * my.named...range. * foo.bar(123.456, "abc") * 123.456 * "abc" * true * </pre> */ private ParseNode parseNonRange(int savePointer) { resetPointer(savePointer); if (Character.isDigit(look)) { return new ParseNode(parseNumber()); } if (look == '"') { return new ParseNode(new StringPtg(parseStringLiteral())); } // from now on we can only be dealing with non-quoted identifiers // which will either be named ranges or functions StringBuilder sb = new StringBuilder(); if (!Character.isLetter(look)) { throw expected("number, string, or defined name"); } while (isValidDefinedNameChar(look)) { sb.append(look); GetChar(); } SkipWhite(); String name = sb.toString(); if (look == '(') { return function(name); } if (name.equalsIgnoreCase("TRUE") || name.equalsIgnoreCase("FALSE")) { return new ParseNode(new BoolPtg(name.toUpperCase())); } if (_book == null) { // Only test cases omit the book (expecting it not to be needed) throw new IllegalStateException("Need book to evaluate name '" + name + "'"); } EvaluationName evalName = _book.getName(name, _sheetIndex); if (evalName == null) { throw new FormulaParseException( "Specified named range '" + name + "' does not exist in the current workbook."); } if (evalName.isRange()) { return new ParseNode(evalName.createPtg()); } // TODO - what about NameX ? throw new FormulaParseException("Specified name '" + name + "' is not a range as expected."); }
/** * Note - caller should reset {@link #_pointer} upon <code>null</code> result * * @return The sheet name as an identifier <code>null</code> if '!' is not found in the right * place */ private SheetIdentifier parseSheetName() { String bookName; if (look == '[') { StringBuilder sb = new StringBuilder(); GetChar(); while (look != ']') { sb.append(look); GetChar(); } GetChar(); bookName = sb.toString(); } else { bookName = null; } if (look == '\'') { StringBuffer sb = new StringBuffer(); Match('\''); boolean done = look == '\''; while (!done) { sb.append(look); GetChar(); if (look == '\'') { Match('\''); done = look != '\''; } } Identifier iden = new Identifier(sb.toString(), true); // quoted identifier - can't concatenate anything more SkipWhite(); if (look == '!') { GetChar(); return new SheetIdentifier(bookName, iden); } return null; } // unquoted sheet names must start with underscore or a letter if (look == '_' || Character.isLetter(look)) { StringBuilder sb = new StringBuilder(); // can concatenate idens with dots while (isUnquotedSheetNameChar(look)) { sb.append(look); GetChar(); } SkipWhite(); if (look == '!') { GetChar(); return new SheetIdentifier(bookName, new Identifier(sb.toString(), false)); } return null; } return null; }