@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"))); }
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 { 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 { 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 ); }
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 ); }
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 );  }