ohm icon indicating copy to clipboard operation
ohm copied to clipboard

Improve error messages resulting from bad "operation prototype strings", etc.

Open alexwarth opened this issue 10 years ago • 0 comments

Right now if you specify an invalid operation prototype string when you add an operation to a semantics, e.g.,

MyGrammar.semantics().addOperation('myOperation(x, y', {...})

you'll get a generic Ohm error message like this:

> 1 | myOperation(x, y
                      ^
Expected ")"

which is not very nice.

A couple of things that would make it better:

(1) Give a little context before showing the snippet of the input and the failures / expectations (2) Don't include a line number

E.g.,

Invalid operation prototype string:

  myOperation(x, y
                  ^
Expected ")"

(Thing (2) suggests that we should have a better API for getting messages out of a MatchFailure. At the moment you can either get a one-size-fits-all message via the message property, or build your own using the getRightmostFailures() method. It would be nice to add a getMessage method that lets you specify some options, e.g., mf.getMessage({includeLineNumbers: false, includeFluffyFailures: true, ...}).)

alexwarth avatar Sep 22 '15 06:09 alexwarth