Debugging Menhir - how?

method call threw Pholyglot__Parser.MenhirBasics.Error.

This is slightly annoying. I have an error in my grammar and need to trace through what’s happening. Any tips…? I can look at the generated parser.ml file for clues, but sometimes it’s not enough. :frowning_face:

Full error message (probably irrelevant):

File "lib/test.ml", line 1147, characters 0-665: method call threw Pholyglot__Parser.MenhirBasics.Error.
  Raised at file "lib/parser.ml" (inlined), line 8, characters 6-17
  Called from file "lib/parser.ml", line 2378, characters 14-21
  Called from file "lib/test.ml", line 1158, characters 8-71
  Called from file "runtime-lib/runtime.ml", line 502, characters 15-19
  Called from file "runtime-lib/runtime.ml", line 343, characters 8-12
  Re-raised at file "runtime-lib/runtime.ml", line 346, characters 6-13
  Called from file "runtime-lib/runtime.ml", line 359, characters 15-52
  Called from file "runtime-lib/runtime.ml", line 446, characters 52-83

Hm, error seems related to keyword “public” and the fact that both class properties and class methods can start with this keyword.

  |  "class" s=CLASS_NAME "{" p=list(class_property) m=list(method_) "}" { ... }

So class_property and method_ both start with the “public” keyword, and for some reason that’s confusing for Menhir?

Maybe also related to this:

Warning: 2 states have shift/reduce conflicts.
Warning: 7 shift/reduce conflicts were arbitrarily resolved.

Hm, maybe I need to slam the two rules together, for property and method. Even tho they return very different things (property vs declaration). :stuck_out_tongue:

Hello @olleharstedt,

It seems that a hint has already been given to a similar problem (the uncaught exception MenhirBasics.Error):

To fix this kind of warning, you need to resolve conflicts by hand. Hopefully, Menhir can help you in such a tricky task by explaining conflicts in a special file .conflicts thanks to the command-line option --explain. For more information about conflicts, see Menhir Reference Manual (version 20230608).

1 Like

Here’s an example on how to use --explain from within dune: Let menhir use external modules by dune - Stack Overflow

(ocamllex lexer)

(menhir
  (modules parser)
  (flags --explain --inspection --table --dump)
)

(executable (name parse)
        (libraries menhirLib))
2 Likes