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

Feedback for peg #255

Closed
andrewchambers opened this issue Jan 15, 2020 · 4 comments
Closed

Feedback for peg #255

andrewchambers opened this issue Jan 15, 2020 · 4 comments

Comments

@andrewchambers
Copy link
Member

andrewchambers commented Jan 15, 2020

  1. When debugging a large peg, sometimes its really hard to know why a given rule failed. This reminded me of this article on a regex debugger https://eigenstate.org/notes/regex-debug . Not sure if it is applicable, or how a trace/step/debug view into pegs would look. But could be quite neat to step/trace a peg.

  2. When developing a large peg, sometimes you want to run subrules by hand to test them, this would be much easier if peg/match and/or peg/compile let you specify the entry rule somehow.

This is possible, though sort of verbose using :

(peg/match (freeze (merge large-g {:main ...})))
@bakpakin
Copy link
Member

For testing a subpeg, why not (peg/match (bigpeg :subrule) "...")? That should help, I think. If you are compiling the peg ahead of time, the names of given rules is removed at compile time. I don't think it's needed to include that information in the compiled peg, but I suppose it could be useful for debugging.

As for tracing pegs, I think that would be a neat idea. At least, we could show the disassembly in a nice format so people could hopefully understand a bit about what is happening. Stepping maybe harder, but is not out of the realm of possibility.

@andrewchambers
Copy link
Member Author

andrewchambers commented Jan 16, 2020

(peg/match (bigpeg :subrule) "...") doesn't work because it only extracts the rule key, but not any subrules this rule depends on.

@sogaiu
Copy link
Contributor

sogaiu commented Dec 29, 2020

It's not complete yet, but I've been working on an implementation of peg/match in Janet: https://gitlab.com/sogaiu/margaret

It started out as bakpakin's code from his PEG blog post and is evolving from there.

In the process I have started adding a little bit of tracing output. If it appropriately supports enough of the native version's constructs, may be it could be useful for debugging some PEGs?

(It doesn't quite have enough of the specials to manage the Janet grammar on the website, but I'm hoping to get there soonish.)

Update: AFAICT, margaret's implementation should be on the complete side.

@bakpakin
Copy link
Member

bakpakin commented Jul 9, 2022

Closing this for now - the original peg debugging script should work correctly.

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

3 participants