zevv / npeg

PEGs for Nim, another take
MIT License
330 stars 22 forks source link

Attach line information to generate functions #37

Closed Varriount closed 1 year ago

Varriount commented 3 years ago

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.

zevv commented 3 years ago

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 commented 3 years ago

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 commented 1 year ago

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