Compiler.JustRun
This commit is contained in:
@@ -23,6 +23,7 @@ library
|
||||
, GM
|
||||
, Compiler.RLPC
|
||||
, Compiler.RlpcError
|
||||
, Compiler.JustRun
|
||||
, Core.Syntax
|
||||
, Core.Examples
|
||||
, Core.Utils
|
||||
|
||||
46
src/Compiler/JustRun.hs
Normal file
46
src/Compiler/JustRun.hs
Normal file
@@ -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
|
||||
|
||||
@@ -101,7 +101,6 @@ evalRLPCIO o m = do
|
||||
Left e -> throwIO e
|
||||
Right a -> pure a
|
||||
|
||||
|
||||
data RLPCOptions = RLPCOptions
|
||||
{ _rlpcLogFile :: Maybe FilePath
|
||||
, _rlpcDebugOpts :: DebugOpts
|
||||
|
||||
Reference in New Issue
Block a user