private ParsingData(string file, string content)
        {
            Rule initialGlobalValues = new Rule(Constants.INTERNAL_ELEMENT + "Initial Global Values");
            Rule initialPlayerValues = new Rule(Constants.INTERNAL_ELEMENT + "Initial Player Values", RuleEvent.OngoingPlayer, Team.All, PlayerSelector.All);

            globalTranslate = new TranslateRule(initialGlobalValues, Root, this);
            playerTranslate = new TranslateRule(initialPlayerValues, Root, this);

            GetRulesets(content, file, true, null);

            VarCollection = new VarCollection(ReservedGlobalIDs.ToArray(), ReservedGlobalNames.ToArray(), ReservedPlayerIDs.ToArray(), ReservedPlayerNames.ToArray());
            Root          = new ScopeGroup(VarCollection);
            ClassIndexes  = IndexedVar.AssignInternalVar(VarCollection, null, "_classIndexes", true);
            ClassArray    = IndexedVar.AssignInternalVar(VarCollection, null, "_classArray", true);

            if (!Diagnostics.ContainsErrors())
            {
                foreach (var ruleset in Rulesets)
                {
                    GetObjects(ruleset.Value, ruleset.Key, globalTranslate, playerTranslate);
                }
            }

            foreach (var type in DefinedTypes)
            {
                try
                {
                    type.RegisterParameters(this);
                }
                catch (SyntaxErrorException ex)
                {
                    Diagnostics.Error(ex);
                }
            }
            foreach (var method in UserMethods)
            {
                try
                {
                    method.RegisterParameters(this);
                }
                catch (SyntaxErrorException ex)
                {
                    Diagnostics.Error(ex);
                }
            }

            if (!Diagnostics.ContainsErrors())
            {
                // Parse the rules.
                Rules = new List <Rule>();

                for (int i = 0; i < RuleNodes.Count; i++)
                {
                    try
                    {
                        var result = TranslateRule.GetRule(RuleNodes[i], Root, this);
                        Rules.Add(result);
                    }
                    catch (SyntaxErrorException ex)
                    {
                        Diagnostics.Error(ex);
                    }
                }

                foreach (var definedVar in VarCollection.AllVars)
                {
                    try
                    {
                        if (definedVar is IndexedVar && definedVar.IsDefinedVar && definedVar.Scope == Root)
                        {
                            Node value = ((IDefine)definedVar.Node).Value;
                            if (value != null)
                            {
                                if (((IndexedVar)definedVar).IsGlobal)
                                {
                                    globalTranslate.Actions.AddRange(((IndexedVar)definedVar).SetVariable(globalTranslate.ParseExpression(Root, Root, value)));
                                }
                                else
                                {
                                    playerTranslate.Actions.AddRange(((IndexedVar)definedVar).SetVariable(playerTranslate.ParseExpression(Root, Root, value)));
                                }
                            }
                        }
                    }
                    catch (SyntaxErrorException ex)
                    {
                        Diagnostics.Error(ex);
                    }
                }

                globalTranslate.Finish();
                playerTranslate.Finish();

                // Add the player initial values rule if it was used.
                if (initialPlayerValues.Actions.Length > 0)
                {
                    Rules.Insert(0, initialPlayerValues);
                }

                // Add the global initial values rule if it was used.
                if (initialGlobalValues.Actions.Length > 0)
                {
                    Rules.Insert(0, initialGlobalValues);
                }

                foreach (Rule rule in AdditionalRules)
                {
                    if (rule.Actions.Length > 0)
                    {
                        Rules.Add(rule);
                    }
                }
            }

            Success = !Diagnostics.ContainsErrors();
        }
        private void GetRulesets(string document, string file, bool isRoot, ImportedFile cache)
        {
            string absolute = new Uri(file).AbsolutePath;

            // If this file was already loaded, don't load it again.
            if (Imported.Contains(absolute))
            {
                return;
            }
            Imported.Add(absolute);
            Diagnostics.AddFile(file);

            // Get the ruleset.
            RulesetNode ruleset;

            if (cache == null)
            {
                ruleset = GetRuleset(file, document);
            }
            else if (cache.Update() || cache.Cache == null)
            {
                ruleset     = GetRuleset(file, cache.Content);
                cache.Cache = ruleset;
            }
            else
            {
                ruleset = (RulesetNode)cache.Cache;
            }

            Rulesets.Add(file, ruleset);

            // Get the imported files.
            if (ruleset != null && !Diagnostics.ContainsErrors())
            {
                ReservedGlobalIDs.AddRange(ruleset.ReservedGlobalIDs);
                ReservedPlayerIDs.AddRange(ruleset.ReservedPlayerIDs);
                if (ruleset.ReservedGlobal != null)
                {
                    ReservedGlobalIDs.AddRange(ruleset.ReservedGlobal.ReservedIDs);
                    ReservedGlobalNames.AddRange(ruleset.ReservedGlobal.ReservedNames);
                }
                if (ruleset.ReservedPlayer != null)
                {
                    ReservedPlayerIDs.AddRange(ruleset.ReservedPlayer.ReservedIDs);
                    ReservedPlayerNames.AddRange(ruleset.ReservedPlayer.ReservedNames);
                }

                List <string> importedFiles = new List <string>();
                foreach (ImportNode importNode in ruleset.Imports)
                {
                    try
                    {
                        Importer importer = new Importer(Diagnostics, importedFiles, importNode.File, file, importNode.Location);
                        if (!importer.AlreadyImported)
                        {
                            GetRulesets(null, importer.ResultingPath, false, importer.FileData);
                            importedFiles.Add(importer.ResultingPath);
                        }
                    }
                    catch (SyntaxErrorException ex)
                    {
                        Diagnostics.Error(ex);
                    }
                }
            }
        }