Not sure i quiet get your meaning about symbolic evaluation, or it s just what i did :x
Anyways, for whoever else interested https://github.com/mh-cbon/template-tree-simplifier I was wondering if you have any thoughts regarding the idea to generate the go code not via string manipulation but via the go ast capabilities. https://golang.org/pkg/go/ast/ I saw there is a printer. I m not quiet sure yet how this going to turn, but i felt i was needing a sort of structure to store types of the data while generating go code, which was not available when i used text processing. I don t want to abuse, but i was also wondering if ESI processing was waking up any of your hears. As i feel more & more confy with the template package i begin to think about this. you or anyone else. thanks! On Thursday, December 22, 2016 at 7:55:10 AM UTC+1, Egon wrote: > > > > On Wednesday, 21 December 2016 23:34:54 UTC+2, mhh...@gmail.com wrote: >> >> Hi, >> >> back on my initial question about compiling template, i m looking for >> some experienced ideas. >> >> I have now found out i needed to change the ast tree of template in order >> to simplify it for later manipulation. >> > > The easiest way I can think of is trying to do it in terms of symbolically > evaluating of the tree and using the actions as the new tree. > > https://play.golang.org/p/i-QY-7wJYq > > Obviously doing the same on the actual structure is more annoying. > > >> So for example i transform this >> {{ ("what" | up) | lower }} >> into >> {{ $some := ("what" | up) }} >> {{ $some | lower }} >> >> And so on, i d like to reach >> {{ $some := up "what" }} >> {{ lower $some }} >> >> Which will be as close as possible to regular go code. >> >> The thing is that the process to do those transformations seems pretty >> fragile and tedious. >> >> I have tree like this >> parse.Tree >> parse.ActionNode >> parse.PipeNode >> parse.CommandNode >> parse.IdentifierNode Ident="up" >> parse.StringNode Quoted="\"some\"" Text="some" >> parse.TextNode Text="\n" >> parse.ActionNode >> parse.PipeNode >> parse.CommandNode >> parse.StringNode Quoted="\"some\"" Text="some" >> parse.CommandNode >> parse.IdentifierNode Ident="split" >> parse.PipeNode >> parse.CommandNode >> parse.PipeNode >> parse.CommandNode >> parse.StringNode Quoted="\"what\"" Text="what" >> parse.CommandNode >> parse.IdentifierNode Ident="lower" >> parse.CommandNode >> parse.IdentifierNode Ident="up" >> parse.TextNode Text="\n" >> >> to simplify, one of the algorithm consist of browsing the structure >> until it match a Pipe containing a Cmd with an Identifier after a Cmd >> with a Pipe >> that would match *("what" | lower) | up* >> >> And so on to simplify more and more the tree. >> >> I wonder if there are better ways to achieve this kind of transform. >> > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.