Detecting incomplete statements

Apr 19, 2012 at 10:43 AM

Is there any good way that I can detect incomplete constructs (not just "Error at line...")? Say for instance that I have a language that has block-statements using curly braces like most c-flavors do. If I pass the code

{
    var a = 5;
How can I know that I'm in a incomplete statement, and that it has to be continued until I can parse correctly?

Coordinator
Apr 19, 2012 at 5:00 PM

what do you mean "it has to be continued"? we don't have any more input.

If you mean something like "how to inject this missing } and continue" - this is one outstanding problem. Currently parser error recovery can only search forward until some key token, like ";" or "}" marking end of construct, and will try to continue from there. More advanced option is to inject the missing token if we can guess that token is missing - this is not implemented yet. 

You can try to override Grammar.ReportParserError and try to do custom recovery there. Recognize the situation and push the missing "}" into the input queue in the parsing context. 

Apr 20, 2012 at 2:55 AM

I don't need to recover, cause I do this line by line, while keeping the "incomplete" lines in memory.

In other words: I first hit Irony with "{", then it tells me that the following statement is incomplete (ie. eof not expected). Then I enter "var a = 5;", and because my application know that the prev line was incomplete, it will append the two into "{\nvar a = 5;" and try to parse that. Still getting that the statement is incomplete I enter "}" and that results in "{\nvar a = 5;\n}" beeing passed to Irony which is valid, and I get a parse-tree back.

Coordinator
Apr 20, 2012 at 3:21 AM

ah, you need then to run parser in Console mode, when it takes partial inputs - look at console sample