I'm experimenting with caching lexer output, and have devised a `cache()` combinator
that takes a parser outputting `Foo` and returns a parser outputting `const Foo &`. The subparser
is queried only once for a given position in the input.
This works a treat until you get to transforms: the functors all take rvalue references. The quick
fix is to let the cache copy results. Another is to make the functors take `auto` arguments.
Yet another would be to change the transformer argument types to take const lvalue references
where the lower level parsing is cached.
Is there anything more generic or appropriate that you'd suggest to address this problem?
The cache might be an unnecessary addition, but at least it can be benchmarked, and the hit
ratio looked at, and then removed should it be redundant. I've ported our crusty in-house DSL
compiler to kj framework and the cache really helps there, because of how the grammar is
written. Of course, the grammar could be fixed, but the cache is a decent stop-gap.
An aside: the parsing framework is a joy to work with, as long as one doesn't need to decode
error messages. I'll have to eventually look at more obvious places to add compile-time error
catching to. Usually, it's some low level function applicator in the framework that bombs out,
with the real problem far away. Visual Studio's approach to error reporting doesn't help either.
Cheers, Kuba