Open Techcable opened 2 years ago
Possibly related: https://github.com/janet-lang/janet/issues/255
In #255, @bakpakin mentioned an "original peg debugging script", but I can't find that anywhere :(
I learned about Margaret after filing this issue, and the debugging tools there look very useful (although I haven't used them a single time).
I think in terms of "peg debugging", there are two options:
peg.c
.I think option (2) probably looks better. We could have the CI mark any incompatibilities between the two as warnings. That way we won't block development, and we could eventually get around to fixing any incompatibilities.
With respect to "original peg debugging script", perhaps @bakpakin meant the bit posted by @andrewchambers initially:
(peg/match (freeze (merge large-g {:main ...})))
FWIW, margaret now supports all PEG specials (including the newer additions like sub
and split
) and AFAIK there aren't any serious incompatibilies.
There are a few differences mentioned here, but I doubt those make a big difference in practice.
Working with PEG parsers for the first time. They are very cool (along with the rest of Janet).
However, debugging a failed "peg/match" can be difficult. Although PEG operates with an internal stack, it is not printed out on errors.
Ocassionally I will overflow the stack or encounter some other sort of error deep in matching. It is pretty easily to write left-recursive grammar accidentally. In that case,
error: peg/match recursed too deeply
is not a particularly helpful error message. 😉It would be nice to (somehow) track the internal PEG stack and print it on error.
If the performance cost of this is unacceptable, we could keep it behind a debug flag.
Maybe there is some sort of compromise (short of full stack traces) that could track the PEG stack's last three or four positions?
Ideally, this would be the first step toward more tools to debug PEG parsers. An (optional)
peg/debug
submodule would be awesome.