git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Works with trailing whitespace
558d43djoneshf
psci/Main.hs+7−12
@@ -308,16 +308,11 @@ getCommand = do
308 firstLine <- getInputLine "> "
308 firstLine <- getInputLine "> "
309 case firstLine of
309 case firstLine of
310 Nothing -> return Empty
310 Nothing -> return Empty
311− Just line -> either (return . Unknown) lift (parseCommands line)
311+ Just line -> either (return . Unknown) (lift . return) (parseCommands line)
312− --Just (':':'m':' ':filePath) -> return $ LoadFile filePath
313− --Just ":q" -> return Quit
314− --Just ":r" -> return Reload
315− --Just (':':'t':' ':expr) -> return $ TypeOf expr
316− --Just (':':_) -> return Unknown
317 --Just other -> Expression <$> go [other]
312 --Just other -> Expression <$> go [other]
318− where
313+ --where
319− go ls = do
314+ --go ls = do
320− l <- getInputLine " "
315+ -- l <- getInputLine " "
321− case l of
316+ -- case l of
322− Nothing -> return $ reverse ls
317+ -- Nothing -> return $ reverse ls
323− Just l' -> go (l' : ls)
318+ -- Just l' -> go (l' : ls)
psci/Parser.hs+24−5
@@ -17,7 +17,7 @@ module Parser where
17
17
18import Commands
18import Commands
19
19
20−import Control.Applicative
20+import Control.Applicative hiding (many)
21
21
22import Text.Parsec hiding ((<|>))
22import Text.Parsec hiding ((<|>))
23
23
@@ -69,17 +69,36 @@ parseLet = psciParser psciLet
69parseExpression :: String -> Either ParseError P.Value
69parseExpression :: String -> Either ParseError P.Value
70parseExpression = psciParser psciExpression
70parseExpression = psciParser psciExpression
71
71
72−parseCommands :: String -> Either ParseError (IO Command)
72+parseCommands :: String -> Either ParseError Command
73−parseCommands = either Left (Right . return) . psciParser (choice availableCommands)
73+parseCommands = psciParser $ choice availableCommands
74
74
75psciHelp :: Parsec String P.ParseState Command
75psciHelp :: Parsec String P.ParseState Command
76−psciHelp = Help <$ (string ":?" >> spaces)
76+psciHelp = Help <$ (string ":?" *> spaces)
77
77
78psciImport :: Parsec String P.ParseState Command
78psciImport :: Parsec String P.ParseState Command
79−psciImport = Import <$> (string ":i" >> spaces >> P.properName)
79+psciImport = Import <$> (string ":i" *> spaces *> P.properName)
80+
81+psciLoadFile :: Parsec String P.ParseState Command
82+psciLoadFile = LoadFile <$> do
83+ string ":m"
84+ spaces
85+ try (manyTill anyChar space) <|> many1 anyChar
86+
87+psciQuit :: Parsec String P.ParseState Command
88+psciQuit = Quit <$ (string ":q" *> spaces)
89+
90+psciReload :: Parsec String P.ParseState Command
91+psciReload = Reload <$ (string ":r" *> spaces)
92+
93+psciTypeOf :: Parsec String P.ParseState Command
94+psciTypeOf = TypeOf <$> (string ":t" *> spaces *> many anyChar)
80
95
81availableCommands :: [Parsec String P.ParseState Command]
96availableCommands :: [Parsec String P.ParseState Command]
82availableCommands =
97availableCommands =
83 map try [ psciHelp
98 map try [ psciHelp
84 , psciImport
99 , psciImport
100+ , psciLoadFile
101+ , psciQuit
102+ , psciReload
103+ , psciTypeOf
85 ]
104 ]