diff --git a/rlp.cabal b/rlp.cabal index c1bedaa..660a3d8 100644 --- a/rlp.cabal +++ b/rlp.cabal @@ -23,6 +23,7 @@ library , GM , Compiler.RLPC , Compiler.RlpcError + , Compiler.JustRun , Core.Syntax , Core.Examples , Core.Utils diff --git a/src/Compiler/JustRun.hs b/src/Compiler/JustRun.hs new file mode 100644 index 0000000..df28db5 --- /dev/null +++ b/src/Compiler/JustRun.hs @@ -0,0 +1,46 @@ +{-| +Module : Compiler.JustRun +Description : No-BS, high-level wrappers for major pipeline pieces. + +A collection of wrapper functions to demo processes such as lexing, parsing, +type-checking, and evaluation. This module intends to export "no-BS" functions +that use Prelude types such as @Either@ and @String@ rather than more complex +types such as @RLPC@ or @Text@. +-} +module Compiler.JustRun + ( justLexSrc + , justParseSrc + , justTypeCheckSrc + ) + where +---------------------------------------------------------------------------------- +import Core.Lex +import Core.Parse +import Core.HindleyMilner +import Core.Syntax (Program') +import Compiler.RLPC +import Control.Arrow ((>>>)) +import Control.Monad ((>=>)) +import Data.Text qualified as T +import Data.Function ((&)) +import GM +---------------------------------------------------------------------------------- + +justLexSrc :: String -> Either RlpcError [CoreToken] +justLexSrc s = lexCoreR (T.pack s) + & fmap (map $ \ (Located _ _ _ t) -> t) + & rlpcToEither + +justParseSrc :: String -> Either RlpcError Program' +justParseSrc s = parse (T.pack s) + & rlpcToEither + where parse = lexCoreR >=> parseCoreProgR + +justTypeCheckSrc :: String -> Either RlpcError Program' +justTypeCheckSrc s = typechk (T.pack s) + & rlpcToEither + where typechk = lexCoreR >=> parseCoreProgR >=> checkCoreProgR + +rlpcToEither :: RLPC e a -> Either e a +rlpcToEither = evalRLPC def >>> fmap fst + diff --git a/src/Compiler/RLPC.hs b/src/Compiler/RLPC.hs index 5e69e16..266e06a 100644 --- a/src/Compiler/RLPC.hs +++ b/src/Compiler/RLPC.hs @@ -100,7 +100,6 @@ evalRLPCIO o m = do -- TODO: errors Left e -> throwIO e Right a -> pure a - data RLPCOptions = RLPCOptions { _rlpcLogFile :: Maybe FilePath