Skip to content

Commit c9da168

Browse files
committed
Update server to 0.13
1 parent e463743 commit c9da168

File tree

4 files changed

+90
-14
lines changed

4 files changed

+90
-14
lines changed

server/Main.hs

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@ import Control.Monad.Trans.Except (ExceptT(..), runExceptT)
1818
import Control.Monad.Trans.Reader (runReaderT)
1919
import qualified Data.Aeson as A
2020
import Data.Aeson ((.=))
21+
import Data.Bifunctor (first, second)
2122
import qualified Data.ByteString.Lazy as BL
2223
import Data.Function (on)
2324
import Data.List (foldl', nubBy)
25+
import qualified Data.List.NonEmpty as NE
2426
import qualified Data.Map as M
2527
import Data.String (fromString)
2628
import Data.Text (Text)
@@ -30,6 +32,8 @@ import qualified Data.Text.Lazy as TL
3032
import Data.Traversable (for)
3133
import GHC.Generics (Generic)
3234
import qualified Language.PureScript as P
35+
import qualified Language.PureScript.CST as CST
36+
import qualified Language.PureScript.CST.Monad as CSTM
3337
import qualified Language.PureScript.Bundle as Bundle
3438
import qualified Language.PureScript.CodeGen.JS as J
3539
import qualified Language.PureScript.CodeGen.JS.Printer as P
@@ -63,13 +67,15 @@ server bundled externs initEnv port = do
6367
| T.length input > 20000 = return (Left (OtherError "Please limit your input to 20000 characters"))
6468
| otherwise = do
6569
let printErrors = P.prettyPrintMultipleErrors (P.defaultPPEOptions { P.ppeCodeColor = Nothing })
66-
case P.parseModuleFromFile (const "<file>") (undefined, input) of
70+
case CST.parseModuleFromFile "<file>" input >>= CST.resFull of
6771
Left parseError ->
68-
return . Left . CompilerErrors . pure . P.toJSONError False P.Error . P.toPositionedError $ parseError
69-
Right (_, m) | P.getModuleName m == P.ModuleName [P.ProperName "Main"] -> do
72+
return . Left . CompilerErrors . P.toJSONErrors False P.Error $ CST.toMultipleErrors "<file>" parseError
73+
Right m | P.getModuleName m == P.ModuleName [P.ProperName "Main"] -> do
7074
(resultMay, ws) <- runLogger' . runExceptT . flip runReaderT P.defaultOptions $ do
7175
((P.Module ss coms moduleName elaborated exps, env), nextVar) <- P.runSupplyT 0 $ do
72-
[desugared] <- P.desugar externs [P.importPrim m]
76+
desugared <- P.desugar externs [P.importPrim m] >>= \case
77+
[d] -> pure d
78+
_ -> error "desugaring did not produce one module"
7379
P.runCheck' (P.emptyCheckState initEnv) $ P.typeCheckModule desugared
7480
regrouped <- P.createBindingGroups moduleName . P.collapseBindingGroups $ elaborated
7581
let mod' = P.Module ss coms moduleName regrouped exps
@@ -80,7 +86,8 @@ server bundled externs initEnv port = do
8086
case resultMay of
8187
Left errs -> (return . Left . CompilerErrors . P.toJSONErrors False P.Error) errs
8288
Right js -> (return . Right) (P.toJSONErrors False P.Error ws, js)
83-
Right _ -> (return . Left. OtherError) "The name of the main module should be Main."
89+
Right _ ->
90+
(return . Left . OtherError) "The name of the main module should be Main."
8491

8592
scotty port $ do
8693
get "/" $
@@ -147,9 +154,15 @@ replaceTypeVariablesAndDesugar f ty = State.evalState (P.everywhereOnTypesM go t
147154
other -> pure other
148155

149156
tryParseType :: Text -> Maybe P.SourceType
150-
tryParseType = hush (P.lex "") >=> hush (P.runTokenParser "" (P.parsePolyType <* Parsec.eof))
157+
tryParseType = hush . fmap (CST.convertType "<file>") . runParser CST.parseTypeP
151158
where
152-
hush f = either (const Nothing) Just . f
159+
hush = either (const Nothing) Just
160+
161+
runParser :: CST.Parser a -> Text -> Either String a
162+
runParser p =
163+
first (CST.prettyPrintError . NE.head)
164+
. CST.runTokenParser (p <* CSTM.token CST.TokEof)
165+
. CST.lexTopLevel
153166

154167
bundle :: IO (Either Bundle.ErrorMessage String)
155168
bundle = runExceptT $ do
@@ -168,7 +181,7 @@ main = do
168181
let onError f = either (Left . f) Right
169182
e <- runExceptT $ do
170183
modules <- ExceptT (fmap (onError Right) (I.loadAllModules inputFiles))
171-
(exts, env) <- ExceptT . fmap (onError Right) . I.runMake . I.make $ modules
184+
(exts, env) <- ExceptT . fmap (onError Right) . I.runMake . I.make . map (second CST.pureResult) $ modules
172185
js <- ExceptT (fmap (onError Left) bundle)
173186
return (fromString js, exts, env)
174187
case e of

stack.yaml

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
1-
resolver: lts-12.0
2-
flags: {}
1+
resolver: lts-13.26
2+
flags:
3+
aeson-pretty:
4+
lib-only: true
5+
these:
6+
assoc: false
7+
quickcheck: false
38
packages:
49
- '.'
510
extra-deps:
6-
- purescript-0.12.3
7-
- pipes-http-1.0.5
11+
- purescript-0.13.5
12+
- happy-1.19.9
13+
- language-javascript-0.7.0.0
14+
- network-3.0.1.1
15+
- these-1.0.1
16+
- semialign-1

stack.yaml.lock

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# This file was autogenerated by Stack.
2+
# You should not edit this file by hand.
3+
# For more information, please see the documentation at:
4+
# https://docs.haskellstack.org/en/stable/lock_files
5+
6+
packages:
7+
- completed:
8+
hackage: purescript-0.13.5@sha256:1e54e144cf2271fae7149734bdae2c79e215c204782d867f68f557a2c3c2472c,62027
9+
pantry-tree:
10+
size: 95425
11+
sha256: af427d485cd2a6d99008aa8f877ce19bc06e97bbe78ff4122b3e0843caf19e49
12+
original:
13+
hackage: purescript-0.13.5
14+
- completed:
15+
hackage: happy-1.19.9@sha256:f8c774230735a390c287b2980cfcd2703d24d8dde85a01ea721b7b4b4c82944f,4667
16+
pantry-tree:
17+
size: 7980
18+
sha256: 1f1d622f6e773e7a674da6364b755714c76c3fbb3c7a4e65deaf07242fc15211
19+
original:
20+
hackage: happy-1.19.9
21+
- completed:
22+
hackage: language-javascript-0.7.0.0@sha256:3eab0262b8ac5621936a4beab6a0f97d0e00a63455a8b0e3ac1547b4088dae7d,3898
23+
pantry-tree:
24+
size: 2244
25+
sha256: b0f28d836cb3fbde203fd7318a896c3a20acd8653a905e1950ae2d9a64bccebf
26+
original:
27+
hackage: language-javascript-0.7.0.0
28+
- completed:
29+
hackage: network-3.0.1.1@sha256:1a251b790ea98b6f7433f677958f921950780ba6f143d61ba8c0e3f7a9879097,4074
30+
pantry-tree:
31+
size: 3296
32+
sha256: 78e378780c998faaf4e32a16b98880220f502d8ef005f24d7ee0c99fb50636e6
33+
original:
34+
hackage: network-3.0.1.1
35+
- completed:
36+
hackage: these-1.0.1@sha256:7ff0f309978604015d978fb155ac4dc10a98e3d70a99aa2be8f755eb0cca4324,3191
37+
pantry-tree:
38+
size: 351
39+
sha256: 3257ef64424e9a07e2ae750eff7affcd459811c4669cb67a5e4f43ab833c5aba
40+
original:
41+
hackage: these-1.0.1
42+
- completed:
43+
hackage: semialign-1@sha256:f11b3d8d0f31a3556061ec0fb515575646d162f12c5b25a0f07c92679db7d862,2433
44+
pantry-tree:
45+
size: 466
46+
sha256: e67b833b94b7fa23afbf7088833a38596cf35a2b93635604dd9e49d0389360fe
47+
original:
48+
hackage: semialign-1
49+
snapshots:
50+
- completed:
51+
size: 499889
52+
url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/13/26.yaml
53+
sha256: ecb02ee16829df8d7219e7d7fe6c310819820bf335b0b9534bce84d3ea896684
54+
original: lts-13.26

trypurescript.cabal

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: trypurescript
2-
version: 0.12.3
2+
version: 0.13.5
33
cabal-version: >=1.8
44
build-type: Simple
55
license: BSD3
@@ -20,7 +20,7 @@ executable trypurescript
2020
filepath -any,
2121
Glob -any,
2222
scotty -any,
23-
purescript ==0.12.3,
23+
purescript ==0.13.5,
2424
containers -any,
2525
http-types >= 0.8.5,
2626
transformers ==0.5.*,

0 commit comments

Comments
 (0)