d11wtq / whittle

Whittle: A small LALR(1) Parser in Pure Ruby (Not a Generator)
https://github.com/d11wtq/whittle
MIT License
115 stars 1 forks source link

error reporting should indicate line position #1

Closed gregwebs closed 12 years ago

gregwebs commented 12 years ago

It isn't always easy to determine the exact parsing issue from the current error information. My ideal error report would include the existing information, but also give the line contents and the exact character on which the parse failed. The ideal way to show this would be with 2 lines where the second has a '^' underneath the character of the first line where the parse failed.

d11wtq commented 12 years ago

Excellent point. This should be really easy to do. All the information is there, so I'll try and get this in this evening's release.

d11wtq commented 12 years ago

This is now in 0.0.7. Example:

/Users/chris/coding/whittle/lib/whittle/parser.rb:277:in `error': Parse error: expected "," but got "-" on line 4. (Whittle::ParseError)

Exact region marked...

fourteen, fifteen - sixteen, seventeen
              ... ^ ... right here
gregwebs commented 12 years ago

Tested out- works great. thank you!

I think you could consider getting rid of "Exact region marked..." and change "right here" accordingly to something like "error occurred here"

d11wtq commented 12 years ago

Good point. I'll change the wording, thanks :)