git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Works with trailing whitespace
commit558d43df2c48515939e4ee886b9c8e9ffe0c5e41 authorjoneshf <jones3.hardy@gmail.com> dateFri 21 Feb 2014, 14:22 (13 years ago) parent55f98d9
2 files changed+31−17
psci/Main.hs+7−12 psci/Parser.hs+24−5
psci/Main.hs+7−12
@@ -308,16 +308,11 @@ getCommand = do
308308 firstLine <- getInputLine "> "
309309 case firstLine of
310310 Nothing -> return Empty
311− Just line -> either (return . Unknown) lift (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
311+ Just line -> either (return . Unknown) (lift . return) (parseCommands line)
317312 --Just other -> Expression <$> go [other]
318− where
319− go ls = do
320− l <- getInputLine " "
321− case l of
322− Nothing -> return $ reverse ls
323− Just l' -> go (l' : ls)
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+24−5
@@ -17,7 +17,7 @@ module Parser where
1717
1818import Commands
1919
20−import Control.Applicative
20+import Control.Applicative hiding (many)
2121
2222import Text.Parsec hiding ((<|>))
2323
@@ -69,17 +69,36 @@ parseLet = psciParser psciLet
6969parseExpression :: String -> Either ParseError P.Value
7070parseExpression = psciParser psciExpression
7171
72−parseCommands :: String -> Either ParseError (IO Command)
73−parseCommands = either Left (Right . return) . psciParser (choice availableCommands)
72+parseCommands :: String -> Either ParseError Command
73+parseCommands = psciParser $ choice availableCommands
7474
7575psciHelp :: Parsec String P.ParseState Command
76−psciHelp = Help <$ (string ":?" >> spaces)
76+psciHelp = Help <$ (string ":?" *> spaces)
7777
7878psciImport :: 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)
8095
8196availableCommands :: [Parsec String P.ParseState Command]
8297availableCommands =
8398 map try [ psciHelp
8499 , psciImport
100+ , psciLoadFile
101+ , psciQuit
102+ , psciReload
103+ , psciTypeOf
85104 ]