TX-2 / TX-2-simulator

Simulator for the pioneering TX-2 computer
https://tx-2.github.io/
MIT License
21 stars 2 forks source link

Improve assembler error messages #69

Open jamesyoungman opened 2 years ago

jamesyoungman commented 2 years ago

Is your feature request related to a problem? Please describe.

The assembler's error-handling strategy is modeled after https://eyalkalderon.com/blog/nom-error-recovery/ but our use of the "placeholder" denoting that we came across an invalid input is not comprehensive.

For example, this line of input is perfectly valid:

100|      REX₆₆   200     ** Set X₆₆ to 200.

If we add an extra symbol in there like this:

100|      REX₆₆   EXTRA 200     ** Set X₆₆ to 200.

We get a somewhat confusing error:

11:508: expected newline after a program instruction
11:508: expected end-of-file
2022-05-16T08:51:58.375986Z ERROR assemble{input="assembler/examples/hello.tx2as" output="hello.tape"}: tx2m4as: assembly failed: AsmFail(SyntaxError { line: 11, columns: Some((508, 3505)), msg: "expected newline after a program instruction" })
line 11, column 509: expected newline after a program instruction

Describe the solution you'd like An error message which is more understandable, making use of the existing LocatedSpan code to show the invalid/unsupported input.

Describe alternatives you've considered I'm hoping that the overall pattern described in Eyal Kalderon's blog post will be sufficient to give a good user experience.

Additional context See above for an example output.