@VisibleForTesting Token(TokenType type, int tokenStart, String string) { this(type, new SourcePos(0, tokenStart), string.length(), string); }
/** * @return the character index within the original expression string * in which this token starts */ public int getTokenStartColumn() { return pos.getColumn(); }
private Token finishToken(TokenType type, String text) { int length = currentCharIndex - currentTokenStart; Token token = new Token(type, currentTokenStartPos, length, text); currentTokenStart = currentCharIndex; currentTokenStartPos = new SourcePos(currentLineIndex, currentColumnIndex); return token; }
@Test public void symbolSourceRefs() { FunctionCallNode call = (FunctionCallNode) FormulaParser.parse("[A] + [B]"); assertThat(call.getSourceRange(), equalTo(new SourceRange(new SourcePos(0, 0), new SourcePos(0, 9)))); assertThat(call.getArgument(1).getSourceRange(), equalTo(new SourceRange(new SourcePos(0, 6), new SourcePos(0, 9)))); }
@Test public void invalidNumber() { FormulaException exception = null; try { FormulaParser.parse("A*B+\nC + 13.342342.2343"); } catch (FormulaException e) { exception = e; } assertNotNull(exception); assertThat(exception.getSourceRange(), equalTo(new SourceRange(new SourcePos(1, 4), new SourcePos(1, 18)))); }
@Test public void badNumberOfArguments() { FormulaValidator validator = validate("IF(1)"); assertThat(validator.getErrors(), hasSize(1)); assertThat(validator.getErrors().get(0).getSourceRange(), equalTo(new SourceRange(new SourcePos(0, 0), 5))); }