git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Remove special cases from parser for JS types
c4186dbGary Burgess
examples/passing/EmptyDataDecls.purs+6−6
@@ -5,10 +5,10 @@ import Prelude
5data Z
5data Z
6data S n
6data S n
7
7
8−data Array n a = Array [a]
8+data ArrayBox n a = ArrayBox [a]
9
9
10−nil :: forall a. Array Z a
10+nil :: forall a. ArrayBox Z a
11−nil = Array []
11+nil = ArrayBox []
12
12
13foreign import concat
13foreign import concat
14 "function concat(l1) {\
14 "function concat(l1) {\
@@ -17,8 +17,8 @@ foreign import concat
17 \ };\
17 \ };\
18 \}" :: forall a. [a] -> [a] -> [a]
18 \}" :: forall a. [a] -> [a] -> [a]
19
19
20−cons' :: forall a n. a -> Array n a -> Array (S n) a
20+cons' :: forall a n. a -> ArrayBox n a -> ArrayBox (S n) a
21−cons' x (Array xs) = Array $ concat [x] xs
21+cons' x (ArrayBox xs) = ArrayBox $ concat [x] xs
22
22
23foreign import error
23foreign import error
24 "function error(msg) {\
24 "function error(msg) {\
@@ -26,5 +26,5 @@ foreign import error
26 \}" :: forall a. String -> a
26 \}" :: forall a. String -> a
27
27
28main = case cons' 1 $ cons' 2 $ cons' 3 nil of
28main = case cons' 1 $ cons' 2 $ cons' 3 nil of
29− Array [1, 2, 3] -> Debug.Trace.trace "Done"
29+ ArrayBox [1, 2, 3] -> Debug.Trace.trace "Done"
30 _ -> error "Failed"
30 _ -> error "Failed"
src/Language/PureScript/Environment.hs+1−1
@@ -1,6 +1,6 @@
1-----------------------------------------------------------------------------
1-----------------------------------------------------------------------------
2--
2--
3−-- Module : Language.PureScript.Prim
3+-- Module : Language.PureScript.Environment
4-- Copyright : (c) 2013-14 Phil Freeman, (c) 2014 Gary Burgess, and other contributors
4-- Copyright : (c) 2013-14 Phil Freeman, (c) 2014 Gary Burgess, and other contributors
5-- License : MIT
5-- License : MIT
6--
6--
src/Language/PureScript/Parser/Types.hs+1−13
@@ -30,15 +30,6 @@ import Language.PureScript.Environment
30import qualified Text.Parsec as P
30import qualified Text.Parsec as P
31import qualified Text.Parsec.Expr as P
31import qualified Text.Parsec.Expr as P
32
32
33−parseNumber :: P.Parsec String ParseState Type
34−parseNumber = const tyNumber <$> reserved "Number"
35−
36−parseString :: P.Parsec String ParseState Type
37−parseString = const tyString <$> reserved "String"
38−
39−parseBoolean :: P.Parsec String ParseState Type
40−parseBoolean = const tyBoolean <$> reserved "Boolean"
41−
42parseArray :: P.Parsec String ParseState Type
33parseArray :: P.Parsec String ParseState Type
43parseArray = squares $ return tyArray
34parseArray = squares $ return tyArray
44
35
@@ -69,10 +60,7 @@ parseForAll = mkForAll <$> (P.try (reserved "forall") *> P.many1 (indented *> id
69--
60--
70parseTypeAtom :: P.Parsec String ParseState Type
61parseTypeAtom :: P.Parsec String ParseState Type
71parseTypeAtom = indented *> P.choice (map P.try
62parseTypeAtom = indented *> P.choice (map P.try
72− [ parseNumber
73− , parseString
74− , parseBoolean
75− , parseArray
63+ [ parseArray
76 , parseArrayOf
64 , parseArrayOf
77 , parseFunction
65 , parseFunction
78 , parseObject
66 , parseObject
src/Language/PureScript/Sugar/Names.hs+5−2
@@ -31,6 +31,8 @@ import Language.PureScript.Environment
31import Language.PureScript.Errors
31import Language.PureScript.Errors
32import Language.PureScript.Traversals
32import Language.PureScript.Traversals
33
33
34+import qualified Language.PureScript.Constants as C
35+
34-- |
36-- |
35-- The global export environment - every declaration exported from every module.
37-- The global export environment - every declaration exported from every module.
36--
38--
@@ -272,7 +274,7 @@ renameInModule imports exports (Module mn decls exps) =
272-- Finds all exported declarations in a set of modules.
274-- Finds all exported declarations in a set of modules.
273--
275--
274findExports :: [Module] -> Either ErrorStack ExportEnvironment
276findExports :: [Module] -> Either ErrorStack ExportEnvironment
275−findExports = foldM addModule $ M.singleton (ModuleName [ProperName "Prim"]) primExports
277+findExports = foldM addModule $ M.singleton (ModuleName [ProperName C.prim]) primExports
276 where
278 where
277
279
278 -- The exported types from the Prim module
280 -- The exported types from the Prim module
@@ -385,7 +387,8 @@ resolveImports env (Module currentModule decls _) =
385 -- module (where Nothing indicates everything is to be imported), and optionally a qualified name
387 -- module (where Nothing indicates everything is to be imported), and optionally a qualified name
386 -- for the module
388 -- for the module
387 scope :: M.Map ModuleName (Maybe SourcePos, Maybe ExplicitImports, Maybe ModuleName)
389 scope :: M.Map ModuleName (Maybe SourcePos, Maybe ExplicitImports, Maybe ModuleName)
390+ scope = M.insert (ModuleName [ProperName C.prim]) (Nothing, Nothing, Nothing) $
388− scope = M.insert currentModule (Nothing, Nothing, Nothing) (findImports decls)
391+ M.insert currentModule (Nothing, Nothing, Nothing) (findImports decls)
389
392
390 resolveImport' :: ImportEnvironment -> (ModuleName, (Maybe SourcePos, Maybe ExplicitImports, Maybe ModuleName)) -> Either ErrorStack ImportEnvironment
393 resolveImport' :: ImportEnvironment -> (ModuleName, (Maybe SourcePos, Maybe ExplicitImports, Maybe ModuleName)) -> Either ErrorStack ImportEnvironment
391 resolveImport' imp (mn, (pos, explImports, impQual)) = do
394 resolveImport' imp (mn, (pos, explImports, impQual)) = do