
After reading the paper referenced in http://lists.boost.org/Archives/boost/2007/04/120230.php I decided to set about implementing something similar to it in C++. You can see the current results here: http://magila.googlepages.com/template.zip It uses Spirit for parsing and AST generation and Property Tree for storing the dynamic data. Still on my todo list is making the character type a template parameter, currently everything just uses char. Also expand() should probably be made a free function. Obviously the main interest is as a companion for the forthcoming cgi library. So what do you think? Interesting? Not? Steven Siloti

Steven Siloti wrote:
After reading the paper referenced in http://lists.boost.org/Archives/boost/2007/04/120230.php I decided to set about implementing something similar to it in C++.
You can see the current results here: http://magila.googlepages.com/template.zip
It uses Spirit for parsing and AST generation and Property Tree for storing the dynamic data. Still on my todo list is making the character type a template parameter, currently everything just uses char. Also expand() should probably be made a free function.
Why seems fine the way it is?
Obviously the main interest is as a companion for the forthcoming cgi library. So what do you think? Interesting? Not?
I think it's interesting. I'm not sure being tied only to property tree only is the ideal. It would be interesting to figure what concepts are required for use with an output template. Perhaps there should be alternate binding mechanisms where say vector<string> could be bound to users. Obviously there's lots of holes to fill, but I would like to see something like this in Boost at some point. Jeff

Jeff Garland wrote:
Steven Siloti wrote:
After reading the paper referenced in http://lists.boost.org/Archives/boost/2007/04/120230.php I decided to set about implementing something similar to it in C++.
You can see the current results here: http://magila.googlepages.com/template.zip
It uses Spirit for parsing and AST generation and Property Tree for storing the dynamic data. Still on my todo list is making the character type a template parameter, currently everything just uses char. Also expand() should probably be made a free function.
FWIW, the QuickBook template engine was inspired by Terrence Parr's template engine. It's a bit more flexible, though, in the sense that the the template declarations and definitions are both part of the language. It is, in theory, turing complete. Rene Rivera is using it to target different backends. Also, the current development on Spirit2 named Karma is also inspired by it. Karma is a fully static, expression template rendition of it using a syntax almost similar to Spirit's. It will debut on BoostCon. Regards, -- Joel de Guzman http://www.boost-consulting.com http://spirit.sf.net

Joel de Guzman wrote:
Jeff Garland wrote:
Steven Siloti wrote:
After reading the paper referenced in http://lists.boost.org/Archives/boost/2007/04/120230.php I decided to set about implementing something similar to it in C++.
You can see the current results here: http://magila.googlepages.com/template.zip
It uses Spirit for parsing and AST generation and Property Tree for storing the dynamic data. Still on my todo list is making the character type a template parameter, currently everything just uses char. Also expand() should probably be made a free function.
FWIW, the QuickBook template engine was inspired by Terrence Parr's template engine. It's a bit more flexible, though, in the sense that the the template declarations and definitions are both part of the language. It is, in theory, turing complete. Rene Rivera is using it to target different backends.
Interesting...
Also, the current development on Spirit2 named Karma is also inspired by it. Karma is a fully static, expression template rendition of it using a syntax almost similar to Spirit's. It will debut on BoostCon.
I can hardly wait any longer :-) Is that the Thursday session? Jeff

Steven Siloti skrev:
After reading the paper referenced in http://lists.boost.org/Archives/boost/2007/04/120230.php I decided to set about implementing something similar to it in C++.
You can see the current results here: http://magila.googlepages.com/template.zip
It uses Spirit for parsing and AST generation and Property Tree for storing the dynamic data. Still on my todo list is making the character type a template parameter, currently everything just uses char. Also expand() should probably be made a free function.
well, not for my sake.
Obviously the main interest is as a companion for the forthcoming cgi library. So what do you think? Interesting? Not?
Very interesting. We have implemented our own template engine, but I would much rather be using a well thought-out and heavily tested version from boost. I think it is quite amazing to see how a variety of boost libraries makes it so easy (or at least short) to implement something like this. Some comments: 1. call the class template_document or something similarly readable 2. see if it is possible to describe a minimal "tree" concept s.t. you can make the class work with other trees than property-tree. (it might be that you only need a small subset of the property-tree operations). -Thorsten

Thorsten Ottosen skrev:
Some comments:
1. call the class template_document or something similarly readable
2. see if it is possible to describe a minimal "tree" concept s.t. you can make the class work with other trees than property-tree. (it might be that you only need a small subset of the property-tree operations).
3. Get rid of all hard-coding of std::string. The charactor type may be found from the string type. List the few string operations that are rally needed, and consider provided a traits class. -Thorsten

Thorsten Ottosen wrote:
Thorsten Ottosen skrev:
Some comments:
1. call the class template_document or something similarly readable
2. see if it is possible to describe a minimal "tree" concept s.t. you can make the class work with other trees than property-tree. (it might be that you only need a small subset of the property-tree operations).
3. Get rid of all hard-coding of std::string. The charactor type may be found from the string type. List the few string operations that are rally needed, and consider provided a traits class.
-Thorsten
You're right of course about needing create a traits class. I've abstracted out the character type, tree type, and associated operations into one. The tree operations are provided by a function and two classes: data, anonymous_children, and named_children. The function data simply returns the data associated with a given node. anonymous_children models a subset of Forward Container and provides access to any unnamed children of a node. Likewise named_children models a subset of Pair Associative Container and provides access to any named children of a node. You can check it out here: http://magila.googlepages.com/templatev2.zip Now for the fun part, documenting all this. Steven Siloti
participants (4)
-
Jeff Garland
-
Joel de Guzman
-
Steven Siloti
-
Thorsten Ottosen