public AssetBundleManifestDocument(string content)
        {
            parser = new ManifestParser(content);
            parser.Reset();

            Parse();
        }
Esempio n. 2
0
        internal void Parse(ManifestParser parser, ManifestToken cur)
        {
            if (parseTabCount > tabCount)
            {
                bool isNew = false;
                if (curChild == null)
                {
                    isNew             = true;
                    curChild          = new ManifestNode();
                    curChild.tabCount = parseTabCount;
                    children.Add(curChild);
                }
                curChild.Parse(parser, cur);
                if (cur.Type == ManifestTokenTypes.EOL)
                {
                    var next  = parser.PeekNextToken();
                    var next2 = parser.PeekNextToken(2);
                    ManifestTokenTypes nextType = ManifestTokenTypes.EOF;
                    int nextTab = 0;
                    if (next.Type == ManifestTokenTypes.Tabstop)
                    {
                        nextTab  = ((ManifestTabStop)next).Count;
                        nextType = next2.Type;
                    }
                    else
                    {
                        nextType      = next.Type;
                        parseTabCount = 0;
                    }

                    if ((nextTab <= curChild.tabCount && nextType == ManifestTokenTypes.String) || (nextTab < curChild.tabCount && nextType == ManifestTokenTypes.ValueBegin))
                    {
                        curChild = null;
                    }
                }
                if (isNew)
                {
                    curChild.tabCount = parseTabCount;
                }
            }
            else if (parseTabCount < tabCount)
            {
                curChild = null;
                return;
            }
            else
            {
                if (curChild != null)
                {
                    if (curChild.tabCount > tabCount || (curChild.tabCount == tabCount && cur.Type == ManifestTokenTypes.ValueBegin))
                    {
                        if (curChild.tabCount == tabCount)
                        {
                            valueBegin = true;
                        }
                        curChild = null;
                    }
                    else
                    {
                        curChild.Parse(parser, cur);
                    }
                }
                else
                {
                    switch (cur.Type)
                    {
                    case ManifestTokenTypes.Tabstop:
                        if (parser.LastToken == null || parser.LastToken.Type == ManifestTokenTypes.EOL)
                        {
                            parseTabCount = ((ManifestTabStop)cur).Count;
                        }
                        break;

                    case ManifestTokenTypes.ValueBegin:
                        if (parser.LastToken == null || parser.LastToken.Type == ManifestTokenTypes.EOL)
                        {
                            valueBegin = true;
                        }
                        else
                        {
                            throw new System.NotSupportedException("Unexpected token:" + cur);
                        }
                        break;

                    case ManifestTokenTypes.String:
                    {
                        //var lastType = parser.LastToken.Type;
                    }
                    break;

                    case ManifestTokenTypes.Node:
                        if (parser.LastToken.Type == ManifestTokenTypes.String)
                        {
                            if (valueBegin)
                            {
                                if (curChild == null)
                                {
                                    curChild          = new ManifestNode();
                                    curChild.Name     = parser.LastToken.Text;
                                    curChild.tabCount = tabCount;
                                    values.Add(curChild);
                                }
                                else
                                {
                                    throw new System.NotSupportedException("Unexpected token:" + cur);
                                }
                            }
                            else if (propertyBegin)
                            {
                                if (pKey == null)
                                {
                                    pKey = parser.LastToken.Text;
                                }
                                else
                                {
                                    throw new System.NotSupportedException("Unexpected token:" + cur);
                                }
                            }
                            else
                            {
                                Name = parser.LastToken.Text;
                            }
                        }
                        else
                        {
                            throw new System.NotSupportedException("Unexpected token:" + cur);
                        }
                        break;

                    case ManifestTokenTypes.Comma:
                    {
                        if (propertyBegin)
                        {
                            if (pKey != null)
                            {
                                if (parser.LastToken.Type == ManifestTokenTypes.String)
                                {
                                    properties[pKey] = parser.LastToken.Text;
                                    pKey             = null;
                                }
                                else
                                {
                                    throw new System.NotSupportedException("Unexpected token:" + cur);
                                }
                            }
                            else
                            {
                                throw new System.NotSupportedException("Unexpected token:" + cur);
                            }
                        }
                        else
                        {
                            throw new System.NotSupportedException("Unexpected token:" + cur);
                        }
                    }
                    break;

                    case ManifestTokenTypes.EOL:
                    case ManifestTokenTypes.EOF:
                        if (!propertyBegin)
                        {
                            if (valueBegin)
                            {
                                if (curChild == null)
                                {
                                    curChild          = new ManifestNode();
                                    curChild.Name     = parser.LastToken.Text;
                                    curChild.tabCount = tabCount;
                                    values.Add(curChild);
                                }
                                else
                                {
                                    throw new System.NotSupportedException("Unexpected token:" + cur);
                                }
                                if (cur.Type == ManifestTokenTypes.EOL)
                                {
                                    if (parser.PeekNextToken().Type == ManifestTokenTypes.Tabstop && parser.PeekNextToken(2).Type == ManifestTokenTypes.String)
                                    {
                                        parser.GetNextToken();
                                        var node = parser.GetNextToken();
                                        curChild.Name += node.Text;
                                    }
                                }
                            }
                            else
                            {
                                if (parser.LastToken.Type == ManifestTokenTypes.String)
                                {
                                    InnerText = parser.LastToken.Text;
                                }
                            }
                        }
                        else
                        {
                            throw new System.NotSupportedException("Unexpected token:" + cur);
                        }
                        propertyBegin = false;
                        valueBegin    = false;
                        break;

                    case ManifestTokenTypes.PropertyBegin:
                        if (!propertyBegin)
                        {
                            propertyBegin = true;
                        }
                        else
                        {
                            throw new System.NotSupportedException("Unexpected token:" + cur);
                        }
                        break;

                    case ManifestTokenTypes.PropertyEnd:
                        if (propertyBegin)
                        {
                            if (pKey != null)
                            {
                                if (parser.LastToken.Type == ManifestTokenTypes.String)
                                {
                                    properties[pKey] = parser.LastToken.Text;
                                    pKey             = null;
                                }
                                else
                                {
                                    throw new System.NotSupportedException("Unexpected token:" + cur);
                                }
                            }

                            propertyBegin = false;
                        }
                        break;

                    default:
                        throw new System.NotSupportedException("Unexpected token:" + cur);
                    }
                }
            }
        }