ohmtech-rdi / eurorack-blocks

Software to Hardware Prototyping for Eurorack using C++, Max/Gen~ or Faust
Other
296 stars 19 forks source link

Enhance length error reports #555

Closed ohmtech-rdi closed 1 year ago

ohmtech-rdi commented 1 year ago

This PR enhances error reports for length errors, typically missing an unit, which is very common.

Before:

Kick.erbui:20:21: error: Expected HP literal, centimeter literal or millimeter literal
         position 2hp, 95.3
                       ^

After:

Kick.erbui:20:25: error: Expected mm, cm, or hp unit
         position 2hp, 95.3
                       ~~~~^
Kick.erbui:20:25: note: did you mean '95.3mm'?
         position 2hp, 95.3mm
                       ~~~~^~

It is also an exploration on how to improve error reporting at the PEG level.

ohmtech-rdi commented 1 year ago

We need to rethink how it is done. In a nutshell we expect some expression, and we might get another one. We then need to parse one token of a different type, and emit an error because the token type is wrong.

For example with length, we expect a length with an unit, but we can test the token to see if it would fall in the category of a number literal (that is, without units), and then make the error based on that. But we also need to consider EOF, tokens like an early }, and so on.