Пример #1
0
        private IDictionary <string, object> ParseObject()
        {
            Dictionary <string, object> dictionary = new Dictionary <string, object>();

            lexer.NextToken();
            while (true)
            {
                switch (lexer.LookAhead())
                {
                case Lexer.Token.None:
                    TriggerError("Invalid token");
                    return(null);

                case Lexer.Token.Comma:
                    lexer.NextToken();
                    continue;

                case Lexer.Token.CurlyClose:
                    lexer.NextToken();
                    return(dictionary);
                }
                string key = EvalLexer(lexer.ParseString());
                if (errorMessage != null)
                {
                    return(null);
                }
                Lexer.Token token = lexer.NextToken();
                if (token != Lexer.Token.Colon)
                {
                    TriggerError("Invalid token; expected ':'");
                    return(null);
                }
                object value = ParseValue();
                if (errorMessage != null)
                {
                    return(null);
                }
                dictionary[key] = value;
            }
        }
Пример #2
0
 public Token NextToken()
 {
     this.SkipWhiteSpaces();
     return(Lexer.NextToken(this.json, ref this.index));
 }
Пример #3
0
        IDictionary <string, object> ParseObject()
        {
            var table = new FastParse.MemoryLiteDictionary <string, object>();

            // Estimate the number of objects that are going to go in this dictionary
            table.SetCapacity(4);

            // {
            lexer.NextToken();

            while (true)
            {
                var token = lexer.LookAhead();

                switch (token)
                {
                case Lexer.Token.None:
                    TriggerError("Invalid token");
                    return(null);

                case Lexer.Token.Comma:
                    lexer.NextToken();
                    break;

                case Lexer.Token.CurlyClose:
                    lexer.NextToken();
                    return(table);

                default:
                    // name
                    string name = lexer.ParseString();

                    /*
                     * if (name.Contains ("TEST_") || name.Contains ("test_")) {
                     *      // If an artists labels an animation as test, let's not include it and save some memory
                     *      lexer.SkipThisObject();
                     *      break;
                     * }*/

                    if (errorMessage != null)
                    {
                        return(null);
                    }

                    // :
                    token = lexer.NextToken();

                    if (token != Lexer.Token.Colon)
                    {
                        TriggerError("Invalid token; expected ':'");
                        return(null);
                    }

                    // value
                    object value = ParseValue();

                    if (errorMessage != null)
                    {
                        return(null);
                    }

                    if (value != null)
                    {
                        table [name] = value;
                    }
                    break;
                }
            }

            //return null; // Unreachable code
        }