ligasgr / intellij-xquery

Plugin to support XQuery in Intellij Idea
Apache License 2.0
35 stars 23 forks source link

Recover parsing state on errors. #199

Open rhdunn opened 8 years ago

rhdunn commented 8 years ago

If the intellij-xquery parser encounters an error, the code that follows the error point is not parsed correctly. This has the following effects:

  1. Subsequent errors are masked by the starting error -- this is worse if the initial error is due to a problem with the xquery parser (like issue #198).
  2. Information in the module such as functions that follow the error is not processed -- this causes calls to those functions to be incorrectly reported as errors.
  3. Automatic indentation is broken when entering code after the point of the error.

It would be helpful for the parser to recover as close as possible to the next valid start/recover point. I understand that this will be complex.

At the basic level, this should be able to recover to the start of the next statement such as if, for, let, and declare function statements.

ligasgr commented 8 years ago

Unfortunately with the very context-sensitive nature of the language and with the fact that in Main Module you can have any expression at the end of the file, it's nearly impossible to get this done right. If you could please prepare some examples with the expected behaviour it would be much easier to at least check if this is achievable.

rhdunn commented 8 years ago

The immediate case is related to issue #198:

declare function a($x, $y) {
    if ($x < (2*$y)) then
        $y
    else
        $x
};

declare function b($x) {
    ()
};

Here, the code in the $x and $y part of the if will not be validated, and function b will not be exposed to the user when referring to it in another module.