The idea is trivial, treat a stream of bytes/characters as containing substitution tokens and rewrite those tokens using a supplied context. Also includes iteration, expression support, context switching and a few other minor aspects.
It's a VS 2017, C# solution, targeting .netcoreapp 1.1 and .net 4.6+.
Once set up, transformation is ultra trivial, assuming a text template and some domain object being supplied to the pro forma method shown below:
private string GenerateMessage<TObject>(string doc, TObject ctx) {
ParseResult res = Parser.Parse(doc);
EvaluationContext ec = EvaluationContext.From(ctx);
var ctx = res.Execute(ExecutionContext.Build(ec));
return ctx.context.ToString();
}
No comments:
Post a Comment