public static ParsnipModel Go(ParsnipModel model) { var vis = new Visitor(); var oldRules = model.Rules; foreach (var oldRule in oldRules) { var newFunc = oldRule.ParseFunction.ApplyVisitor(vis); var newRule = oldRule.WithParseFunction(newFunc); model = model.ReplacingRule(oldRule, newRule); } return(model); }
public static ParsnipModel Go(ParsnipModel model) { var oldRules = model.Rules; foreach (var oldRule in oldRules) { var interfaceMethodName = NameGen.InterfaceMethodName(oldRule.RuleIdentifier); var vis = new Visitor(interfaceMethodName); (var newFunc, var newMethods) = oldRule.ParseFunction.ApplyVisitor(vis, oldRule.ReturnType); var newRule = oldRule.WithParseFunction(newFunc); model = model.ReplacingRule(oldRule, newRule); foreach (var method in newMethods) { model = model.AddingInterfaceMethod(method); } } return(model); }
public static ParsnipModel Go(ParsnipModel model) { var vis = new ReplacingVisitor(model); vis.ReferencedRule = old => { var rule = model.Rules.FirstOrDefault(i => i.RuleIdentifier == old.Identifier); if (rule == null) { throw new InvalidOperationException($"No such rule: {old.Identifier}"); } return(new ReferencedRule(old.Identifier, rule.ReturnType, interfaceMethod: null)); }; var oldRules = model.Rules; foreach (var oldRule in oldRules) { var newFunc = oldRule.ParseFunction.ApplyVisitor(vis); var newRule = oldRule.WithParseFunction(newFunc); model = model.ReplacingRule(oldRule, newRule); } return(model); }
public ReplacingVisitor(ParsnipModel model) { this.model = model; }