public Token Expect(string value, bool ignoreCase = true) { if (!this.Is(value, ignoreCase)) { throw UltraLiteException.UnexpectedToken(this, value); } return(this); }
/// <summary> /// If EOF throw an invalid token exception (used in while()) otherwise return "false" (not EOF) /// </summary> public bool CheckEOF() { if (_eof) { throw UltraLiteException.UnexpectedToken(this.Current); } return(false); }
/// <summary> /// Expect for type1 OR type2 OR type3 (if not, throw UnexpectedToken) /// </summary> public Token Expect(TokenType type1, TokenType type2, TokenType type3) { if (this.Type != type1 && this.Type != type2 && this.Type != type3) { throw UltraLiteException.UnexpectedToken(this); } return(this); }
internal BsonValue ReadValue(Token token) { switch (token.Type) { case TokenType.String: return(token.Value); case TokenType.OpenBrace: return(this.ReadObject()); case TokenType.OpenBracket: return(this.ReadArray()); case TokenType.Minus: // read next token (must be a number) var number = _tokenizer.ReadToken(false).Expect(TokenType.Int, TokenType.Double); return(number.Type == TokenType.Double ? new BsonValue(-Convert.ToDouble(number.Value, _numberFormat)) : new BsonValue(-Convert.ToInt32(number.Value, _numberFormat))); case TokenType.Int: return(new BsonValue(Convert.ToInt32(token.Value, _numberFormat))); case TokenType.Double: return(new BsonValue(Convert.ToDouble(token.Value, _numberFormat))); case TokenType.Word: switch (token.Value.ToLower()) { case "null": return(BsonValue.Null); case "true": return(true); case "false": return(false); default: throw UltraLiteException.UnexpectedToken(token); } } throw UltraLiteException.UnexpectedToken(token); }