begin hm visualiser
This commit is contained in:
@@ -15,10 +15,11 @@ import GM
|
||||
|
||||
driver :: RLPCIO ()
|
||||
driver = forFiles_ $ \f ->
|
||||
withSource f (lexCoreR >=> parseCoreProgR >=> evalProgR)
|
||||
withSource f (lexCoreR >=> parseCoreProgR >=> undefined >=> evalProgR)
|
||||
|
||||
driverSource :: T.Text -> RLPCIO ()
|
||||
driverSource = lexCoreR >=> parseCoreProgR >=> evalProgR >=> printRes
|
||||
driverSource = lexCoreR >=> parseCoreProgR
|
||||
>=> undefined >=> evalProgR >=> printRes
|
||||
where
|
||||
printRes = liftIO . print . view _1
|
||||
|
||||
|
||||
12
app/Main.hs
12
app/Main.hs
@@ -2,6 +2,7 @@
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
module Main where
|
||||
----------------------------------------------------------------------------------
|
||||
import Control.Lens hiding (argument)
|
||||
import Compiler.RLPC
|
||||
import Compiler.RlpcError
|
||||
import Control.Exception
|
||||
@@ -23,6 +24,7 @@ import Control.Lens.Combinators hiding (argument)
|
||||
|
||||
import CoreDriver qualified
|
||||
import RlpDriver qualified
|
||||
import Server qualified
|
||||
----------------------------------------------------------------------------------
|
||||
|
||||
optParser :: ParserInfo RLPCOptions
|
||||
@@ -74,7 +76,11 @@ options = RLPCOptions
|
||||
<> metavar "rlp|core"
|
||||
<> help "the language to be compiled -- see README"
|
||||
)
|
||||
<*> some (argument str $ metavar "FILES...")
|
||||
<*> switch
|
||||
( long "server"
|
||||
<> short 's'
|
||||
)
|
||||
<*> many (argument str $ metavar "FILES...")
|
||||
where
|
||||
infixr 9 #
|
||||
f # x = f x
|
||||
@@ -107,7 +113,9 @@ mmany v = liftA2 (<>) v (mmany v)
|
||||
main :: IO ()
|
||||
main = do
|
||||
opts <- execParser optParser
|
||||
void $ evalRLPCIO opts dispatch
|
||||
if opts ^. rlpcServer
|
||||
then Server.server
|
||||
else void $ evalRLPCIO opts dispatch
|
||||
|
||||
dispatch :: RLPCIO ()
|
||||
dispatch = getLang >>= \case
|
||||
|
||||
@@ -15,5 +15,5 @@ import GM
|
||||
|
||||
driver :: RLPCIO ()
|
||||
driver = forFiles_ $ \f ->
|
||||
withSource f (parseRlpProgR >=> desugarRlpProgR >=> evalProgR)
|
||||
withSource f (parseRlpProgR >=> undefined >=> desugarRlpProgR >=> evalProgR)
|
||||
|
||||
|
||||
68
app/Server.hs
Normal file
68
app/Server.hs
Normal file
@@ -0,0 +1,68 @@
|
||||
{-# LANGUAGE LambdaCase, BlockArguments #-}
|
||||
{-# LANGUAGE DerivingVia #-}
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
module Server
|
||||
( server
|
||||
)
|
||||
where
|
||||
--------------------------------------------------------------------------------
|
||||
import GHC.Generics (Generic, Generically(..))
|
||||
import Data.Text (Text)
|
||||
import Data.Text qualified as T
|
||||
import Data.Text.IO qualified as T
|
||||
import Data.Pretty
|
||||
import Data.Aeson
|
||||
import Control.Applicative
|
||||
import Control.Monad
|
||||
import Control.Concurrent
|
||||
import Network.WebSockets qualified as WS
|
||||
|
||||
import Data.Functor.Foldable
|
||||
|
||||
import Misc.CofreeF
|
||||
import Rlp.AltSyntax
|
||||
import Rlp.HindleyMilner
|
||||
import Rlp.AltParse
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
server :: IO ()
|
||||
server = do
|
||||
WS.runServer "127.0.0.1" 9002 application
|
||||
|
||||
application :: WS.ServerApp
|
||||
application pending =
|
||||
WS.acceptRequest pending >>= talk
|
||||
|
||||
newtype Command = Annotate Text
|
||||
|
||||
instance FromJSON Command where
|
||||
parseJSON = withObject "command object" $ \v -> do
|
||||
cmd :: Text <- v .: "command"
|
||||
case cmd of
|
||||
"annotate" -> Annotate <$> v .: "data"
|
||||
_ -> empty
|
||||
|
||||
data Response = Annotated Value
|
||||
| PartiallyAnnotated Value
|
||||
deriving (Generic)
|
||||
deriving (ToJSON)
|
||||
via Generically Response
|
||||
|
||||
talk :: WS.Connection -> IO ()
|
||||
talk conn = forever $ do
|
||||
msg <- WS.receiveData @Text conn
|
||||
T.putStrLn $ "received: " <> msg
|
||||
case decodeStrictText msg of
|
||||
Just c -> doCommand c
|
||||
Nothing -> WS.sendTextData @Text conn "\"error while parsing json\""
|
||||
|
||||
doCommand :: Command -> IO ()
|
||||
doCommand (Annotate s) = undefined
|
||||
|
||||
parse = undefined
|
||||
|
||||
serialisedAnnotated :: Cofree (RlpExprF PsName) (Type PsName)
|
||||
-> Value
|
||||
serialisedAnnotated = cata \case
|
||||
t :<$ e -> object [ "e" .= e, "type" .= rout @Text t ]
|
||||
|
||||
Reference in New Issue
Block a user