XPathParser { protected Literal parseNumericLiteral( TokenStream tokens ) { Position pos = tokens.nextPosition(); String sign = ""; if (tokens.canConsume('-')) sign = "-"; else if (tokens.canConsume('+')) sign = ""; String number = tokens.consume(); if (number.indexOf(".") != -1) { String value = sign + number; if (value.endsWith("e") && (tokens.matches('+') || tokens.matches('-'))) { value = value + tokens.consume() + tokens.consume(); } try { String canonical = typeSystem.getDoubleFactory().asString(value); return new Literal(canonical); } catch (ValueFormatException e) { String msg = GraphI18n.expectingLiteralAndUnableToParseAsDouble.text(value, pos.getLine(), pos.getColumn()); throw new ParsingException(pos, msg); } } String value = sign + number; try { String canonical = typeSystem.getLongFactory().asString(value); return new Literal(canonical); } catch (ValueFormatException e) { String msg = GraphI18n.expectingLiteralAndUnableToParseAsLong.text(value, pos.getLine(), pos.getColumn()); throw new ParsingException(pos, msg); } } XPathParser( TypeSystem context ); Component parseXPath( String xpath );  }
@Test public void shouldParseNumberLiteralContainingUnquotedIntegralValuesIntoCanonicalStringRepresentation() { assertThat(parser.parseNumericLiteral(tokenize("1")), is(literal("1"))); assertThat(parser.parseNumericLiteral(tokenize("-1")), is(literal("-1"))); assertThat(parser.parseNumericLiteral(tokenize("0")), is(literal("0"))); assertThat(parser.parseNumericLiteral(tokenize("+1001")), is(literal("1001"))); }
@Test public void shouldParseNumberLiteralContainingUnquotedDecimalValuesIntoCanonicalStringRepresentation() { assertThat(parser.parseNumericLiteral(tokenize("1.2")), is(literal("1.2"))); assertThat(parser.parseNumericLiteral(tokenize("-1.2")), is(literal("-1.2"))); assertThat(parser.parseNumericLiteral(tokenize("0.2")), is(literal("0.2"))); assertThat(parser.parseNumericLiteral(tokenize("+1001.2")), is(literal("1001.2"))); assertThat(parser.parseNumericLiteral(tokenize("1.2e10")), is(literal("1.2E10"))); assertThat(parser.parseNumericLiteral(tokenize("-1.2e10")), is(literal("-1.2E10"))); assertThat(parser.parseNumericLiteral(tokenize("0.2e10")), is(literal("2.0E9"))); assertThat(parser.parseNumericLiteral(tokenize("1.2e+10")), is(literal("1.2E10"))); assertThat(parser.parseNumericLiteral(tokenize("-1.2e+10")), is(literal("-1.2E10"))); assertThat(parser.parseNumericLiteral(tokenize("0.2e+10")), is(literal("2.0E9"))); assertThat(parser.parseNumericLiteral(tokenize("1.2e-10")), is(literal("1.2E-10"))); assertThat(parser.parseNumericLiteral(tokenize("-1.2e-10")), is(literal("-1.2E-10"))); assertThat(parser.parseNumericLiteral(tokenize("0.2e-10")), is(literal("2.0E-11"))); }