Inconsistent hammer-parser-backtrace behavior
Leaving the usual hammer-parse-step
/ hammer-parse-apply
workflow with commands like finish
, step
exposes a flaw: the parser marked [current]
at the top of the stack will have the wrong value under some circumstances.
For example:
(gdb) fin
Run till exit from #0 0x00007ffff7f9cc0a in parse_many (env=0x555555575320, state=0x555555592378) at build/debug/src/parsers/many.c:26
0x00007ffff7fa3884 in perform_lowlevel_parse (state=0x555555592378, parser=0x555555575350) at build/debug/src/backends/packrat.c:43
43 tmp_res = parser->vtable->parse(parser->env, state);
Value returned is $11 = (HParseResult *) 0x555555594d38
(gdb) hpbt
[0x5555555752f0] wel [current]
[0x555555575350] (Unnamed many)
[0x555555575380] ws
[0x55555557cdf0] (Unnamed ignoreseq)
[0x55555557ce20] (Unnamed ignore)
[0x55555557cec0] lasteof
[0x555555592280] (Unnamed ignoreseq)
(gdb) fin
The parser marked as [current]
should be: [0x555555575350] (Unnamed many)
A few avenues for fixing:
- pushing new parsers on the stack as soon as
h_do_parse
is called - returning to
perform_lowlevel_parse
orparse_*
from user input should update the top of stack - folding
top_level_parse.h_do_parse_parser
into the parser stack implementation