git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Bit of cleanup and documentation. Fixes #216.
commit4e87a31ed9a012feac99b663ff3e8c03a29b1d95 authorjoneshf <jones3.hardy@gmail.com> dateFri 21 Feb 2014, 15:16 (13 years ago) parent4b9abe3
2 files changed+43−18
psci/Main.hs+1−2 psci/Parser.hs+42−16
psci/Main.hs+1−2
@@ -253,8 +253,7 @@ getCommand = do
253253 _ -> lift $ return c
254254 where
255255 go :: [String] -> InputT IO String
256− go ls =
257− maybe (return . unlines $ reverse ls) (go . (:ls)) =<< getInputLine " "
256+ go ls = maybe (return . unlines $ reverse ls) (go . (:ls)) =<< getInputLine " "
258257
259258-- |
260259-- Performs an action for each meta-command given, and also for expressions..
psci/Parser.hs+42−16
@@ -30,10 +30,10 @@ psciModules :: Parsec String P.ParseState [P.Module]
3030psciModules = P.parseModules
3131
3232-- |
33−-- PSCI version of 'let'.
33+-- PSCI version of @let@.
3434-- This is essentially let from do-notation.
35−-- However, since we don't support the 'Eff' monad,
36−-- we actually want the normal 'let'.
35+-- However, since we don't support the @Eff@ monad,
36+-- we actually want the normal @let@.
3737--
3838psciLet :: Parsec String P.ParseState (P.Value -> P.Value)
3939psciLet = P.Let <$> (P.reserved "let" *> P.indented *> P.parseBinder)
@@ -59,29 +59,44 @@ parseModules :: String -> Either ParseError [P.Module]
5959parseModules = psciParser psciModules
6060
6161-- |
62−-- Parses PSCI 'let' bindings.
62+-- Parses PSCI @let@ bindings.
6363--
6464parseLet :: String -> Either ParseError (P.Value -> P.Value)
6565parseLet = psciParser psciLet
6666
6767-- |
68−-- Parses PSCI expressions.
68+-- Parses PSCI @expressions@.
6969--
7070parseExpression :: String -> Either ParseError P.Value
7171parseExpression = psciParser psciExpression
7272
73+-- |
74+-- Parses PSCI metacommands or expressions input from the user.
75+--
7376parseCommands :: String -> Either ParseError Command
74−parseCommands = psciParser $ choice availableCommands
77+parseCommands = psciParser $ choice (map try availableCommands)
7578
79+-- |
80+-- Parses expressions entered at the PSCI repl.
81+--
7682psciExpr :: Parsec String P.ParseState Command
77−psciExpr = Expression <$> (lookAhead (try (satisfy (/= ':'))) *> many1 anyChar)
83+psciExpr = Expression <$> (lookAhead (try (noneOf ":")) *> many1 anyChar)
7884
85+-- |
86+-- Parses 'Commands.Help' command.
87+--
7988psciHelp :: Parsec String P.ParseState Command
8089psciHelp = Help <$ (spaces *> string ":?" *> spaces)
8190
91+-- |
92+-- Parses 'Commands.Import' command.
93+--
8294psciImport :: Parsec String P.ParseState Command
8395psciImport = Import <$> (spaces *> string ":i" *> spaces *> P.properName)
8496
97+-- |
98+-- Parses 'Commands.LoadFile' command.
99+--
85100psciLoadFile :: Parsec String P.ParseState Command
86101psciLoadFile = LoadFile <$> do
87102 spaces
@@ -89,22 +104,33 @@ psciLoadFile = LoadFile <$> do
89104 spaces
90105 try (manyTill anyChar space) <|> many1 anyChar
91106
107+-- |
108+-- Parses 'Commands.Quit' command.
109+--
92110psciQuit :: Parsec String P.ParseState Command
93111psciQuit = Quit <$ (spaces *> string ":q" *> spaces)
94112
113+-- |
114+-- Parses 'Commands.Reload' command.
115+--
95116psciReload :: Parsec String P.ParseState Command
96117psciReload = Reload <$ (spaces *> string ":r" *> spaces)
97118
119+-- |
120+-- Parses 'Commands.TypeOf' command.
121+--
98122psciTypeOf :: Parsec String P.ParseState Command
99123psciTypeOf = TypeOf <$> (spaces *> string ":t" *> spaces *> many anyChar)
100124
125+-- |
126+-- List of commands that are available from PSCI.
127+--
101128availableCommands :: [Parsec String P.ParseState Command]
102−availableCommands =
103− map try [ psciExpr
104− , psciHelp
105− , psciImport
106− , psciLoadFile
107− , psciQuit
108− , psciReload
109− , psciTypeOf
110− ]
129+availableCommands = [ psciExpr
130+ , psciHelp
131+ , psciImport
132+ , psciLoadFile
133+ , psciQuit
134+ , psciReload
135+ , psciTypeOf
136+ ]