gracelang / minigrace

Self-hosting compiler for the Grace programming language
39 stars 22 forks source link

Bad error message for reserved word #321

Closed apblack closed 11 months ago

apblack commented 4 years ago

I got this error message:

constantScope.grace[111:17]: Syntax error: a parameter list beginning with a '(' must end with a ')'.
 110: 
 111: method variable (class) name (cannonicalName) kind (knd) {
----------------------^

The problem is that the parser found the reserved word class while it was looking for an identifier. But the message doesn't say this.

apblack commented 4 years ago

This one is quite similar:

constantScope.grace[102:9]: Syntax error: a sequence beginning with a '[' must end with a ']'.
 101:     obj::graceObjectAttributes,
 102:     bool:booleanAttributes,
--------------^

Here the parser found the reserved token : while it was looking for the rest of an expression.

Can we manage a message like

I was expecting an expression, but found the reserved token :

or

I was expecting a parameter name, but found the reserved token class

apblack commented 11 months ago

The first example was fixed (with the help of @geeksam) in commit 580ad15ba0b1fce058da915a2b3a81173ca5a3b9. When an identifier is expected but not found, the parser not explicitly checks for a reserved word, and tells the user that the reserved word cannot be used as identifier.

The second example is not fixed, and I'm not clear how it might be. As opposed to the case where one is parsing a parameter list, a sequence constructor contains arbitrary expressions, and saying that a close bracket was expected may be the best we can do.