git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Expression no longer consumes colons.
4b9abe3joneshf
psci/Commands.hs+1−25
@@ -30,7 +30,7 @@ data Command
30 -- |
30 -- |
31 -- A purescript expression
31 -- A purescript expression
32 --
32 --
33− | Expression [String]
33+ | Expression String
34 -- |
34 -- |
35 -- Show the help command
35 -- Show the help command
36 --
36 --
@@ -60,30 +60,6 @@ data Command
60 --
60 --
61 | Unknown ParseError
61 | Unknown ParseError
62
62
63−---- |
64−---- Parses the input and returns either a Metacommand or an expression.
65−----
66−--getCommand :: InputT IO Command
67−--getCommand = do
68−-- firstLine <- getInputLine "> "
69−-- case firstLine of
70−-- Nothing -> return Empty
71−-- Just line -> psciParser psciHelp
72−-- --Just ":?" -> return Help
73−-- --Just (':':'i':' ':moduleName) -> return $ Import moduleName
74−-- --Just (':':'m':' ':filePath) -> return $ LoadFile filePath
75−-- --Just ":q" -> return Quit
76−-- --Just ":r" -> return Reload
77−-- --Just (':':'t':' ':expr) -> return $ TypeOf expr
78−-- --Just (':':_) -> return Unknown
79−-- --Just other -> Expression <$> go [other]
80−-- where
81−-- go ls = do
82−-- l <- getInputLine " "
83−-- case l of
84−-- Nothing -> return $ reverse ls
85−-- Just l' -> go (l' : ls)
86−
87-- |
63-- |
88-- The help menu.
64-- The help menu.
89--
65--
psci/Main.hs+19−18
@@ -238,13 +238,31 @@ handleTypeOf value (PSCI imports loadedModules lets) = do
238
238
239-- Commands
239-- Commands
240
240
241+-- |
242+-- Parses the input and returns either a Metacommand or an expression.
243+--
244+getCommand :: InputT IO Command
245+getCommand = do
246+ firstLine <- getInputLine "> "
247+ case firstLine of
248+ Nothing -> return Empty
249+ Just line -> case parseCommands line of
250+ Left err -> return $ Unknown err
251+ Right c -> case c of
252+ Expression expr -> Expression <$> go [expr]
253+ _ -> lift $ return c
254+ where
255+ go :: [String] -> InputT IO String
256+ go ls =
257+ maybe (return . unlines $ reverse ls) (go . (:ls)) =<< getInputLine " "
258+
241-- |
259-- |
242-- Performs an action for each meta-command given, and also for expressions..
260-- Performs an action for each meta-command given, and also for expressions..
243--
261--
244handleCommand :: Command -> StateT PSCI (InputT IO) ()
262handleCommand :: Command -> StateT PSCI (InputT IO) ()
245handleCommand Empty = return ()
263handleCommand Empty = return ()
246handleCommand (Expression ls) =
264handleCommand (Expression ls) =
247− case psciParser (choice [Left <$> psciLet, Right <$> psciExpression]) (unlines ls) of
265+ case psciParser (choice [Left <$> psciLet, Right <$> psciExpression]) ls of
248 Left err -> inputTToState $ outputStrLn (show err)
266 Left err -> inputTToState $ outputStrLn (show err)
249 Right (Left l) -> modify (updateLets l)
267 Right (Left l) -> modify (updateLets l)
250 Right (Right decl) -> get >>= inputTToState . handleDeclaration decl
268 Right (Right decl) -> get >>= inputTToState . handleDeclaration decl
@@ -299,20 +317,3 @@ main = do
299 case c of
317 case c of
300 Quit -> outputTStrLn quitMessage
318 Quit -> outputTStrLn quitMessage
301 _ -> handleCommand c >> go
319 _ -> handleCommand c >> go
302−
303−-- |
304−-- Parses the input and returns either a Metacommand or an expression.
305−--
306−getCommand :: InputT IO Command
307−getCommand = do
308− firstLine <- getInputLine "> "
309− case firstLine of
310− Nothing -> return Empty
311− Just line -> either (return . Unknown) (lift . return) (parseCommands line)
312− --Just other -> Expression <$> go [other]
313− --where
314− --go ls = do
315− -- l <- getInputLine " "
316− -- case l of
317− -- Nothing -> return $ reverse ls
318− -- Just l' -> go (l' : ls)
psci/Parser.hs+13−7
@@ -32,7 +32,8 @@ psciModules = P.parseModules
32-- |
32-- |
33-- PSCI version of 'let'.
33-- PSCI version of 'let'.
34-- This is essentially let from do-notation.
34-- This is essentially let from do-notation.
35−-- However, since we don't support the 'Eff' monad, we actually want the normal 'let'.
35+-- However, since we don't support the 'Eff' monad,
36+-- we actually want the normal 'let'.
36--
37--
37psciLet :: Parsec String P.ParseState (P.Value -> P.Value)
38psciLet :: Parsec String P.ParseState (P.Value -> P.Value)
38psciLet = P.Let <$> (P.reserved "let" *> P.indented *> P.parseBinder)
39psciLet = P.Let <$> (P.reserved "let" *> P.indented *> P.parseBinder)
@@ -72,30 +73,35 @@ parseExpression = psciParser psciExpression
72parseCommands :: String -> Either ParseError Command
73parseCommands :: String -> Either ParseError Command
73parseCommands = psciParser $ choice availableCommands
74parseCommands = psciParser $ choice availableCommands
74
75
76+psciExpr :: Parsec String P.ParseState Command
77+psciExpr = Expression <$> (lookAhead (try (satisfy (/= ':'))) *> many1 anyChar)
78+
75psciHelp :: Parsec String P.ParseState Command
79psciHelp :: Parsec String P.ParseState Command
76−psciHelp = Help <$ (string ":?" *> spaces)
80+psciHelp = Help <$ (spaces *> string ":?" *> spaces)
77
81
78psciImport :: Parsec String P.ParseState Command
82psciImport :: Parsec String P.ParseState Command
79−psciImport = Import <$> (string ":i" *> spaces *> P.properName)
83+psciImport = Import <$> (spaces *> string ":i" *> spaces *> P.properName)
80
84
81psciLoadFile :: Parsec String P.ParseState Command
85psciLoadFile :: Parsec String P.ParseState Command
82psciLoadFile = LoadFile <$> do
86psciLoadFile = LoadFile <$> do
87+ spaces
83 string ":m"
88 string ":m"
84 spaces
89 spaces
85 try (manyTill anyChar space) <|> many1 anyChar
90 try (manyTill anyChar space) <|> many1 anyChar
86
91
87psciQuit :: Parsec String P.ParseState Command
92psciQuit :: Parsec String P.ParseState Command
88−psciQuit = Quit <$ (string ":q" *> spaces)
93+psciQuit = Quit <$ (spaces *> string ":q" *> spaces)
89
94
90psciReload :: Parsec String P.ParseState Command
95psciReload :: Parsec String P.ParseState Command
91−psciReload = Reload <$ (string ":r" *> spaces)
96+psciReload = Reload <$ (spaces *> string ":r" *> spaces)
92
97
93psciTypeOf :: Parsec String P.ParseState Command
98psciTypeOf :: Parsec String P.ParseState Command
94−psciTypeOf = TypeOf <$> (string ":t" *> spaces *> many anyChar)
99+psciTypeOf = TypeOf <$> (spaces *> string ":t" *> spaces *> many anyChar)
95
100
96availableCommands :: [Parsec String P.ParseState Command]
101availableCommands :: [Parsec String P.ParseState Command]
97availableCommands =
102availableCommands =
103+ map try [ psciExpr
98− map try [ psciHelp
104+ , psciHelp
99 , psciImport
105 , psciImport
100 , psciLoadFile
106 , psciLoadFile
101 , psciQuit
107 , psciQuit