Parser error at or near '{'
Monday, September 14, 2009 at 03:30AM Useful and detailed error messages have always been a priority in the design of Mascara. I believe good error messages means a lot for the day-to-day productivity when using a language tool such as this.
Therefore it has always been a bit embarassing with the generic "Parser error at or near..." message in the case of syntax errors.
It just tells you that some character is wrong, not what you are supposed to write instead. Especially when learning a new language this can be infuriating. Particularily for people (like me!) who like to explore by trial and error.
In the latest Mascara release, parser error messages have been improved so they now suggest what syntax would be allowed instead of the erroneous character.
E.g. if you write
class {}
You get:
Syntax error. Unexpected '{'. Expected identifier
This tells you that an identifier is required after the keyword "class", which is hopefully a lot more useful than just the message "Parser error at or near '{'".
In many cases multiple options are legal at a given point. If you write:
class A()
The compiler will report:
Syntax error. Unexpected '('. Expected one of: '!', 'implements', 'extends', '.<', ';', '{'.
That is quite a number of tokens to choose from, but hopefully it gives a much better hint about how to fix the syntax error.
Sometimes it can be slightliy less obvious where the actual error is. Consider this:
var x =
var y = 100;
In this example I forgot to finish the first line. However the compiler will flag the "var" on the second line with "Unexpected var. Expected expression." This is because it would be legal to have the assignment value on the next line - but then "var" is not a legal expression, which causes an error.
In general it is a difficult problem to give helpful error messages for syntax errors, but hopefully these improvements is a step in the right direction, and will make it more fun to explore the language by trial and error.
Olav | Comments Off | 