protected override void VisitAnyExpression(AnyExpression expression) { CS.IndentInOut( "AnyExpression", () => { Locals.PeekPrep(Writer); CS.If( $"!{Cfg.CurName}.AtEnd", () => { using var next = Locals.Use("next"); using var location = Locals.Use("location"); using var node = Locals.Use("node"); CS.Ln($"{next} = {Cfg.CurName}.Advance(1);"); CS.Ln($"{location} = Location.From({Cfg.CurName}, {next});"); CS.Ln($"{node} = Leaf.From({location}, NodeSymbols.Any, ((char){Cfg.CurName}.Current).ToString(CultureInfo.InvariantCulture));"); CS.Ln($"{Locals.Result} = Result.Success({node}, {next}, {node});"); }, () => { CS.Ln($"{Locals.Result} = Result.Fail({Cfg.CurName});"); }); }); }
protected override void VisitStarExpression(StarExpression star) { CS.IndentInOut( "StarExpression", () => { using var start = Locals.Use("start"); using var nodes = Locals.Use("nodes"); using var location = Locals.Use("location"); using var node = Locals.Use("node"); CS.Ln($"{start} = {Cfg.CurName};"); CS.Ln($"{nodes} = new List<INode>(10);"); Locals.PeekPrep(Writer); CS.ForEver( () => { VisitExpression(star.Expression); CS.If( $"{Locals.Result}.IsSuccess", () => { CS.Ln($"{Cfg.CurName} = {Locals.Result}.Next;"); CS.Ln($"{nodes}.AddRange({Locals.Result}.Nodes);"); }, () => { CS.Ln("break;"); }); }); CS.Ln($"{location} = Location.From({start}, {Cfg.CurName});"); CS.Ln($"{node} = NodeList.From({location}, NodeSymbols.Star, {nodes});"); CS.Ln($"{Locals.Result} = Result.Success({location}, {Cfg.CurName}, {node});"); }); }
protected override void VisitNotExpression(NotExpression expression) { CS.IndentInOut( "NotExpression", () => { Locals.PeekPrep(Writer); VisitExpression(expression.Expression); CS.If( $"{Locals.Result}.IsSuccess", () => CS.Ln($"{Locals.Result} = Result.Fail({Cfg.CurName});"), () => CS.Ln($"{Locals.Result} = Result.Success({Locals.Result}, {Cfg.CurName});")); }); }