private void ImplementSkipSpace() { CS.Block($"public override {Cfg.IContext} {Cfg.SkipSpace}({Cfg.IContext} {Cfg.CtxName})", () => { CS.Ln($"return {Cfg.CU(Grammar.Attr.Spacing.Identifier)}({Cfg.CtxName}).Next;"); }); }
public void Visit() { CS.Block($"namespace {Cfg.Namespace}", () => { foreach (var @using in Cfg.Usings) { CS.Ln($"using {@using};"); } CS.Ln(); CS.Block($"public partial class {Cfg.ParserClass} : {Cfg.ParserBase}", () => { ImplementInterfaceParse(); CS.Ln(); ImplementSkipSpace(); foreach (var rule in Grammar.AllRules) { CS.Ln(); VisitRule(rule); } CS.Ln(); CS.Ln(GL.Lines); }); }); }
private void ImplementInterfaceParse() { CS.Block($"public override {Cfg.IResult} {Cfg.InterfaceParse}({Cfg.IContext} {Cfg.CtxName})", () => { CS.Ln($"{Cfg.ClearCache}();"); CS.Ln($"return {Cfg.CU(Grammar.Attr.Start.Identifier)}({Cfg.CtxName});"); }); }
protected override void VisitRule(IRule rule) { CS.Ln($"// {rule.Identifier} -> {Cfg.CU(rule.Identifier)}"); CS.Block($"protected virtual {Cfg.IResult} {Cfg.CU(rule.Identifier)}({Cfg.IContext} {Cfg.CtxName})", () => { Locals.Reset(); using (Locals.PrepareResult()) { CS.Ln($"var {Cfg.CurName} = {Cfg.CtxName};"); VisitExpression(rule.Expression); CS.Ln($"return {Cfg.FinishRule}({Locals.Result}, \"{CharRep.InCSharp(rule.Identifier.Name)}\");"); } }); }