<commit_before>> {-# OPTIONS_GHC -fglasgow-exts #-}

> -- | 
> -- Module      : Ivor.Plugin
> -- Copyright   : <NAME>
> -- Licence     : BSD-style (see LICENSE in the distribution)
> --
> -- Maintainer  : <EMAIL>
> -- Stability   : experimental
> -- Portability : portable
> -- 
> -- Plugin loader

> module Ivor.Plugin(Ivor.Plugin.load) where

> import Ivor.TT
> import System.Plugins as Plugins
> import Text.ParserCombinators.Parsec

> -- | Load the given plugin file (which should be a full path to a .o file)
> -- and update the Context.
> -- Plugins must contain the symbol
> -- @initialise :: Context -> (Context, Maybe (Parser ViewTerm))@
> -- which updates the context and returns any parser extensions.

> load :: FilePath -> Context -> IO (Context, Maybe (Parser ViewTerm))
> load fn ctxt = do 
>          mv <- Plugins.load_ fn [] "initialise"
>          -- mv <- Plugins.load fn [] ["/Users/edwin/.ghc/i386-darwin-6.6.1/package.conf"] "initialise"
>          initialise <- case mv of
>                  LoadFailure msg -> fail $ "Plugin loading failed: " ++ (show msg)
>                  LoadSuccess _ v -> return v
>          return $ initialise ctxt<commit_msg>Changed Plugins<commit_after>> {-# OPTIONS_GHC -fglasgow-exts #-}

> -- | 
> -- Module      : Ivor.Plugin
> -- Copyright   : <NAME>
> -- Licence     : BSD-style (see LICENSE in the distribution)
> --
> -- Maintainer  : <EMAIL>
> -- Stability   : experimental
> -- Portability : portable
> -- 
> -- Plugin loader

> module Ivor.Plugin(Ivor.Plugin.load) where

> import Ivor.TT

> import System.Plugins as Plugins
> import Text.ParserCombinators.Parsec

> -- | Load the given plugin file (which should be a full path to a .o or
> -- .hs file) and update the Context. If it is a .hs file, it will be
> -- compiled if necessary.
> -- Plugins must contain the symbol
> -- @plugin_context :: Monad m => Context -> m Context
> -- which updates the context, and optionally a symbol
> -- @plugin_parser :: Parser ViewTerm
> -- which adds new parsing rules. Returns the new context and the
> -- extra parsing rules, if any.

> load :: FilePath -> Context -> IO (Context, Maybe (Parser ViewTerm))
> load fn ctxt = do 
>          objIn <- compilePlugin fn
>          obj <- case objIn of
>                    Left errs -> fail errs
>                    Right ok -> return ok
>          contextMod <- Plugins.load_ obj [] "plugin_context"
>          -- mv <- Plugins.load fn [] ["/Users/edwin/.ghc/i386-darwin-6.6.1/package.conf"] "initialise"
>          (mod, contextFn) <- case contextMod of
>                  LoadFailure msg -> fail $ "Plugin loading failed: " ++
>                                              show msg
>                  LoadSuccess mod v -> return (mod, v)
>          parserMod <- Plugins.reload mod "plugin_parser"
>          parserules <- case parserMod of
>                  LoadFailure msg -> return Nothing
>                  LoadSuccess _ v -> return $ Just v
>          ctxt' <- case contextFn ctxt of
>                      Just x -> return x
>                      Nothing -> fail "Error in running plugin_context"
>          return $ (ctxt', parserules)

Make a .o from a .hs, so that we can load Haskell source as well as object
files

> compilePlugin :: FilePath -> IO (Either String FilePath)
> compilePlugin hs 
>     | isExt ".hs" hs =
>         do status <- make hs []
>            case status of
>               MakeSuccess c out -> return $ Right out
>               MakeFailure errs -> return $ Left (concat (map (++"\n") errs))
>     | isExt ".o" hs = return $ Right hs
>     | elem '.' hs = return (Left $ "unrecognised file type " ++ hs)
>     | otherwise = compilePlugin (hs++".o")
>   where isExt ext fn = case span (/='.') fn of
>                           (file, e) -> ext == e
{'fraction_non_alphanumeric': 0.12984956452889945, 'fraction_numerical': 0.003167062549485352, 'mean_word_length': 2.015115354017502, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 112, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4843455', 'n_tokens_mistral': 1148, 'n_tokens_neox': 1101, 'n_words': 385}