0

As Happy generates a state machine and runs through it upon parsing, I presume when hitting a parse error it will be able to tell what tokens it was expecting.

Is there anyway to get this information as part of printing the error? Currently I'm just printing out the location in the source of the failing token and what sort of token is failing, but it would be good to tell the user what sort of token is expected.

Can I get this sort of information and feed it into my error handling function, and if so how?

Clinton
  • 22,361
  • 15
  • 67
  • 163
  • 1
    TL;DR from the duplicate: there was a [PR](https://github.com/simonmar/happy/pull/46) for this which has been merged and is in the latest Happy version. Although the documentation has not been built recently, it is kept up to date. Looks like `%errorhandlertype explist` is what you need to be able to get more of this information. I haven't found a working example of this feature though. – Alec Jun 02 '17 at 06:28
  • With Happy 1.19.7 or newer, [here](https://github.com/harpocrates/language-rust/blob/0e02e21c389cb56c77f71b902288b195ed273af6/src/Language/Rust/Parser/Internal.y#L74) is a working grammar that uses this feature. – Alec Sep 15 '17 at 18:01
  • 1
    By the way, here's a [newer documentation](https://monlih.github.io/happy-docs) of Happy that I built recently. It includes the added documentation for the `%errorhandlertype` option. – Monolith Mar 21 '21 at 20:59

0 Answers0