diff options
Diffstat (limited to 'docs/users_guide/extending_ghc.rst')
-rw-r--r-- | docs/users_guide/extending_ghc.rst | 45 |
1 files changed, 23 insertions, 22 deletions
diff --git a/docs/users_guide/extending_ghc.rst b/docs/users_guide/extending_ghc.rst index 4a987bca87..b2b555c005 100644 --- a/docs/users_guide/extending_ghc.rst +++ b/docs/users_guide/extending_ghc.rst @@ -754,23 +754,24 @@ in the source code as well as the original syntax tree of the compiled module. :: - parsed :: [CommandLineOption] -> ModSummary -> HsParsedModule - -> (Messages PsWarning, Messages PsError) - -> Hsc (HsParsedModule, (Messages PsWarning, Messages PsError) + parsed :: [CommandLineOption] -> ModSummary + -> ParsedResult -> Hsc ParsedResult The ``ModSummary`` contains useful -meta-information about the compiled module. The ``HsParsedModule`` contains the -lexical and syntactical information we mentioned before. The result that you -return will change the result of the parsing. If you don't want to change the -result, just return the ``HsParsedModule`` that you received as the argument. +meta-information about the compiled module. The ``ParsedResult`` contains a +``HsParsedModule``, which contains the lexical and syntactical information we +mentioned before. The result that you return will change the result of the +parsing. If you don't want to change the result, just return the +``ParsedResult`` that you received as the argument. If the parser encounters any errors that prevent an AST from being constructed, the plugin will not be run, but other kinds of errors, as well as warnings, -will be given to the plugin via the ``Messages`` tuple. This allows you to -modify, remove, and add warnings or errors before they are displayed to the -user, although in most cases, you will likely want to return the tuple -unmodified. The parsing pass will fail if the returned ``Messages PsError`` -collection is not empty after all parsing plugins have been run. +will be given to the plugin via the ``PsMessages`` value of the +``ParsedResult``. This allows you to modify, remove, and add warnings or errors +before they are displayed to the user, although in most cases, you will likely +want to return the messages unmodified. The parsing pass will fail if the +``Messages PsError`` collection inside the return ``ParsedResult`` is not empty +after all parsing plugins have been run. Type checked representation ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -892,6 +893,7 @@ displayed. import GHC.Types.Avail import GHC.Utils.Outputable import GHC.Hs.Doc + import GHC plugin :: Plugin plugin = defaultPlugin @@ -902,15 +904,14 @@ displayed. , interfaceLoadAction = interfaceLoadPlugin } - parsedPlugin :: [CommandLineOption] -> ModSummary -> HsParsedModule - -> (Messages PsWarning, Messages PsError) - -> Hsc (HsParsedModule, (Messages PsWarning, Messages PsError)) - parsedPlugin _ _ pm msgs@(warns, errs) + parsedPlugin :: [CommandLineOption] -> ModSummary + -> ParsedResult -> Hsc ParsedResult + parsedPlugin _ _ parsed@(ParsedResult pm msgs) = do dflags <- getDynFlags - liftIO $ putStrLn $ "parsePlugin: \n" ++ (showSDoc dflags $ ppr $ hpm_module pm) - liftIO $ putStrLn $ "parsePlugin warnings: \n" ++ (showSDoc dflags $ ppr warns) - liftIO $ putStrLn $ "parsePlugin errors: \n" ++ (showSDoc dflags $ ppr errs) - return (pm, msgs) + liftIO $ putStrLn $ "parsePlugin: \n" ++ (showSDoc dflags $ ppr $ hpm_module pm) + liftIO $ putStrLn $ "parsePlugin warnings: \n" ++ (showSDoc dflags $ ppr $ psWarnings msgs) + liftIO $ putStrLn $ "parsePlugin errors: \n" ++ (showSDoc dflags $ ppr $ psErrors msgs) + return parsed renamedAction :: [CommandLineOption] -> TcGblEnv -> HsGroup GhcRn -> TcM (TcGblEnv, HsGroup GhcRn) renamedAction _ tc gr = do @@ -1320,10 +1321,10 @@ Defaulting plugins have a single access point in the `GHC.Tc.Types` module , deProposalCts :: [Ct] -- ^ The constraints against which defaults are checked. } - + type DefaultingPluginResult = [DefaultingProposal] type FillDefaulting = WantedConstraints -> TcPluginM DefaultingPluginResult - + -- | A plugin for controlling defaulting. data DefaultingPlugin = forall s. DefaultingPlugin { dePluginInit :: TcPluginM s |