private TokenId ParseNumber(CharacterReader reader) { while (char.IsNumber(reader.Peek()) || (reader.Peek() == '.')) { reader.Read(); } return(TokenId.Number); }
private TokenId GetNextTokenId() { char ch = _reader.Read(); if ((ch == '\n') || (char.IsWhiteSpace(ch))) { while ((_reader.Peek() == '\n') || (char.IsWhiteSpace(_reader.Peek()))) { _reader.Read(); } return(TokenId.Whitespace); } switch (ch) { case ',': return(TokenId.Comma); case ':': return(TokenId.Colon); case '[': return(TokenId.OpenSquareBrace); case ']': return(TokenId.CloseSquareBrace); case '{': return(TokenId.OpenCurlyBrace); case '}': return(TokenId.CloseCurlyBrace); case '\"': return(ParseString(_reader)); case 'n': return(ParseNull(_reader)); default: if ((ch == '-') || (ch >= '0') && (ch <= '9')) { return(ParseNumber(_reader)); } return(TokenId.None); } }
private TokenId ParseString(CharacterReader reader) { while (reader.Peek() != '\"') { reader.Read(); } reader.Read(); return(TokenId.String); }
private TokenId ParseNull(CharacterReader reader) { if (reader.Peek() != 'u') { throw new InvalidOperationException(); } reader.Read(); if (reader.Peek() != 'l') { throw new InvalidOperationException(); } reader.Read(); if (reader.Peek() != 'l') { throw new InvalidOperationException(); } reader.Read(); return(TokenId.Null); }