Example #1
0
        /// <summary>
        /// Parse the token stream.
        /// </summary>
        public void Parse()
        {
            m_obj = ParseObject();

            // Reset for future calculations.
            m_tokenStream.Reset();
        }
Example #2
0
        /// <summary>
        /// Opens a new file to be read. Overwrite the current
        /// JSON object.
        /// </summary>
        public void Open(string filename)
        {
            StreamReader reader = new StreamReader(filename);
            IronJSONLexer lexer;
            IronJSONTokenStream stream;
            IronJSONParser parser;

            lexer = new IronJSONLexer(reader.ReadToEnd());

            stream = lexer.GenerateTokenStream();

            parser = new IronJSONParser(stream);

            parser.Parse();
            m_obj = parser.Obj;
            m_cd = new IronJSONValue(m_obj);
            m_curPath = new ArrayList();

            reader.Close();
        }
Example #3
0
 /// <summary>
 /// Constructs an empty JSON object.
 /// </summary>
 public JSONManager()
 {
     m_obj = new IronJSONObject();
     m_cd = new IronJSONValue(m_obj);
     m_curPath = new ArrayList();
 }
Example #4
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="o">
 /// A <see cref="IronJSONObject"/>
 /// </param>
 public IronJSONValue(IronJSONObject o)
     : this(ValueType.Object)
 {
     m_data.objct = o;
 }
Example #5
0
 public IronJSONParser(IronJSONTokenStream tokenStream)
 {
     m_tokenStream = tokenStream;
     m_obj = null;
 }
Example #6
0
        /// <summary>
        /// Parse an object.
        /// </summary>
        private IronJSONObject ParseObject()
        {
            IronJSONObject obj = new IronJSONObject();

            VerifyToken(m_tokenStream.CurrentToken,
                        new TokenType[]{TokenType.LeftCurlyBracket});

            // Skip the '{'
            if (!m_tokenStream.ToNextToken())
                throw ParseError("expected '}'");

            while (!m_tokenStream.AtEnd() &&
                   m_tokenStream.CurrentToken.Type == TokenType.String)
            {
                // Save the string.
                string id = m_tokenStream.CurrentToken.String;
                m_tokenStream.ToNextToken(); // Skip the id.

                // Skip the ':'
                VerifyToken(m_tokenStream.CurrentToken, new TokenType[]{TokenType.Colon});
                if (!m_tokenStream.ToNextToken())
                    throw ParseError("expected ':'");

                // Parse the value.
                obj[id] = ParseValue();

                // Skip the ',' or '}'. Error if it's not either.
                VerifyToken(m_tokenStream.CurrentToken,
                            new TokenType[]{TokenType.Comma, TokenType.RightCurlyBracket});
                if (!m_tokenStream.ToNextToken())
                    break;

                // If what we skipped what a '}', break.
                if (m_tokenStream.PreviousToken.Type == TokenType.RightCurlyBracket)
                    break;
            }

            return obj;
        }