Allow source plugins to fire even when parsing fails
Motivation
Background: I want to write a plugin that makes it possible to use Idris's !-notation in Haskell.
GHC already parses prefix-! in expressions. When it encounters them, it replaces that node in the AST with a hole, and adds an error messages containing the actual expression.
So by combining the AST and error messages, I have all the information I need to construct a modified AST, emulating !-notation.
The only problem is that a plugin's parsedResultAction
is only called if the parser hasn't produced any errors.
Proposal
Add some way to have a plugin's parsedResultAction
(or similar) called even when the parser has produced errors, assuming it has successfully produced an AST (i.e. assuming the ParseResult
is POk
). The plugin action should receive the list of warnings and errors, and return a new list of warnings and errors. Compilation only proceeds if the resulting list does not contain any errors.
This seems to be doable with some straightforward changes in GHC.Driver.Main, which I'd be happy to implement. However, I'm not sure about the design. My suggestion would be to change the type of parsedResultAction
from
parsedResultAction ::
[CommandLineOption] -> ModSummary -> HsParsedModule -> Hsc HsParsedModule
to
parsedResultAction ::
[CommandLineOption] -> ModSummary -> HsParsedModule -> Messages PsMessage -> Hsc (HsParsedModule, Messages PsMessage)