Closed uucidl closed 8 years ago
It blew on a file of relative small size (13K)
Nicolas on Tue, Jul 26 2016:
auto searcher = h_indirect(); h_bind_indirect( searcher, h_choice(parser, h_right(h_ch_range(0x01, 0xff), searcher), nullptr)); return searcher
This should work well for a context-free backend.
With packrat, this blows up because that backend is essentially recursive descent and cannot easily "forget about" a combinator it has entered, even if it does nothing more with the result. You would be asking for tail-recursion, basically.
What you can do instead:
auto pre = h_right(h_and(h_not(parser)), h_ch_range(1,255));
return h_sequence(h_many(pre), parser, 0);
This should run with constant stack overhead wrt. parser
.
Indeed it works! thanks
On my dataset, where the match is rare, the parser version works measurably slower than calling h_parse
repeatedly manually on every byte.
As I was exploring how to search for matches using a hammer parser I came up with the following:
It works for small inputs, however as soon as I threw a real world file at it, I blew up my stack in a series of: (tested on windows)