npeg icon indicating copy to clipboard operation
npeg copied to clipboard

Attach line information to generate functions

Open Varriount opened this issue 4 years ago • 2 comments

NPeg doesn't appear to attach line information to its generated code. For instance, when the backtrace depth has been exceeded, a stack trace like the following will occur:

.\sample.nim(17) sample
..\npeg\src\npeg.nim(134) match
..\npeg\src\npeg\stack.nim(31) fn`gensym15613
..\npeg\src\npeg\stack.nim(27) grow
Error: unhandled exception: backtrace stack overflow, depth>1024 [NPegException]

Ideally, the traceback would indicate (either directly, or via the generated function name) what rule caused the error.

Varriount avatar Sep 09 '21 19:09 Varriount

Hmm, I'll check how line info is exactly propagated at this time; most of the line info should be copied, but I guess there are some points where injected code does not properly get linked to a source rule.

zevv avatar Sep 09 '21 20:09 zevv

This one is not so easy to fix I'm afraid: NPeg propagates line info at compile time to make sure any compilation or syntax errors end up pointing to the right rule, but currently there is no original lineinfo available at run time.

My advice for this one would be to run with -d:npegTrace to see where your grammar was heading when your overflow happened. I'll leave this ticket open as a reminder, when I find some time I'll have a better look to see if this can be enhanced.

zevv avatar Sep 10 '21 06:09 zevv

Closing this, feel free to reopen if it's still relevant.

zevv avatar Nov 04 '22 18:11 zevv