Skip to content

Commit ece1b22

Browse files
committed
REPL: Edit width should be 80. NFCI
1 parent ec7a585 commit ece1b22

File tree

5 files changed

+68
-37
lines changed

5 files changed

+68
-37
lines changed

saw-script/src/SAWScript/REPL.hs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,25 +38,26 @@ run mfile opts = do
3838
(_result, _rst') <- runREPL (repl mfile) rst
3939
return ()
4040

41-
-- | Function to enter a nested TopLevel REPL, passed down into the interpreter
42-
-- to avoid cyclic dependencies.
41+
-- | Function to enter a nested TopLevel REPL, passed down into the
42+
-- interpreter to avoid cyclic dependencies.
4343
--
44-
-- Note that there isn't any REPL state that needs to be transferred to the
45-
-- nested instance, only the interpreter state.
44+
-- Note that there isn't any REPL state that needs to be transferred
45+
-- to the nested instance, only the interpreter state.
4646
--
4747
reenterTopLevel :: TopLevelRO -> TopLevelRW -> IO TopLevelRW
4848
reenterTopLevel ro rw = do
4949
let rst = resumeREPL ro rw Nothing
5050
(_result, rst') <- runREPL (repl Nothing) rst
5151
return $ rTopLevelRW rst'
5252

53-
-- | Function to enter a nested ProofScript REPL, passed down into the interpreter
54-
-- to avoid cyclic dependencies.
53+
-- | Function to enter a nested ProofScript REPL, passed down into the
54+
-- interpreter to avoid cyclic dependencies.
5555
--
56-
-- Note that there isn't any REPL state that needs to be transferred to the
57-
-- nested instance, only the interpreter state.
56+
-- Note that there isn't any REPL state that needs to be transferred
57+
-- to the nested instance, only the interpreter state.
5858
--
59-
reenterProofScript :: TopLevelRO -> TopLevelRW -> ProofState -> IO (TopLevelRW, ProofState)
59+
reenterProofScript ::
60+
TopLevelRO -> TopLevelRW -> ProofState -> IO (TopLevelRW, ProofState)
6061
reenterProofScript ro rw pst = do
6162
let rst = resumeREPL ro rw (Just pst)
6263
(_result, rst') <- runREPL (repl Nothing) rst

saw-script/src/SAWScript/REPL/Command.hs

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,10 @@ failOn errs = case (reverse errs) of
7777
fail (Text.unpack lastMsg)
7878

7979
cdCmd :: FilePath -> REPL ()
80-
cdCmd f | null f = liftIO $ putStrLn $ "Error: The :cd command requires a path argument"
81-
| otherwise = do
80+
cdCmd f
81+
| null f =
82+
liftIO $ putStrLn "Error: The :cd command requires a path argument"
83+
| otherwise = do
8284
exists <- liftIO $ doesDirectoryExist f
8385
if exists
8486
then liftIO $ setCurrentDirectory f
@@ -141,7 +143,9 @@ quitCmd =
141143

142144
searchCmd :: Text -> REPL ()
143145
searchCmd str
144-
| Text.null str = liftIO $ putStrLn $ "Error: The :search command requires at least one argument"
146+
| Text.null str =
147+
let msg = "Error: The :search command requires at least one argument" in
148+
liftIO $ putStrLn msg
145149
| otherwise = do
146150

147151
-- FUTURE: it would be nice to be able to use the words
@@ -162,7 +166,8 @@ searchCmd str
162166
rw <- getTopLevelRW
163167
let environ = rwEnviron rw
164168
rebindables = rwRebindables rw
165-
errs_or_pat <- liftIO $ Loader.readSchemaPattern replFileName environ rebindables avail str
169+
errs_or_pat <- liftIO $
170+
Loader.readSchemaPattern replFileName environ rebindables avail str
166171
pat <- case errs_or_pat of
167172
Left errs -> failOn errs
168173
Right p -> return p
@@ -213,7 +218,8 @@ searchCmd str
213218
" with unexpected lifecycle " <> Text.pack (show lc)
214219
]
215220
(visMatches, expMatches, depMatches) =
216-
Map.foldrWithKey inspect (Map.empty, Map.empty, Map.empty) allMatches
221+
let empty = (Map.empty, Map.empty, Map.empty) in
222+
Map.foldrWithKey inspect empty allMatches
217223

218224
printMatch (name, (lc, ty)) = do
219225
let ty' = PPS.pShowText ty
@@ -252,13 +258,13 @@ searchCmd str
252258
else do
253259
liftIO $ putStrLn "No matches."
254260
if not (Map.null expMatches) then do
255-
liftIO $ putStrLn $ "The following experimental matches require " ++
256-
"enable_experimental:"
261+
liftIO $ putStrLn $ "The following experimental matches " ++
262+
" require enable_experimental:"
257263
printMatches expMatches
258264
alsoDeprecated
259265
else if not (Map.null depMatches) then do
260266
liftIO $ putStrLn $ "The following deprecated matches require " ++
261-
"enable_deprecated:"
267+
"enable_deprecated:"
262268
printMatches depMatches
263269
else
264270
pure ()
@@ -280,13 +286,15 @@ tenvCmd = do
280286

281287
typeOfCmd :: Text -> REPL ()
282288
typeOfCmd str
283-
| Text.null str = liftIO $ putStrLn "Error: The :type command requires an argument"
289+
| Text.null str =
290+
liftIO $ putStrLn "Error: The :type command requires an argument"
284291
| otherwise = do
285292
rw <- getTopLevelRW
286293
let environ = rwEnviron rw
287294
rebindables = rwRebindables rw
288295
avail = rwPrimsAvail rw
289-
errs_or_expr <- liftIO $ Loader.readExpression replFileName environ rebindables avail str
296+
errs_or_expr <- liftIO $
297+
Loader.readExpression replFileName environ rebindables avail str
290298
(schema, _expr) <- case errs_or_expr of
291299
Left errs -> failOn errs
292300
Right info -> return info
@@ -448,7 +456,8 @@ executeReplCommand cmd args0 =
448456
[] -> action ""
449457
[arg] -> action arg
450458
_ -> do
451-
let msg = "The command " <> cName cmd <> " takes only one argument"
459+
let msg = "The command " <> cName cmd <>
460+
" takes only one argument"
452461
liftIO $ TextIO.putStrLn msg
453462
in
454463
exceptionProtect $ case cBody cmd of
@@ -467,7 +476,9 @@ executeReplCommand cmd args0 =
467476
-- | Execute REPL :-command text.
468477
executeReplCommandText :: Text -> REPL ()
469478
executeReplCommandText text =
470-
let textWords = filter (\w -> not $ Text.null w) $ Text.split isSpace text in
479+
let textWords =
480+
filter (\w -> not $ Text.null w) $ Text.split isSpace text
481+
in
471482
case textWords of
472483
[] -> pure ()
473484
cmdName : args ->
@@ -476,8 +487,9 @@ executeReplCommandText text =
476487
-- Historically SAW accepts ":?cmd" without a space
477488
if Text.isPrefixOf ":?" cmdName then
478489
executeReplCommandText $ ":? " <> Text.drop 2 cmdName
479-
else
480-
liftIO $ TextIO.putStrLn $ "Unknown command: " <> cmdName
490+
else do
491+
let msg = "Unknown command: " <> cmdName
492+
liftIO $ TextIO.putStrLn msg
481493
[cmd] ->
482494
executeReplCommand cmd args
483495
cmds -> liftIO $ do

saw-script/src/SAWScript/REPL/Data.hs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,15 @@ import SAWScript.REPL.Monad
5050
getCryptolExprNames :: REPL [Text]
5151
getCryptolExprNames =
5252
do fNames <- fmap getNamingEnv getCryptolEnv
53-
return (map (Text.pack . show . pp) (Map.keys (MN.namespaceMap NSValue fNames)))
53+
let keys = Map.keys (MN.namespaceMap NSValue fNames)
54+
return (map (Text.pack . show . pp) keys)
5455

5556
-- | Get visible Cryptol type names.
5657
getCryptolTypeNames :: REPL [Text]
5758
getCryptolTypeNames =
5859
do fNames <- fmap getNamingEnv getCryptolEnv
59-
return (map (Text.pack . show . pp) (Map.keys (MN.namespaceMap NSType fNames)))
60+
let keys = Map.keys (MN.namespaceMap NSType fNames)
61+
return (map (Text.pack . show . pp) keys)
6062

6163
-- | Get visible variable names for Haskeline completion.
6264
getSAWScriptValueNames :: REPL [Text]

saw-script/src/SAWScript/REPL/Haskeline.hs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ License : BSD3
77
Maintainer : saw@galois.com
88
Stability : provisional
99
10-
Haskeline interface layer with main REPL loop and tab completion support.
10+
Haskeline interface layer with main REPL loop and tab completion
11+
support.
1112
-}
1213

1314
module SAWScript.REPL.Haskeline (repl) where
@@ -335,7 +336,8 @@ completeReplCommand text cursor =
335336
-- text on the line, the LHS of the return value should
336337
-- always be the LHS of the input cursor.
337338

338-
let completion cmd = appendCompletion (Text.length cmdPrefix, cName cmd)
339+
let completion cmd =
340+
appendCompletion (Text.length cmdPrefix, cName cmd)
339341
let completions = map completion $ searchCommandsByPrefix cmdPrefix
340342
return (cursorLeftRaw cursor, completions)
341343
cmdName : args ->
@@ -354,8 +356,8 @@ completeReplCommand text cursor =
354356
-- but you can only actually give it one. Should
355357
-- strengthen the argument schema.
356358
case cBody cmd of
357-
ExprArg _ -> completeSAWScriptValue (last args) cursor
358-
TypeArgs _ -> completeSAWScriptType (last args) cursor
359+
ExprArg _ -> completeSAWScriptValue (last args) cursor
360+
TypeArgs _ -> completeSAWScriptType (last args) cursor
359361
FilenameArg _ -> completeFilename cursor
360362
ShellArg _ -> completeFilename cursor
361363
NoArg _ -> return (cursorLeftRaw cursor, [])

saw-script/src/SAWScript/REPL/Monad.hs

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ module SAWScript.REPL.Monad (
3030
) where
3131

3232
import Control.Monad (void)
33-
import Control.Monad.Catch (MonadThrow(..), MonadCatch(..), MonadMask(..), catchJust)
33+
import Control.Monad.Catch (
34+
MonadThrow(..), MonadCatch(..), MonadMask(..),
35+
catchJust
36+
)
3437
import Control.Monad.State (MonadState(..), StateT(..), get, gets, modify)
3538
import Control.Monad.Except (runExceptT)
3639
import Control.Monad.IO.Class (MonadIO(..))
@@ -42,9 +45,14 @@ import CryptolSAWCore.CryptolEnv
4245

4346
import SAWCentral.Options (Options)
4447
import SAWCentral.Proof (ProofState, ProofResult(..))
45-
import SAWCentral.TopLevel (TopLevelRO(..), TopLevelRW(..), TopLevel(..), runTopLevel)
46-
import SAWCentral.Value (ProofScript(..), showsProofResult,
47-
rwGetCryptolEnv, TopLevelShellHook, ProofScriptShellHook)
48+
import SAWCentral.TopLevel (
49+
TopLevelRO(..), TopLevelRW(..), TopLevel(..),
50+
runTopLevel
51+
)
52+
import SAWCentral.Value (
53+
ProofScript(..), showsProofResult,
54+
rwGetCryptolEnv, TopLevelShellHook, ProofScriptShellHook
55+
)
4856

4957
import SAWScript.Panic (panic)
5058
import SAWScript.Interpreter (buildTopLevelEnv)
@@ -64,7 +72,9 @@ data REPLState = REPLState
6472
}
6573

6674
-- | Create an initial, empty environment.
67-
initREPL :: Bool -> Options -> TopLevelShellHook -> ProofScriptShellHook -> IO REPLState
75+
initREPL ::
76+
Bool -> Options -> TopLevelShellHook -> ProofScriptShellHook ->
77+
IO REPLState
6878
initREPL isBatch opts tlhook pshook =
6979
do (ro, rw) <- buildTopLevelEnv opts [] tlhook pshook
7080
return REPLState
@@ -93,7 +103,9 @@ resumeREPL ro rw mpst =
93103

94104
-- | REPL monad context.
95105
newtype REPL a = REPL { unREPL :: StateT REPLState IO a }
96-
deriving (Applicative, Functor, Monad, MonadThrow, MonadCatch, MonadMask, MonadFail)
106+
deriving (
107+
Applicative, Functor, Monad, MonadThrow, MonadCatch, MonadMask, MonadFail
108+
)
97109

98110
deriving instance MonadState REPLState REPL
99111

@@ -119,7 +131,8 @@ liftProofScript m = do
119131
let pst = case mpst of
120132
Nothing -> panic "liftProofScript" ["Not in ProofScript mode"]
121133
Just ps -> ps
122-
(result, pst') <- liftTopLevel $ runStateT (runExceptT (unProofScript m)) pst
134+
(result, pst') <-
135+
liftTopLevel $ runStateT (runExceptT (unProofScript m)) pst
123136
modify (\st -> st { rProofState = Just pst' })
124137
liftTopLevel $ case result of
125138
Left (stats, cex) ->
@@ -157,7 +170,8 @@ catchFail m k = catchJust sel m k
157170
sel e | isUserError e = Just (ioeGetErrorString e)
158171
| otherwise = Nothing
159172

160-
-- | Handle any other exception (except that we ignore async exceptions and exitWith)
173+
-- | Handle any other exception (except that we ignore async
174+
-- exceptions and exitWith)
161175
catchOther :: REPL a -> (X.SomeException -> REPL a) -> REPL a
162176
catchOther m k = catchJust flt m k
163177
where

0 commit comments

Comments
 (0)