gracelang / minigrace

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

missing brace after class generates bad error message #306

Closed apblack closed 5 years ago

apblack commented 5 years ago

This program

class annotationsNode(annotations)
    inherit baseNode
    def kind is public = "annonations"
    var anns is public = annotations

    method childrenDo(anAction:Procedure1) {
        anns.do(anAction)
    }
}

(which is in file _.../tests/known-failing/missing_brace_afterclass.grace) is missing the opening brace at the end of the first line. But instead of getting an error at that point (inherit would be taken as the next part of the method name, but it's a reserved word), we get this error:

Syntax error: on closing a block, the indentation must return to that of the line on which the block was opened (0)
    in "missing brace after class" (line 8, column 1-4)

I think that what's going on here is that everything up until the opening brace on line 6 is taken as a single continued line. Line 7 anns.do ... is then treated as the indented body of the block. The closing brace on line 8 is then expected to close the continued line 1. This all happens in the lexer, before the parser ever gets to complain about the method name that contains a reserved word.

If this is right, I'm not sure how to solve this problem. Perhaps treating the lexer as producing one token at a time, rather than running it on the whole program?

apblack commented 5 years ago

Commit 98535dd8d adds a check to the lexer for a continuation line that starts with a keyword that indicates that it must be a new statement. This example is added as a test in commit 2eadd4f6