void DefineRulePart(Rule r, RulePart part, AbstractSyntaxTree tree) { switch (part) { case RulePart.Do: r.Atom = tree.ToString(); break; case RulePart.As: r.Code = tree; break; case RulePart.If: r.Condition = (r.Condition == null) ? tree : new AbstractSyntaxTree("&") { Left = tree, Right = r.Condition }; break; default: throw new Exception("Error: expected DO, AS, or IF here."); case RulePart.end: if (r.Atom == null && r.Condition == null && r.Code != null) { throw new Exception("A rule requires either a name or a condition. This code part cannot stand alone: " + r.Code); } if (r.Atom == null && r.Condition != null && r.Code == null) { throw new Exception("A rule requires either a name or a value. This conditional part cannot stand alone: " + r.Condition); } r.Location = Volume + Book + Chapter + Section; if (Volume.EndsWith(" private\r\n") || Book.EndsWith(" private\r\n") || Chapter.EndsWith(" private\r\n") || Section.EndsWith(" private\r\n")) { r.IsPrivateToFile = Program.CurrentFileScope; } Program.AllRules.Add(r); thisRule = new Rule(); break; } current = null; rulePart = RulePart.unknown; }