private IToken TryGetNumericLiteral() { bool dotoccurred = false; bool expoccurred = false; bool negoccurred = false; if (Length == 1) { dotoccurred = true; } char next = Peek(); while (Char.IsDigit(next) || next == '-' || next == '+' || next == 'e' || (next == '.' && !dotoccurred)) { // Consume the Character ConsumeCharacter(); if (next == '+') { // Can only be first character in the numeric literal or come immediately after the 'e' if (Length > 1 && !Value.EndsWith("e+")) { throw Error("Unexpected Character (Code " + (int)next + ") +\nThe plus sign can only occur once at the Start of a Numeric Literal and once immediately after the 'e' exponent specifier, if this was intended as an additive operator please insert space to disambiguate this"); } } if (next == '-') { if (negoccurred && !Value.EndsWith("e-")) { // Negative sign already seen throw Error("Unexpected Character (Code " + (int)next + ") -\nThe minus sign can only occur once at the Start of a Numeric Literal, if this was intended as a subtractive operator please insert space to disambiguate this"); } else { negoccurred = true; // Check this is at the start of the string or immediately after the 'e' if (Length > 1 && !Value.EndsWith("e-")) { throw Error("Unexpected Character (Code " + (int)next + ") -\nThe minus sign can only occur at the Start of a Numeric Literal and once immediately after the 'e' exponent specifier, if this was intended as a subtractive operator please insert space to disambiguate this"); } } } else if (next == 'e') { if (expoccurred) { // Exponent already seen throw Error("Unexpected Character (Code " + (int)next + " e\nThe Exponent specifier can only occur once in a Numeric Literal"); } else { expoccurred = true; // Check that it isn't the start of the string if (Length == 1) { throw Error("Unexpected Character (Code " + (int)next + " e\nThe Exponent specifier cannot occur at the start of a Numeric Literal"); } } } else if (next == '.') { dotoccurred = true; } next = Peek(); } // Decimals can't end with a . so backtrack if (Value.EndsWith(".")) { Backtrack(); } String value = Value; if (!SparqlSpecsHelper.IsValidNumericLiteral(value)) { // Invalid Numeric Literal throw Error("The format of the Numeric Literal '" + Value + "' is not valid!"); } // Return the Token LastTokenType = Token.PLAINLITERAL; return(new PlainLiteralToken(Value, CurrentLine, StartPosition, EndPosition)); }