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

-- 
You received this message because you are subscribed to the Google Groups 
"Cap'n Proto" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
Visit this group at https://groups.google.com/group/capnproto.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/capnproto/1de280d3-e818-4c4b-af5c-126916267116%40googlegroups.com.

Reply via email to