Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

peg/match should give a stack trace on errors #1010

Open
Techcable opened this issue Aug 17, 2022 · 3 comments
Open

peg/match should give a stack trace on errors #1010

Techcable opened this issue Aug 17, 2022 · 3 comments

Comments

@Techcable
Copy link
Contributor

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.

@sogaiu
Copy link
Contributor

sogaiu commented Aug 17, 2022

Possibly related: #255

@Techcable
Copy link
Contributor Author

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:

  1. Emulate some of the the debugging features (especially stack tracing) in peg.c.
  2. Make Margaret an semi-official tool, using regression tests to keep it in sync

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.

@sogaiu
Copy link
Contributor

sogaiu commented Aug 23, 2022

With respect to "original peg debugging script", perhaps @bakpakin meant the bit posted by @andrewchambers initially:

(peg/match (freeze (merge large-g {:main ...})))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants