@@ -30,10 +30,10 @@ psciModules :: Parsec String P.ParseState [P.Module]
30psciModules = P.parseModules
30psciModules = P.parseModules
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,
35+-- However, since we don't support the @Eff@ monad,
36−-- we actually want the normal 'let'.
36+-- we actually want the normal @let@.
38psciLet :: Parsec String P.ParseState (P.Value -> P.Value)
38psciLet :: Parsec String P.ParseState (P.Value -> P.Value)
39psciLet = P.Let <$> (P.reserved "let" *> P.indented *> P.parseBinder)
39psciLet = P.Let <$> (P.reserved "let" *> P.indented *> P.parseBinder)
@@ -59,29 +59,44 @@ parseModules :: String -> Either ParseError [P.Module]
59parseModules = psciParser psciModules
59parseModules = psciParser psciModules
62−-- Parses PSCI 'let' bindings.
62+-- Parses PSCI @let@ bindings.
64parseLet :: String -> Either ParseError (P.Value -> P.Value)
64parseLet :: String -> Either ParseError (P.Value -> P.Value)
65parseLet = psciParser psciLet
65parseLet = psciParser psciLet
68−-- Parses PSCI expressions.
68+-- Parses PSCI @expressions@.
70parseExpression :: String -> Either ParseError P.Value
70parseExpression :: String -> Either ParseError P.Value
71parseExpression = psciParser psciExpression
71parseExpression = psciParser psciExpression
74+-- Parses PSCI metacommands or expressions input from the user.
73parseCommands :: String -> Either ParseError Command
76parseCommands :: String -> Either ParseError Command
74−parseCommands = psciParser $ choice availableCommands
77+parseCommands = psciParser $ choice (map try availableCommands)
80+-- Parses expressions entered at the PSCI repl.
76psciExpr :: Parsec String P.ParseState Command
82psciExpr :: Parsec String P.ParseState Command
77−psciExpr = Expression <$> (lookAhead (try (satisfy (/= ':'))) *> many1 anyChar)
83+psciExpr = Expression <$> (lookAhead (try (noneOf ":")) *> many1 anyChar)
86+-- Parses 'Commands.Help' command.
79psciHelp :: Parsec String P.ParseState Command
88psciHelp :: Parsec String P.ParseState Command
80psciHelp = Help <$ (spaces *> string ":?" *> spaces)
89psciHelp = Help <$ (spaces *> string ":?" *> spaces)
92+-- Parses 'Commands.Import' command.
82psciImport :: Parsec String P.ParseState Command
94psciImport :: Parsec String P.ParseState Command
83psciImport = Import <$> (spaces *> string ":i" *> spaces *> P.properName)
95psciImport = Import <$> (spaces *> string ":i" *> spaces *> P.properName)
98+-- Parses 'Commands.LoadFile' command.
85psciLoadFile :: Parsec String P.ParseState Command
100psciLoadFile :: Parsec String P.ParseState Command
86psciLoadFile = LoadFile <$> do
101psciLoadFile = LoadFile <$> do
@@ -89,22 +104,33 @@ psciLoadFile = LoadFile <$> do
90 try (manyTill anyChar space) <|> many1 anyChar
105 try (manyTill anyChar space) <|> many1 anyChar
108+-- Parses 'Commands.Quit' command.
92psciQuit :: Parsec String P.ParseState Command
110psciQuit :: Parsec String P.ParseState Command
93psciQuit = Quit <$ (spaces *> string ":q" *> spaces)
111psciQuit = Quit <$ (spaces *> string ":q" *> spaces)
114+-- Parses 'Commands.Reload' command.
95psciReload :: Parsec String P.ParseState Command
116psciReload :: Parsec String P.ParseState Command
96psciReload = Reload <$ (spaces *> string ":r" *> spaces)
117psciReload = Reload <$ (spaces *> string ":r" *> spaces)
120+-- Parses 'Commands.TypeOf' command.
98psciTypeOf :: Parsec String P.ParseState Command
122psciTypeOf :: Parsec String P.ParseState Command
99psciTypeOf = TypeOf <$> (spaces *> string ":t" *> spaces *> many anyChar)
123psciTypeOf = TypeOf <$> (spaces *> string ":t" *> spaces *> many anyChar)
126+-- List of commands that are available from PSCI.
101availableCommands :: [Parsec String P.ParseState Command]
128availableCommands :: [Parsec String P.ParseState Command]
102−availableCommands =
129+availableCommands = [ psciExpr
104− , psciHelp
130+ , psciHelp
105− , psciImport
131+ , psciImport
106− , psciLoadFile
132+ , psciLoadFile
107− , psciQuit
133+ , psciQuit
108− , psciReload
134+ , psciReload
109− , psciTypeOf
135+ , psciTypeOf