moonscript icon indicating copy to clipboard operation
moonscript copied to clipboard

Get column range instead of only line for parse errors?

Open aleclarson opened this issue 7 years ago • 4 comments

Is there a way to know the specific {{first_line, first_column}, {last_line, last_column}} range of a parse error? This would be useful for code highlighting in my text editor. Currently, I just highlight the entire line.

aleclarson avatar Apr 10 '18 17:04 aleclarson

For parse errors? Probably not. When a parse error happens it guesses where the error was by returning the greatest position in the input code that it was able to parse up to. It doesn't know where the error stops since it doesn't parse past where it fails.

In order to do that, the parser would have to parse invalid code until to comes across valid code. I guess it might be possible to creating error boundaries for common things like strings, tables, and comprehensions, but it would be a complicated change.

leafo avatar Apr 11 '18 06:04 leafo

I recently ran into a compile error, and I noticed there's not even a line number associated with it. Is this normal for compile errors?

Compile error: Short-dot syntax must be called within a with block

aleclarson avatar Apr 13 '18 15:04 aleclarson

It seems like it's a compiler error when the parser should be the one erroring (which is quite difficult). A lot of the times, the compiler will give an error without a line. It's normal, but it is bad design/a bug.

RyanSquared avatar Apr 13 '18 16:04 RyanSquared

The compiler error not having access to the code position is a bug, it should have it but some refactoring needs to be done

leafo avatar Apr 13 '18 18:04 leafo