public override void EnterRoot(Root root) { var eventModules = root.SourceFiles .SelectMany(x => x.ModuleDeclarations) .Where(x => x.Name == "Rule") .SelectMany(x => x.ModuleDeclarations) .Where(x => x.Name == "Events") .ToList(); var teamEnum = eventModules .SelectMany(x => x.EnumDeclarations) .Single(x => x.Name == "Team"); var playerEnum = eventModules .SelectMany(x => x.EnumDeclarations) .Single(x => x.Name == "Players"); root.AddChildFirst( new RuleDeclaration(root.Context, "Initialize player variables", new INode[] { new NativeTrigger(root.Context, "Ongoing - Each Player", new INode[] { new SimpleNameExpression(root.Context, "All") { Declaration = teamEnum.Values.Single(x => ((StringLiteral)x.Value).UnquotedText == "All") }, new SimpleNameExpression(root.Context, "All") { Declaration = playerEnum.Values.Single(x => ((StringLiteral)x.Value).UnquotedText == "All") }, }), new BooleanLiteral(root.Context, true), new LambdaExpression(root.Context, new INode[] { new BlockStatement(root.Context, new IStatement[0]) }) })); root.AddChildFirst( new RuleDeclaration(root.Context, "Initialize global variables", new INode[] { new NativeTrigger(root.Context, "Ongoing - Global", new INode[0]), new BooleanLiteral(root.Context, true), new LambdaExpression(root.Context, new INode[] { new BlockStatement(root.Context, new IStatement[0]) }) })); }