14import Prelude (bind, pure, show, ($), (<<<), const)
15import Control.Monad.Error.Class (liftEither)
16import Control.Monad.Reader.Trans (ReaderT, runReaderT, ask)
17import Control.Monad.Trans.Class (lift)
18import Data.Argonaut.Core (Json)
19import Data.Argonaut.Decode (printJsonDecodeError)
20import Data.Argonaut.Decode.Class (decodeJson)
21import Data.Argonaut.Parser (jsonParser)
22import Data.Functor ((<$>))
23import Data.Bifunctor (lmap)
24import Data.Either (Either)
25import Data.Maybe (Maybe(Just))
26import Data.Monoid ((<>))
27import Effect.Aff (Aff, error)
28import Effect.Exception (Error)
29import Affjax.ResponseFormat (string)
30import Affjax.Node (post, printError)
31import Affjax.RequestBody (RequestBody (String))
32import Parsing.String as PS
33import Parsing.String.Replace as PS.Replace
35type Settings = { protocol :: String
38 , parser :: Json -> Either Error SuccessResult
41type Compiler = ReaderT Code (ReaderT Settings Aff)
43-- extracted from github:purescript/trypurescript
51 { replacement :: String
52 , replaceRange :: Maybe ErrorPosition
57 , position :: Maybe ErrorPosition
58 , suggestion :: Maybe Suggestion
62 , warnings :: Maybe (Array CompileWarning)
64-- end of imports from github:purescript/trypurescript
66successFromJson :: Json -> Either Error SuccessResult
67successFromJson json = (error <<< printJsonDecodeError) `lmap` (decodeJson json)
69askCode :: Compiler Code
72askSettings :: Compiler Settings
75liftAff :: forall a. Aff a -> Compiler a
76liftAff h = lift $ lift h
78rename :: String -> String -> Code -> Code
79rename url output code = PS.Replace.replace code (prefix <$> PS.string "from \"..") where
80 prefix = const $ "from \"" <> url <> output
82appendMain :: Code -> Code
83appendMain code = code <> "\nmain();"
85compile :: Compiler Code
89 let url = s.protocol <> "://" <> s.hostname <> ":" <> show s.port
92 mRes <- liftAff $ post string (url <> endpoint) $ Just $ String code
93 res <- liftEither $ (error <<< printError) `lmap` mRes
94 body <- liftEither $ error `lmap` (jsonParser res.body)
95 succ <- liftEither $ s.parser body
96 pure $ appendMain $ rename url output succ.js
98runCompiler :: Settings -> Code -> Aff Code
99runCompiler s code = runReaderT (runReaderT compile code) s
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list