git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Remove 'import' as a directive to match ghci
commit9a72e09ef5eb55f813e962042b45d2be5812f4e1 authorHarry Garrood <harry@garrood.me> dateThu 12 Mar 2015, 22:04 (12 years ago) parent69c6da4
4 files changed+12−15
psci/Directive.hs−3 psci/Main.hs+2−2 psci/Parser.hs+4−2 src/Language/PureScript/Parser/Declarations.hs+6−8
psci/Directive.hs−3
@@ -21,7 +21,6 @@ data Directive
2121 = Help
2222 | Quit
2323 | Reset
24− | Import
2524 | Browse
2625 | Load
2726 | Type
@@ -36,7 +35,6 @@ commands :: Directive -> [String]
3635commands Help = ["?", "help"]
3736commands Quit = ["quit"]
3837commands Reset = ["reset"]
39−commands Import = ["import"]
4038commands Browse = ["browse"]
4139commands Load = ["load", "module"]
4240commands Type = ["type"]
@@ -66,7 +64,6 @@ help =
6664 [ (Help, "", "Show this help menu")
6765 , (Quit, "", "Quit PSCi")
6866 , (Reset, "", "Reset")
69− , (Import, "<module>", "Import <module> for use in PSCI")
7067 , (Browse, "<module>", "Browse <module>")
7168 , (Load, "<file>", "Load <file> for importing")
7269 , (Type, "<expr>", "Show the type of <expr>")
psci/Main.hs+2−2
@@ -227,7 +227,6 @@ completionContext (':' : cmd) word =
227227 dstr = takeWhile (not . isSpace) cmd
228228
229229 context :: D.Directive -> Maybe CompletionContext
230− context D.Import = Just Module
231230 context D.Browse = Just Module
232231 context D.Load = Just $ FilePath word
233232 context D.Quit = Nothing
@@ -473,9 +472,10 @@ handleShowImportedModules = do
473472 where
474473 showModules = return . unlines . sort . map showModule
475474 showModule (mn, declType, asQ) =
476− case asQ of
475+ "import " ++ case asQ of
477476 Just mn' -> "qualified " ++ N.runModuleName mn ++ " as " ++ N.runModuleName mn'
478477 Nothing -> N.runModuleName mn ++ " " ++ showDeclType declType
478+
479479 showDeclType D.Unqualified = ""
480480 showDeclType (D.Qualifying refs) = refsList refs
481481 showDeclType (D.Hiding refs) = "hiding " ++ refsList refs
psci/Parser.hs+4−2
@@ -38,7 +38,7 @@ parseCommand :: String -> Either String C.Command
3838parseCommand cmdString =
3939 case cmdString of
4040 (':' : cmd) -> parseDirective cmd
41− _ -> parseRest (psciLet <|> psciExpression) cmdString
41+ _ -> parseRest (psciImport <|> psciLet <|> psciExpression) cmdString
4242 where
4343 parseRest :: P.TokenParser a -> String -> Either String a
4444 parseRest p s = either (Left . show) Right $ do
@@ -60,7 +60,6 @@ parseCommand cmdString =
6060 Just D.Help -> return C.Help
6161 Just D.Quit -> return C.Quit
6262 Just D.Reset -> return C.Reset
63− Just D.Import -> C.Import <$> parseRest P.parseImportDeclarationTail arg
6463 Just D.Browse -> C.Browse <$> parseRest P.moduleName arg
6564 Just D.Load -> return $ C.LoadFile (trim arg)
6665 Just D.Show -> return $ C.Show (trim arg)
@@ -86,3 +85,6 @@ parseCommand cmdString =
8685 where
8786 manyDecls :: P.TokenParser [P.Declaration]
8887 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 (
2424 parseGuard,
2525 parseBinder,
2626 parseBinderNoParens,
27− parseImportDeclarationTail,
27+ parseImportDeclaration',
2828) where
2929
3030import Prelude hiding (lex)
@@ -147,15 +147,13 @@ parseFixityDeclaration = do
147147
148148parseImportDeclaration :: TokenParser Declaration
149149parseImportDeclaration = do
150− reserved "import"
151− indented
152− (mn, declType, asQ) <- parseImportDeclarationTail
150+ (mn, declType, asQ) <- parseImportDeclaration'
153151 return $ ImportDeclaration mn declType asQ
154152
155−-- |
156−-- The part of an import statement following the 'import'.
157−parseImportDeclarationTail :: TokenParser (ModuleName, ImportDeclarationType, (Maybe ModuleName))
158−parseImportDeclarationTail =
153+parseImportDeclaration' :: TokenParser (ModuleName, ImportDeclarationType, (Maybe ModuleName))
154+parseImportDeclaration' = do
155+ reserved "import"
156+ indented
159157 qualImport <|> stdImport
160158 where
161159 stdImport = do