dlang-community / Pegged

A Parsing Expression Grammar (PEG) module, using the D programming language.
533 stars 66 forks source link

core.exception.ArraySliceError@pegged\pegged\peg.d(1930): slice [0 .. 18446744073709551612] extends past source array of length 0 #333

Closed ethindp closed 1 year ago

ethindp commented 1 year ago

I've no idea what I'm doing wrong here, but this is incredibly confusing.

For context, I'm writing a parser for the Ada grammar, I might be misrepresenting a rule but I don't think so (this appears to be in pegged itself). I'm using v 0.4.8. Has anyone else encountered this problem?

veelo commented 1 year ago

Just arrived at my hotelroom after beerconf, so I am not fit to go into much detail. But looking at the source https://github.com/PhilippeSigaud/Pegged/blob/31e02e22e075a37434354a26ef5d1dd8f58808e5/pegged/peg.d#L1930C25-L1930C25 it appears the length of errString is zero, and subtracting 4 from unsigned 0 gives you this giant index. So I would say this is a bug in Pegged, but one that is only triggered if you try to feed it an invalid grammar.

I fixed a similar error in #325. Maybe this is enough info for you to fix this by yourself, and I'll gladly accept a pull request. Otherwise I may find some time tomorrow during the DConf hackathon.

ethindp commented 1 year ago

@veelo Wouldn't Pegged report if my grammar was invalid? I'm pre-generating the code via asModule since compiling it at build time would take quite a long time.

veelo commented 1 year ago

By the way, if you get your grammar to work, it would be nice to include it as an example, if you like.

ethindp commented 1 year ago

I'd be happy to, though I'll probably want to trim the AST a lot before I do (the AST is probably going to be pretty big).

veelo commented 1 year ago

@veelo Wouldn't Pegged report if my grammar was invalid?

Yes, it is during the reporting that Pegged messes up.

veelo commented 1 year ago

I've tagged a new release: v.0.4.9. It should show up on Dub later today. Please let me know if this resolves the problem.

ethindp commented 1 year ago

@veelo I'll let you know if it (doesn't) work once Dub has it. Thank you!