git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Bit of cleanup and documentation. Fixes #216.
4e87a31joneshf
psci/Main.hs+1−2
@@ -253,8 +253,7 @@ getCommand = do
253 _ -> lift $ return c
253 _ -> lift $ return c
254 where
254 where
255 go :: [String] -> InputT IO String
255 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 " "
258
257
259-- |
258-- |
260-- Performs an action for each meta-command given, and also for expressions..
259-- 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]
30psciModules = P.parseModules
30psciModules = P.parseModules
31
31
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,
35+-- However, since we don't support the @Eff@ monad,
36−-- we actually want the normal 'let'.
36+-- we actually want the normal @let@.
37--
37--
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
60
60
61-- |
61-- |
62−-- Parses PSCI 'let' bindings.
62+-- Parses PSCI @let@ bindings.
63--
63--
64parseLet :: String -> Either ParseError (P.Value -> P.Value)
64parseLet :: String -> Either ParseError (P.Value -> P.Value)
65parseLet = psciParser psciLet
65parseLet = psciParser psciLet
66
66
67-- |
67-- |
68−-- Parses PSCI expressions.
68+-- Parses PSCI @expressions@.
69--
69--
70parseExpression :: String -> Either ParseError P.Value
70parseExpression :: String -> Either ParseError P.Value
71parseExpression = psciParser psciExpression
71parseExpression = psciParser psciExpression
72
72
73+-- |
74+-- Parses PSCI metacommands or expressions input from the user.
75+--
73parseCommands :: String -> Either ParseError Command
76parseCommands :: String -> Either ParseError Command
74−parseCommands = psciParser $ choice availableCommands
77+parseCommands = psciParser $ choice (map try availableCommands)
75
78
79+-- |
80+-- Parses expressions entered at the PSCI repl.
81+--
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)
78
84
85+-- |
86+-- Parses 'Commands.Help' command.
87+--
79psciHelp :: Parsec String P.ParseState Command
88psciHelp :: Parsec String P.ParseState Command
80psciHelp = Help <$ (spaces *> string ":?" *> spaces)
89psciHelp = Help <$ (spaces *> string ":?" *> spaces)
81
90
91+-- |
92+-- Parses 'Commands.Import' command.
93+--
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)
84
96
97+-- |
98+-- Parses 'Commands.LoadFile' command.
99+--
85psciLoadFile :: Parsec String P.ParseState Command
100psciLoadFile :: Parsec String P.ParseState Command
86psciLoadFile = LoadFile <$> do
101psciLoadFile = LoadFile <$> do
87 spaces
102 spaces
@@ -89,22 +104,33 @@ psciLoadFile = LoadFile <$> do
89 spaces
104 spaces
90 try (manyTill anyChar space) <|> many1 anyChar
105 try (manyTill anyChar space) <|> many1 anyChar
91
106
107+-- |
108+-- Parses 'Commands.Quit' command.
109+--
92psciQuit :: Parsec String P.ParseState Command
110psciQuit :: Parsec String P.ParseState Command
93psciQuit = Quit <$ (spaces *> string ":q" *> spaces)
111psciQuit = Quit <$ (spaces *> string ":q" *> spaces)
94
112
113+-- |
114+-- Parses 'Commands.Reload' command.
115+--
95psciReload :: Parsec String P.ParseState Command
116psciReload :: Parsec String P.ParseState Command
96psciReload = Reload <$ (spaces *> string ":r" *> spaces)
117psciReload = Reload <$ (spaces *> string ":r" *> spaces)
97
118
119+-- |
120+-- Parses 'Commands.TypeOf' command.
121+--
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)
100
124
125+-- |
126+-- List of commands that are available from PSCI.
127+--
101availableCommands :: [Parsec String P.ParseState Command]
128availableCommands :: [Parsec String P.ParseState Command]
102−availableCommands =
129+availableCommands = [ psciExpr
103− map try [ 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
110− ]
136+ ]