1 Feb 08:37
[Spirit2] API ease of use vs. efficiency tradeoffs
Bernard Hugueney <spirit <at> bernard-hugueney.org>
2009-02-01 07:37:25 GMT
2009-02-01 07:37:25 GMT
Dear Spiriters, I came to a better understanding of the Spirit2x API thanks to your messages and a little investigation. It appears to me that Spirit2(x) uses pass-by-reference "out" arguments and bool return value instead of boost::optional<> for performance reasons. Also for performance reasons, it uses default constructor and swap() (when using rule<>::operator%=() ) instead of "copy" constructor. (Hereafter, I'll consider that rule<> are used to create AST nodes, so rules result type is for example ast_node, while parsed data would be for example int float std::string, or boost::fusion::vector<> combinaison of those, the parsed data would be of type parsed_data_t). However, I would like to question those choices : 1) With regard to default constructor and swap() it create two constraints that I consider bothersome : a) AST nodes constructed from parsed data must be DefaultConstructible, with a added state corresponding to "no parsed data". b) AST nodes must be swappable with parsed data. The swap function cannot be meaningful as soon as the AST node adds something to the parsed data, because the parsed data cannot receive this info (-> "slicing"). Empiric evidence of the uselessness of this functionality for custom AST is given by the fact that a small bug in the Spirit2x implementation pervented to use custom swap function, hence custom AST node types for rules using operator%=. While these choice of API negatively impact the API of the client code with "undue" constraints, I think (and am willing to investigate any benchmark(Continue reading)
> > Thank you very much for your answer, and your work on Spirit2x
>
> Most welcome. So here's my answer:
>
> It would be good to first invite you to the spirit-devel list. I'd
> like to point you out to some threads I started as a means to self
> document the insides of Spirit2.
Most interesting reading ! I can't believe I used to consider parsers boring
.
> Having said that, it seems, based on my short experiment a day
> ago, that the return-attribute semantics *can* be simulated by
RSS Feed