git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Remove 'import' as a directive to match ghci
9a72e09Harry Garrood
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+2−2
@@ -227,7 +227,6 @@ completionContext (':' : cmd) word =
227 dstr = takeWhile (not . isSpace) cmd
227 dstr = takeWhile (not . isSpace) cmd
228
228
229 context :: D.Directive -> Maybe CompletionContext
229 context :: D.Directive -> Maybe CompletionContext
230− context D.Import = Just Module
231 context D.Browse = Just Module
230 context D.Browse = Just Module
232 context D.Load = Just $ FilePath word
231 context D.Load = Just $ FilePath word
233 context D.Quit = Nothing
232 context D.Quit = Nothing
@@ -473,9 +472,10 @@ handleShowImportedModules = do
473 where
472 where
474 showModules = return . unlines . sort . map showModule
473 showModules = return . unlines . sort . map showModule
475 showModule (mn, declType, asQ) =
474 showModule (mn, declType, asQ) =
476− case asQ of
475+ "import " ++ case asQ of
477 Just mn' -> "qualified " ++ N.runModuleName mn ++ " as " ++ N.runModuleName mn'
476 Just mn' -> "qualified " ++ N.runModuleName mn ++ " as " ++ N.runModuleName mn'
478 Nothing -> N.runModuleName mn ++ " " ++ showDeclType declType
477 Nothing -> N.runModuleName mn ++ " " ++ showDeclType declType
478+
479 showDeclType D.Unqualified = ""
479 showDeclType D.Unqualified = ""
480 showDeclType (D.Qualifying refs) = refsList refs
480 showDeclType (D.Qualifying refs) = refsList refs
481 showDeclType (D.Hiding refs) = "hiding " ++ refsList refs
481 showDeclType (D.Hiding refs) = "hiding " ++ refsList refs
psci/Parser.hs+4−2
@@ -38,7 +38,7 @@ 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 (psciImport <|> psciLet <|> psciExpression) cmdString
42 where
42 where
43 parseRest :: P.TokenParser a -> String -> Either String a
43 parseRest :: P.TokenParser a -> String -> Either String a
44 parseRest p s = either (Left . show) Right $ do
44 parseRest p s = either (Left . show) Right $ do
@@ -60,7 +60,6 @@ parseCommand cmdString =
60 Just D.Help -> return C.Help
60 Just D.Help -> return C.Help
61 Just D.Quit -> return C.Quit
61 Just D.Quit -> return C.Quit
62 Just D.Reset -> return C.Reset
62 Just D.Reset -> return C.Reset
63− Just D.Import -> C.Import <$> parseRest P.parseImportDeclarationTail arg
64 Just D.Browse -> C.Browse <$> parseRest P.moduleName arg
63 Just D.Browse -> C.Browse <$> parseRest P.moduleName arg
65 Just D.Load -> return $ C.LoadFile (trim arg)
64 Just D.Load -> return $ C.LoadFile (trim arg)
66 Just D.Show -> return $ C.Show (trim arg)
65 Just D.Show -> return $ C.Show (trim arg)
@@ -86,3 +85,6 @@ parseCommand cmdString =
86 where
85 where
87 manyDecls :: P.TokenParser [P.Declaration]
86 manyDecls :: P.TokenParser [P.Declaration]
88 manyDecls = C.mark (many1 (C.same *> P.parseDeclaration))
87 manyDecls = C.mark (many1 (C.same *> P.parseDeclaration))
88+
89+ psciImport :: P.TokenParser C.Command
90+ psciImport = C.Import <$> P.parseImportDeclaration'
src/Language/PureScript/Parser/Declarations.hs+6−8
@@ -24,7 +24,7 @@ module Language.PureScript.Parser.Declarations (
24 parseGuard,
24 parseGuard,
25 parseBinder,
25 parseBinder,
26 parseBinderNoParens,
26 parseBinderNoParens,
27− parseImportDeclarationTail,
27+ parseImportDeclaration',
28) where
28) where
29
29
30import Prelude hiding (lex)
30import Prelude hiding (lex)
@@ -147,15 +147,13 @@ parseFixityDeclaration = do
147
147
148parseImportDeclaration :: TokenParser Declaration
148parseImportDeclaration :: TokenParser Declaration
149parseImportDeclaration = do
149parseImportDeclaration = do
150− reserved "import"
150+ (mn, declType, asQ) <- parseImportDeclaration'
151− indented
152− (mn, declType, asQ) <- parseImportDeclarationTail
153 return $ ImportDeclaration mn declType asQ
151 return $ ImportDeclaration mn declType asQ
154
152
155−-- |
156−-- The part of an import statement following the 'import'.
157−parseImportDeclarationTail :: TokenParser (ModuleName, ImportDeclarationType, (Maybe ModuleName))
153+parseImportDeclaration' :: TokenParser (ModuleName, ImportDeclarationType, (Maybe ModuleName))
158−parseImportDeclarationTail =
154+parseImportDeclaration' = do
155+ reserved "import"
156+ indented
159 qualImport <|> stdImport
157 qualImport <|> stdImport
160 where
158 where
161 stdImport = do
159 stdImport = do