git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Merge pull request #956 from hdgarrood/psci-imports
da7b120Phil Freeman
psci/Commands.hs+14−3
@@ -32,7 +32,7 @@ data Command
32 -- |
32 -- |
33 -- Import a module from a loaded file
33 -- Import a module from a loaded file
34 --
34 --
35− | Import ModuleName
35+ | Import ImportedModule
36 -- |
36 -- |
37 -- Browse a module
37 -- Browse a module
38 --
38 --
@@ -50,9 +50,9 @@ data Command
50 --
50 --
51 | Reset
51 | Reset
52 -- |
52 -- |
53− -- Binds a value to a name
53+ -- Add some declarations to the current evaluation context.
54 --
54 --
55− | Let [Declaration]
55+ | Decls [Declaration]
56 -- |
56 -- |
57 -- Find the type of an expression
57 -- Find the type of an expression
58 --
58 --
@@ -65,3 +65,14 @@ data Command
65 -- Show command
65 -- Show command
66 --
66 --
67 | Show String
67 | Show String
68+
69+-- | All of the data that is contained by an ImportDeclaration in the AST.
70+-- That is:
71+--
72+-- * A module name, the name of the module which is being imported
73+-- * An ImportDeclarationType which specifies whether there is an explicit
74+-- import list, a hiding list, or neither.
75+-- * If the module is imported qualified, its qualified name in the importing
76+-- module. Otherwise, Nothing.
77+--
78+type ImportedModule = (ModuleName, ImportDeclarationType, Maybe ModuleName)
psci/Directive.hs−3
@@ -21,7 +21,6 @@ data Directive
21 = Help
21 = Help
22 | Quit
22 | Quit
23 | Reset
23 | Reset
24− | Import
25 | Browse
24 | Browse
26 | Load
25 | Load
27 | Type
26 | Type
@@ -36,7 +35,6 @@ commands :: Directive -> [String]
36commands Help = ["?", "help"]
35commands Help = ["?", "help"]
37commands Quit = ["quit"]
36commands Quit = ["quit"]
38commands Reset = ["reset"]
37commands Reset = ["reset"]
39−commands Import = ["import"]
40commands Browse = ["browse"]
38commands Browse = ["browse"]
41commands Load = ["load", "module"]
39commands Load = ["load", "module"]
42commands Type = ["type"]
40commands Type = ["type"]
@@ -66,7 +64,6 @@ help =
66 [ (Help, "", "Show this help menu")
64 [ (Help, "", "Show this help menu")
67 , (Quit, "", "Quit PSCi")
65 , (Quit, "", "Quit PSCi")
68 , (Reset, "", "Reset")
66 , (Reset, "", "Reset")
69− , (Import, "<module>", "Import <module> for use in PSCI")
70 , (Browse, "<module>", "Browse <module>")
67 , (Browse, "<module>", "Browse <module>")
71 , (Load, "<file>", "Load <file> for importing")
68 , (Load, "<file>", "Load <file> for importing")
72 , (Type, "<expr>", "Show the type of <expr>")
69 , (Type, "<expr>", "Show the type of <expr>")
psci/Main.hs+49−26
@@ -72,12 +72,16 @@ data PSCiOptions = PSCiOptions
72--
72--
73data PSCiState = PSCiState
73data PSCiState = PSCiState
74 { psciImportedFilenames :: [FilePath]
74 { psciImportedFilenames :: [FilePath]
75− , psciImportedModuleNames :: [P.ModuleName]
75+ , psciImportedModules :: [C.ImportedModule]
76 , psciLoadedModules :: [(Either P.RebuildPolicy FilePath, P.Module)]
76 , psciLoadedModules :: [(Either P.RebuildPolicy FilePath, P.Module)]
77 , psciLetBindings :: [P.Declaration]
77 , psciLetBindings :: [P.Declaration]
78 , psciNodeFlags :: [String]
78 , psciNodeFlags :: [String]
79 }
79 }
80
80
81+psciImportedModuleNames :: PSCiState -> [P.ModuleName]
82+psciImportedModuleNames (PSCiState{psciImportedModules = is}) =
83+ map (\(mn, _, _) -> mn) is
84+
81-- State helpers
85-- State helpers
82
86
83-- |
87-- |
@@ -89,8 +93,8 @@ updateImportedFiles filename st = st { psciImportedFilenames = filename : psciIm
89-- |
93-- |
90-- Updates the state to have more imported modules.
94-- Updates the state to have more imported modules.
91--
95--
92−updateImports :: P.ModuleName -> PSCiState -> PSCiState
96+updateImportedModules :: C.ImportedModule -> PSCiState -> PSCiState
93−updateImports name st = st { psciImportedModuleNames = name : psciImportedModuleNames st }
97+updateImportedModules im st = st { psciImportedModules = im : psciImportedModules st }
94
98
95-- |
99-- |
96-- Updates the state to have more loaded files.
100-- Updates the state to have more loaded files.
@@ -108,8 +112,8 @@ updateLets ds st = st { psciLetBindings = psciLetBindings st ++ ds }
108-- |
112-- |
109-- Load the necessary modules.
113-- Load the necessary modules.
110--
114--
111−defaultImports :: [P.ModuleName]
115+defaultImports :: [C.ImportedModule]
112−defaultImports = [P.ModuleName [P.ProperName "Prelude"]]
116+defaultImports = [(P.ModuleName [P.ProperName "Prelude"], D.Implicit, Nothing)]
113
117
114-- |
118-- |
115-- Locates the node executable.
119-- Locates the node executable.
@@ -181,7 +185,7 @@ helpMessage = "The following commands are available:\n\n " ++
181 , replicate (11 - length arg) ' '
185 , replicate (11 - length arg) ' '
182 , desc
186 , desc
183 ]
187 ]
184− where cmd = ":" ++ head (D.commands dir)
188+ where cmd = ":" ++ head (D.commands dir)
185
189
186-- |
190-- |
187-- The welcome prologue.
191-- The welcome prologue.
@@ -223,7 +227,6 @@ completionContext (':' : cmd) word =
223 dstr = takeWhile (not . isSpace) cmd
227 dstr = takeWhile (not . isSpace) cmd
224
228
225 context :: D.Directive -> Maybe CompletionContext
229 context :: D.Directive -> Maybe CompletionContext
226− context D.Import = Just Module
227 context D.Browse = Just Module
230 context D.Browse = Just Module
228 context D.Load = Just $ FilePath word
231 context D.Load = Just $ FilePath word
229 context D.Quit = Nothing
232 context D.Quit = Nothing
@@ -370,10 +373,9 @@ mkdirp = createDirectoryIfMissing True . takeDirectory
370-- Makes a volatile module to execute the current expression.
373-- Makes a volatile module to execute the current expression.
371--
374--
372createTemporaryModule :: Bool -> PSCiState -> P.Expr -> P.Module
375createTemporaryModule :: Bool -> PSCiState -> P.Expr -> P.Module
373−createTemporaryModule exec PSCiState{psciImportedModuleNames = imports, psciLetBindings = lets} val =
376+createTemporaryModule exec PSCiState{psciImportedModules = imports, psciLetBindings = lets} val =
374 let
377 let
375 moduleName = P.ModuleName [P.ProperName "$PSCI"]
378 moduleName = P.ModuleName [P.ProperName "$PSCI"]
376− importDecl m = P.ImportDeclaration m P.Unqualified Nothing
377 traceModule = P.ModuleName [P.ProperName "Debug", P.ProperName "Trace"]
379 traceModule = P.ModuleName [P.ProperName "Debug", P.ProperName "Trace"]
378 trace = P.Var (P.Qualified (Just traceModule) (P.Ident "print"))
380 trace = P.Var (P.Qualified (Just traceModule) (P.Ident "print"))
379 mainValue = P.App trace (P.Var (P.Qualified Nothing (P.Ident "it")))
381 mainValue = P.App trace (P.Var (P.Qualified Nothing (P.Ident "it")))
@@ -388,10 +390,9 @@ createTemporaryModule exec PSCiState{psciImportedModuleNames = imports, psciLetB
388-- Makes a volatile module to hold a non-qualified type synonym for a fully-qualified data type declaration.
390-- Makes a volatile module to hold a non-qualified type synonym for a fully-qualified data type declaration.
389--
391--
390createTemporaryModuleForKind :: PSCiState -> P.Type -> P.Module
392createTemporaryModuleForKind :: PSCiState -> P.Type -> P.Module
391−createTemporaryModuleForKind PSCiState{psciImportedModuleNames = imports} typ =
393+createTemporaryModuleForKind PSCiState{psciImportedModules = imports} typ =
392 let
394 let
393 moduleName = P.ModuleName [P.ProperName "$PSCI"]
395 moduleName = P.ModuleName [P.ProperName "$PSCI"]
394− importDecl m = P.ImportDeclaration m P.Unqualified Nothing
395 itDecl = P.TypeSynonymDeclaration (P.ProperName "IT") [] typ
396 itDecl = P.TypeSynonymDeclaration (P.ProperName "IT") [] typ
396 in
397 in
397 P.Module [] moduleName ((importDecl `map` imports) ++ [itDecl]) Nothing
398 P.Module [] moduleName ((importDecl `map` imports) ++ [itDecl]) Nothing
@@ -400,13 +401,15 @@ createTemporaryModuleForKind PSCiState{psciImportedModuleNames = imports} typ =
400-- Makes a volatile module to execute the current imports.
401-- Makes a volatile module to execute the current imports.
401--
402--
402createTemporaryModuleForImports :: PSCiState -> P.Module
403createTemporaryModuleForImports :: PSCiState -> P.Module
403−createTemporaryModuleForImports PSCiState{psciImportedModuleNames = imports} =
404+createTemporaryModuleForImports PSCiState{psciImportedModules = imports} =
404 let
405 let
405 moduleName = P.ModuleName [P.ProperName "$PSCI"]
406 moduleName = P.ModuleName [P.ProperName "$PSCI"]
406− importDecl m = P.ImportDeclaration m P.Unqualified Nothing
407 in
407 in
408 P.Module [] moduleName (importDecl `map` imports) Nothing
408 P.Module [] moduleName (importDecl `map` imports) Nothing
409
409
410+importDecl :: C.ImportedModule -> P.Declaration
411+importDecl (mn, declType, asQ) = P.ImportDeclaration mn declType asQ
412+
410modulesDir :: FilePath
413modulesDir :: FilePath
411modulesDir = ".psci_modules" ++ pathSeparator : "node_modules"
414modulesDir = ".psci_modules" ++ pathSeparator : "node_modules"
412
415
@@ -434,11 +437,11 @@ handleDeclaration val = do
434 Nothing -> PSCI $ outputStrLn "Couldn't find node.js"
437 Nothing -> PSCI $ outputStrLn "Couldn't find node.js"
435
438
436-- |
439-- |
437−-- Takes a let declaration and updates the environment, then run a make. If the declaration fails,
440+-- Takes a list of declarations and updates the environment, then run a make. If the declaration fails,
438−-- restore the pre-let environment.
441+-- restore the original environment.
439--
442--
440−handleLet :: [P.Declaration] -> PSCI ()
443+handleDecls :: [P.Declaration] -> PSCI ()
441−handleLet ds = do
444+handleDecls ds = do
442 st <- PSCI $ lift get
445 st <- PSCI $ lift get
443 let st' = updateLets ds st
446 let st' = updateLets ds st
444 let m = createTemporaryModule False st' (P.ObjectLiteral [])
447 let m = createTemporaryModule False st' (P.ObjectLiteral [])
@@ -463,17 +466,37 @@ handleShowLoadedModules = do
463--
466--
464handleShowImportedModules :: PSCI ()
467handleShowImportedModules :: PSCI ()
465handleShowImportedModules = do
468handleShowImportedModules = do
466− PSCiState { psciImportedModuleNames = importedModuleNames } <- PSCI $ lift get
469+ PSCiState { psciImportedModules = importedModules } <- PSCI $ lift get
467− psciIO $ readModules importedModuleNames >>= putStrLn
470+ psciIO $ showModules importedModules >>= putStrLn
468 return ()
471 return ()
472+ where
469− where readModules = return . unlines . sort . map N.runModuleName
473+ showModules = return . unlines . sort . map showModule
474+ showModule (mn, declType, asQ) =
475+ "import " ++ case asQ of
476+ Just mn' -> "qualified " ++ N.runModuleName mn ++ " as " ++ N.runModuleName mn'
477+ Nothing -> N.runModuleName mn ++ " " ++ showDeclType declType
478+
479+ showDeclType D.Implicit = ""
480+ showDeclType (D.Explicit refs) = refsList refs
481+ showDeclType (D.Hiding refs) = "hiding " ++ refsList refs
482+ refsList refs = "(" ++ commaList (map showRef refs) ++ ")"
483+
484+ showRef :: P.DeclarationRef -> String
485+ showRef (D.TypeRef pn dctors) = show pn ++ "(" ++ maybe ".." (commaList . map N.runProperName) dctors ++ ")"
486+ showRef (D.ValueRef ident) = show ident
487+ showRef (D.TypeClassRef pn) = show pn
488+ showRef (D.TypeInstanceRef ident) = show ident
489+ showRef (D.PositionedDeclarationRef _ _ ref) = showRef ref
490+
491+ commaList :: [String] -> String
492+ commaList = intercalate ", "
470
493
471-- |
494-- |
472-- Imports a module, preserving the initial state on failure.
495-- Imports a module, preserving the initial state on failure.
473--
496--
474−handleImport :: P.ModuleName -> PSCI ()
497+handleImport :: C.ImportedModule -> PSCI ()
475−handleImport moduleName = do
498+handleImport im = do
476− st <- updateImports moduleName <$> PSCI (lift get)
499+ st <- updateImportedModules im <$> PSCI (lift get)
477 let m = createTemporaryModuleForImports st
500 let m = createTemporaryModuleForImports st
478 e <- psciIO . runMake $ P.make modulesDir (psciLoadedModules st ++ [(Left P.RebuildAlways, m)]) []
501 e <- psciIO . runMake $ P.make modulesDir (psciLoadedModules st ++ [(Left P.RebuildAlways, m)]) []
479 case e of
502 case e of
@@ -575,8 +598,8 @@ getCommand singleLineMode = do
575handleCommand :: C.Command -> PSCI ()
598handleCommand :: C.Command -> PSCI ()
576handleCommand (C.Expression val) = handleDeclaration val
599handleCommand (C.Expression val) = handleDeclaration val
577handleCommand C.Help = PSCI $ outputStrLn helpMessage
600handleCommand C.Help = PSCI $ outputStrLn helpMessage
578−handleCommand (C.Import moduleName) = handleImport moduleName
601+handleCommand (C.Import im) = handleImport im
579−handleCommand (C.Let l) = handleLet l
602+handleCommand (C.Decls l) = handleDecls l
580handleCommand (C.LoadFile filePath) = do
603handleCommand (C.LoadFile filePath) = do
581 absPath <- psciIO $ expandTilde filePath
604 absPath <- psciIO $ expandTilde filePath
582 exists <- psciIO $ doesFileExist absPath
605 exists <- psciIO $ doesFileExist absPath
@@ -592,7 +615,7 @@ handleCommand C.Reset = do
592 files <- psciImportedFilenames <$> PSCI (lift get)
615 files <- psciImportedFilenames <$> PSCI (lift get)
593 PSCI . lift . modify $ \st -> st
616 PSCI . lift . modify $ \st -> st
594 { psciImportedFilenames = files
617 { psciImportedFilenames = files
595− , psciImportedModuleNames = defaultImports
618+ , psciImportedModules = defaultImports
596 , psciLetBindings = []
619 , psciLetBindings = []
597 }
620 }
598 loadAllImportedModules
621 loadAllImportedModules
psci/Parser.hs+86−49
@@ -13,8 +13,8 @@
13--
13--
14-----------------------------------------------------------------------------
14-----------------------------------------------------------------------------
15
15
16−module Parser (
16+module Parser
17− parseCommand
17+ ( parseCommand
18 ) where
18 ) where
19
19
20import Prelude hiding (lex)
20import Prelude hiding (lex)
@@ -38,51 +38,88 @@ parseCommand :: String -> Either String C.Command
38parseCommand cmdString =
38parseCommand cmdString =
39 case cmdString of
39 case cmdString of
40 (':' : cmd) -> parseDirective cmd
40 (':' : cmd) -> parseDirective cmd
41− _ -> parseRest (psciLet <|> psciExpression) cmdString
41+ _ -> parseRest psciCommand cmdString
42+
43+parseRest :: P.TokenParser a -> String -> Either String a
44+parseRest p s = either (Left . show) Right $ do
45+ ts <- P.lex "" s
46+ P.runTokenParser "" (p <* eof) ts
47+
48+psciCommand :: P.TokenParser C.Command
49+psciCommand = choice (map try parsers)
42 where
50 where
43− parseRest :: P.TokenParser a -> String -> Either String a
51+ parsers =
44− parseRest p s = either (Left . show) Right $ do
52+ [ psciLet
45− ts <- P.lex "" s
53+ , psciImport
46− P.runTokenParser "" (p <* eof) ts
54+ , psciOtherDeclaration
47−
55+ , psciExpression
56+ ]
57+
48− trim :: String -> String
58+trim :: String -> String
49− trim = trimEnd . trimStart
59+trim = trimEnd . trimStart
50−
60+
51− trimStart :: String -> String
61+trimStart :: String -> String
52− trimStart = dropWhile isSpace
62+trimStart = dropWhile isSpace
53−
63+
54− trimEnd :: String -> String
64+trimEnd :: String -> String
55− trimEnd = reverse . trimStart . reverse
65+trimEnd = reverse . trimStart . reverse
56−
66+
57− parseDirective :: String -> Either String C.Command
67+parseDirective :: String -> Either String C.Command
58− parseDirective cmd =
68+parseDirective cmd =
59− case D.parseDirective dstr of
69+ case D.parseDirective dstr of
60− Just D.Help -> return C.Help
70+ Just D.Help -> return C.Help
61− Just D.Quit -> return C.Quit
71+ Just D.Quit -> return C.Quit
62− Just D.Reset -> return C.Reset
72+ Just D.Reset -> return C.Reset
63− Just D.Import -> C.Import <$> parseRest P.moduleName arg
64− Just D.Browse -> C.Browse <$> parseRest P.moduleName arg
73+ Just D.Browse -> C.Browse <$> parseRest P.moduleName arg
65− Just D.Load -> return $ C.LoadFile (trim arg)
74+ Just D.Load -> return $ C.LoadFile (trim arg)
66− Just D.Show -> return $ C.Show (trim arg)
75+ Just D.Show -> return $ C.Show (trim arg)
67− Just D.Type -> C.TypeOf <$> parseRest P.parseValue arg
76+ Just D.Type -> C.TypeOf <$> parseRest P.parseValue arg
68− Just D.Kind -> C.KindOf <$> parseRest P.parseType arg
77+ Just D.Kind -> C.KindOf <$> parseRest P.parseType arg
69− Nothing -> Left $ "Unrecognized command. Type :? for help."
78+ Nothing -> Left $ "Unrecognized command. Type :? for help."
70− where (dstr, arg) = break isSpace cmd
79+ where (dstr, arg) = break isSpace cmd
71−
80+
72− -- |
81+-- |
73− -- Parses expressions entered at the PSCI repl.
82+-- Parses expressions entered at the PSCI repl.
74− --
83+--
75− psciExpression :: P.TokenParser C.Command
84+psciExpression :: P.TokenParser C.Command
76− psciExpression = C.Expression <$> P.parseValue
85+psciExpression = C.Expression <$> P.parseValue
77−
86+
78− -- |
87+-- |
79− -- PSCI version of @let@.
88+-- PSCI version of @let@.
80− -- This is essentially let from do-notation.
89+-- This is essentially let from do-notation.
81− -- However, since we don't support the @Eff@ monad,
90+-- However, since we don't support the @Eff@ monad,
82− -- we actually want the normal @let@.
91+-- we actually want the normal @let@.
83− --
92+--
84− psciLet :: P.TokenParser C.Command
93+psciLet :: P.TokenParser C.Command
85− psciLet = C.Let <$> (P.reserved "let" *> P.indented *> manyDecls)
94+psciLet = C.Decls <$> (P.reserved "let" *> P.indented *> manyDecls)
86− where
95+ where
87− manyDecls :: P.TokenParser [P.Declaration]
96+ manyDecls :: P.TokenParser [P.Declaration]
88− manyDecls = C.mark (many1 (C.same *> P.parseDeclaration))
97+ manyDecls = C.mark (many1 (C.same *> P.parseLocalDeclaration))
98+
99+-- | Imports must be handled separately from other declarations, so that
100+-- :show import works, for example.
101+psciImport :: P.TokenParser C.Command
102+psciImport = C.Import <$> P.parseImportDeclaration'
103+
104+-- | Any other declaration that we don't need a 'special case' parser for
105+-- (like let or import declarations).
106+psciOtherDeclaration :: P.TokenParser C.Command
107+psciOtherDeclaration = C.Decls . (:[]) <$> do
108+ decl <- discardPositionInfo <$> P.parseDeclaration
109+ if acceptable decl
110+ then return decl
111+ else fail "this kind of declaration is not supported in psci"
112+
113+discardPositionInfo :: P.Declaration -> P.Declaration
114+discardPositionInfo (P.PositionedDeclaration _ _ d) = d
115+discardPositionInfo d = d
116+
117+acceptable :: P.Declaration -> Bool
118+acceptable (P.DataDeclaration _ _ _ _) = True
119+acceptable (P.TypeSynonymDeclaration _ _ _) = True
120+acceptable (P.ExternDeclaration _ _ _ _) = True
121+acceptable (P.ExternDataDeclaration _ _) = True
122+acceptable (P.ExternInstanceDeclaration _ _ _ _) = True
123+acceptable (P.TypeClassDeclaration _ _ _ _) = True
124+acceptable (P.TypeInstanceDeclaration _ _ _ _ _) = True
125+acceptable _ = False
src/Language/PureScript.hs+1−1
@@ -257,7 +257,7 @@ reverseDependencies g = combine [ (dep, mn) | (mn, deps) <- g, dep <- deps ]
257addDefaultImport :: ModuleName -> Module -> Module
257addDefaultImport :: ModuleName -> Module -> Module
258addDefaultImport toImport m@(Module coms mn decls exps) =
258addDefaultImport toImport m@(Module coms mn decls exps) =
259 if isExistingImport `any` decls || mn == toImport then m
259 if isExistingImport `any` decls || mn == toImport then m
260− else Module coms mn (ImportDeclaration toImport Unqualified Nothing : decls) exps
260+ else Module coms mn (ImportDeclaration toImport Implicit Nothing : decls) exps
261 where
261 where
262 isExistingImport (ImportDeclaration mn' _ _) | mn' == toImport = True
262 isExistingImport (ImportDeclaration mn' _ _) | mn' == toImport = True
263 isExistingImport (PositionedDeclaration _ _ d) = isExistingImport d
263 isExistingImport (PositionedDeclaration _ _ d) = isExistingImport d
src/Language/PureScript/AST/Declarations.hs+5−5
@@ -127,15 +127,15 @@ instance Eq DeclarationRef where
127--
127--
128data ImportDeclarationType
128data ImportDeclarationType
129 -- |
129 -- |
130− -- Unqualified import
130+ -- An import with no explicit list: `import M`
131 --
131 --
132− = Unqualified
132+ = Implicit
133 -- |
133 -- |
134− -- Qualified import with a list of references to import
134+ -- An import with an explicit list of references to import: `import M (foo)`
135 --
135 --
136− | Qualifying [DeclarationRef]
136+ | Explicit [DeclarationRef]
137 -- |
137 -- |
138− -- Import with hiding clause with a list of references to hide
138+ -- An import with a list of references to hide: `import M hiding (foo)`
139 --
139 --
140 | Hiding [DeclarationRef]
140 | Hiding [DeclarationRef]
141 deriving (Show, D.Data, D.Typeable)
141 deriving (Show, D.Data, D.Typeable)
src/Language/PureScript/Parser/Declarations.hs+13−6
@@ -24,6 +24,8 @@ module Language.PureScript.Parser.Declarations (
24 parseGuard,
24 parseGuard,
25 parseBinder,
25 parseBinder,
26 parseBinderNoParens,
26 parseBinderNoParens,
27+ parseImportDeclaration',
28+ parseLocalDeclaration
27) where
29) where
28
30
29import Prelude hiding (lex)
31import Prelude hiding (lex)
@@ -146,6 +148,11 @@ parseFixityDeclaration = do
146
148
147parseImportDeclaration :: TokenParser Declaration
149parseImportDeclaration :: TokenParser Declaration
148parseImportDeclaration = do
150parseImportDeclaration = do
151+ (mn, declType, asQ) <- parseImportDeclaration'
152+ return $ ImportDeclaration mn declType asQ
153+
154+parseImportDeclaration' :: TokenParser (ModuleName, ImportDeclarationType, (Maybe ModuleName))
155+parseImportDeclaration' = do
149 reserved "import"
156 reserved "import"
150 indented
157 indented
151 qualImport <|> stdImport
158 qualImport <|> stdImport
@@ -157,21 +164,21 @@ parseImportDeclaration = do
157 stdImportHiding mn = do
164 stdImportHiding mn = do
158 reserved "hiding"
165 reserved "hiding"
159 declType <- importDeclarationType Hiding
166 declType <- importDeclarationType Hiding
160− return $ ImportDeclaration mn declType Nothing
167+ return (mn, declType, Nothing)
161 stdImportQualifying mn = do
168 stdImportQualifying mn = do
162− declType <- importDeclarationType Qualifying
169+ declType <- importDeclarationType Explicit
163− return $ ImportDeclaration mn declType Nothing
170+ return (mn, declType, Nothing)
164 qualImport = do
171 qualImport = do
165 reserved "qualified"
172 reserved "qualified"
166 indented
173 indented
167 moduleName' <- moduleName
174 moduleName' <- moduleName
168− declType <- importDeclarationType Qualifying
175+ declType <- importDeclarationType Explicit
169 reserved "as"
176 reserved "as"
170 asQ <- moduleName
177 asQ <- moduleName
171− return $ ImportDeclaration moduleName' declType (Just asQ)
178+ return (moduleName', declType, Just asQ)
172 importDeclarationType expectedType = do
179 importDeclarationType expectedType = do
173 idents <- P.optionMaybe $ indented *> (parens $ commaSep parseDeclarationRef)
180 idents <- P.optionMaybe $ indented *> (parens $ commaSep parseDeclarationRef)
174− return $ fromMaybe Unqualified (expectedType <$> idents)
181+ return $ fromMaybe Implicit (expectedType <$> idents)
175
182
176
183
177parseDeclarationRef :: TokenParser DeclarationRef
184parseDeclarationRef :: TokenParser DeclarationRef
src/Language/PureScript/Pretty/Values.hs+1−1
@@ -1,7 +1,7 @@
1-----------------------------------------------------------------------------
1-----------------------------------------------------------------------------
2--
2--
3-- Module : Language.PureScript.Pretty.Values
3-- Module : Language.PureScript.Pretty.Values
4−-- Copyright : Kinds.hs(c) Phil Freeman 2013
4+-- Copyright : (c) Phil Freeman 2013
5-- License : MIT
5-- License : MIT
6--
6--
7-- Maintainer : Phil Freeman <paf31@cantab.net>
7-- Maintainer : Phil Freeman <paf31@cantab.net>
src/Language/PureScript/Sugar/Names.hs+4−4
@@ -199,7 +199,7 @@ elaborateImports (Module coms mn decls exps) = Module coms mn decls' exps
199 fqValues (Var (Qualified (Just mn') _)) = [mn']
199 fqValues (Var (Qualified (Just mn') _)) = [mn']
200 fqValues _ = []
200 fqValues _ = []
201 mkImport :: ModuleName -> Declaration
201 mkImport :: ModuleName -> Declaration
202− mkImport mn' = ImportDeclaration mn' (Qualifying []) Nothing
202+ mkImport mn' = ImportDeclaration mn' (Explicit []) Nothing
203
203
204-- |
204-- |
205-- Replaces all local names with qualified names within a module and checks that all existing
205-- Replaces all local names with qualified names within a module and checks that all existing
@@ -417,7 +417,7 @@ resolveImports env (Module _ currentModule decls _) =
417 -- module (where Nothing indicates everything is to be imported), and optionally a qualified name
417 -- module (where Nothing indicates everything is to be imported), and optionally a qualified name
418 -- for the module
418 -- for the module
419 scope :: M.Map ModuleName (Maybe SourceSpan, ImportDeclarationType, Maybe ModuleName)
419 scope :: M.Map ModuleName (Maybe SourceSpan, ImportDeclarationType, Maybe ModuleName)
420− scope = M.insert currentModule (Nothing, Unqualified, Nothing) (findImports decls)
420+ scope = M.insert currentModule (Nothing, Implicit, Nothing) (findImports decls)
421
421
422 resolveImport' :: ImportEnvironment -> (ModuleName, (Maybe SourceSpan, ImportDeclarationType, Maybe ModuleName)) -> m ImportEnvironment
422 resolveImport' :: ImportEnvironment -> (ModuleName, (Maybe SourceSpan, ImportDeclarationType, Maybe ModuleName)) -> m ImportEnvironment
423 resolveImport' imp (mn, (pos, typ, impQual)) = do
423 resolveImport' imp (mn, (pos, typ, impQual)) = do
@@ -437,8 +437,8 @@ resolveImport currentModule importModule exps imps impQual =
437 where
437 where
438
438
439 resolveByType :: ImportDeclarationType -> m ImportEnvironment
439 resolveByType :: ImportDeclarationType -> m ImportEnvironment
440− resolveByType Unqualified = importAll importExplicit
440+ resolveByType Implicit = importAll importExplicit
441− resolveByType (Qualifying explImports) = (checkedRefs >=> foldM importExplicit imps) explImports
441+ resolveByType (Explicit explImports) = (checkedRefs >=> foldM importExplicit imps) explImports
442 resolveByType (Hiding hiddenImports) = do
442 resolveByType (Hiding hiddenImports) = do
443 hiddenImports' <- checkedRefs hiddenImports
443 hiddenImports' <- checkedRefs hiddenImports
444 importAll (importNonHidden hiddenImports')
444 importAll (importNonHidden hiddenImports')