git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Remove special cases from parser for JS types

Implicitly import Prim everywhere to deal with it instead

commitc4186db0fa78f1922ac2fb2d6b942877fd924a93 authorGary Burgess <gary.burgess@gmail.com> dateTue 15 Jul 2014, 20:15 (12 years ago) parentb5a13bb
4 files changed+13−22
examples/passing/EmptyDataDecls.purs+6−6 src/Language/PureScript/Environment.hs+1−1 src/Language/PureScript/Parser/Types.hs+1−13 src/Language/PureScript/Sugar/Names.hs+5−2
examples/passing/EmptyDataDecls.purs+6−6
@@ -5,10 +5,10 @@ import Prelude
55data Z
66data S n
77
8−data Array n a = Array [a]
8+data ArrayBox n a = ArrayBox [a]
99
10−nil :: forall a. Array Z a
11−nil = Array []
10+nil :: forall a. ArrayBox Z a
11+nil = ArrayBox []
1212
1313foreign import concat
1414 "function concat(l1) {\
@@ -17,8 +17,8 @@ foreign import concat
1717 \ };\
1818 \}" :: forall a. [a] -> [a] -> [a]
1919
20−cons' :: forall a n. a -> Array n a -> Array (S n) a
21−cons' x (Array xs) = Array $ concat [x] xs
20+cons' :: forall a n. a -> ArrayBox n a -> ArrayBox (S n) a
21+cons' x (ArrayBox xs) = ArrayBox $ concat [x] xs
2222
2323foreign import error
2424 "function error(msg) {\
@@ -26,5 +26,5 @@ foreign import error
2626 \}" :: forall a. String -> a
2727
2828main = 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"
3030 _ -> error "Failed"
src/Language/PureScript/Environment.hs+1−1
@@ -1,6 +1,6 @@
11-----------------------------------------------------------------------------
22--
3−-- Module : Language.PureScript.Prim
3+-- Module : Language.PureScript.Environment
44-- Copyright : (c) 2013-14 Phil Freeman, (c) 2014 Gary Burgess, and other contributors
55-- License : MIT
66--
src/Language/PureScript/Parser/Types.hs+1−13
@@ -30,15 +30,6 @@ import Language.PureScript.Environment
3030import qualified Text.Parsec as P
3131import qualified Text.Parsec.Expr as P
3232
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−
4233parseArray :: P.Parsec String ParseState Type
4334parseArray = squares $ return tyArray
4435
@@ -69,10 +60,7 @@ parseForAll = mkForAll <$> (P.try (reserved "forall") *> P.many1 (indented *> id
6960--
7061parseTypeAtom :: P.Parsec String ParseState Type
7162parseTypeAtom = indented *> P.choice (map P.try
72− [ parseNumber
73− , parseString
74− , parseBoolean
75− , parseArray
63+ [ parseArray
7664 , parseArrayOf
7765 , parseFunction
7866 , parseObject
src/Language/PureScript/Sugar/Names.hs+5−2
@@ -31,6 +31,8 @@ import Language.PureScript.Environment
3131import Language.PureScript.Errors
3232import Language.PureScript.Traversals
3333
34+import qualified Language.PureScript.Constants as C
35+
3436-- |
3537-- The global export environment - every declaration exported from every module.
3638--
@@ -272,7 +274,7 @@ renameInModule imports exports (Module mn decls exps) =
272274-- Finds all exported declarations in a set of modules.
273275--
274276findExports :: [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
276278 where
277279
278280 -- The exported types from the Prim module
@@ -385,7 +387,8 @@ resolveImports env (Module currentModule decls _) =
385387 -- module (where Nothing indicates everything is to be imported), and optionally a qualified name
386388 -- for the module
387389 scope :: M.Map ModuleName (Maybe SourcePos, Maybe ExplicitImports, Maybe ModuleName)
388− scope = M.insert currentModule (Nothing, Nothing, Nothing) (findImports decls)
390+ scope = M.insert (ModuleName [ProperName C.prim]) (Nothing, Nothing, Nothing) $
391+ M.insert currentModule (Nothing, Nothing, Nothing) (findImports decls)
389392
390393 resolveImport' :: ImportEnvironment -> (ModuleName, (Maybe SourcePos, Maybe ExplicitImports, Maybe ModuleName)) -> Either ErrorStack ImportEnvironment
391394 resolveImport' imp (mn, (pos, explImports, impQual)) = do