Skip to content

Commit 0a66f32

Browse files
committed
Merge remote-tracking branch 'origin/master' into release
2 parents f6eaf34 + 0bfbcff commit 0a66f32

File tree

2 files changed

+43
-23
lines changed

2 files changed

+43
-23
lines changed

dev-tools/package.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ executables:
157157
- base
158158
- aeson
159159
- bytestring
160+
- containers
160161
- hs-backend-booster
161162
- prettyprinter
162163
- text

dev-tools/pretty/Pretty.hs

+42-23
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{-# LANGUAGE FlexibleContexts #-}
12
{-# LANGUAGE PatternSynonyms #-}
23

34
{- | Pretty printer for JSON KORE terms
@@ -9,8 +10,19 @@ module Main (
910
main,
1011
) where
1112

13+
import Control.Monad (unless)
14+
import Control.Monad.Trans.Except
15+
import Data.Aeson (eitherDecode)
16+
import Data.ByteString.Lazy qualified as BS
17+
import Data.Map (Map)
18+
import Data.Map qualified as Map
19+
import Data.Text.IO qualified as Text
20+
import Prettyprinter
21+
import System.Environment (getArgs)
22+
23+
import Booster.Pattern.Base (Term, Variable)
1224
import Booster.Pattern.Pretty
13-
import Booster.Prettyprinter (renderDefault)
25+
import Booster.Prettyprinter (renderDefault, renderText)
1426
import Booster.Syntax.Json (KoreJson (..))
1527
import Booster.Syntax.Json.Internalise (
1628
InternalisedPredicates (..),
@@ -21,12 +33,6 @@ import Booster.Syntax.Json.Internalise (
2133
pattern DisallowAlias,
2234
)
2335
import Booster.Syntax.ParsedKore (internalise, parseKoreDefinition)
24-
import Control.Monad.Trans.Except
25-
import Data.Aeson (eitherDecode)
26-
import Data.ByteString.Lazy qualified as BS
27-
import Data.Text.IO qualified as Text
28-
import Prettyprinter
29-
import System.Environment (getArgs)
3036

3137
main :: IO ()
3238
main = do
@@ -40,24 +46,37 @@ main = do
4046
Left err -> putStrLn $ "Error: " ++ err
4147
Right KoreJson{term} -> do
4248
case runExcept $ internalisePattern DisallowAlias CheckSubsorts Nothing internalDef term of
43-
Right (trm, preds, ceils, _subst, _unsupported) -> do
44-
putStrLn "Pretty-printing pattern: "
45-
putStrLn $ renderDefault $ pretty' @'[Decoded] trm
46-
putStrLn "Bool predicates: "
47-
mapM_ (putStrLn . renderDefault . pretty' @'[Decoded]) preds
48-
putStrLn "Ceil predicates: "
49-
mapM_ (putStrLn . renderDefault . pretty' @'[Decoded]) ceils
49+
Right (trm, preds, ceils, subst, unsupported) -> do
50+
Text.putStrLn . renderText . vsep $
51+
[ "Pretty-printing pattern:"
52+
, pretty' @'[Decoded, Infix] trm
53+
, renderThings "Bool predicates:" preds
54+
, renderThings "Ceil predicates:" ceils
55+
, hang 2 $ "Substitution:" <> line <> showSubst subst
56+
]
57+
unless (null unsupported) $ do
58+
putStrLn $ "...as well as " <> show (length unsupported) <> " unsupported parts:"
59+
mapM_ print unsupported
5060
Left (NoTermFound _) ->
5161
case runExcept $ internalisePredicates DisallowAlias CheckSubsorts Nothing internalDef [term] of
5262
Left es -> error (show es)
5363
Right ts -> do
54-
putStrLn "Pretty-printing predicates: "
55-
putStrLn "Bool predicates: "
56-
mapM_ (putStrLn . renderDefault . pretty' @'[Decoded]) ts.boolPredicates
57-
putStrLn "Ceil predicates: "
58-
mapM_ (putStrLn . renderDefault . pretty' @'[Decoded]) ts.ceilPredicates
59-
putStrLn "Substitution: "
60-
mapM_ (putStrLn . renderDefault . pretty' @'[Decoded]) ts.substitution
61-
putStrLn "Unsupported predicates: "
62-
mapM_ print ts.unsupported
64+
Text.putStrLn . renderText . vsep $
65+
[ "Pretty-printing predicates:"
66+
, renderThings "Bool predicates:" ts.boolPredicates
67+
, renderThings "Ceil predicates:" ts.ceilPredicates
68+
, hang 2 $ "Substitution:" <> line <> showSubst ts.substitution
69+
]
70+
unless (null ts.unsupported) $ do
71+
putStrLn $ "...as well as " <> show (length ts.unsupported) <> " unsupported parts:"
72+
mapM_ print ts.unsupported
6373
Left err -> error (show err)
74+
where
75+
showSubst :: Map Variable Term -> Doc ann
76+
showSubst m =
77+
vsep
78+
[pretty' @'[Decoded] v <+> "->" <+> pretty' @'[Decoded, Infix] expr | (v, expr) <- Map.assocs m]
79+
80+
renderThings :: Pretty (PrettyWithModifiers '[Decoded, Infix] a) => Doc ann -> [a] -> Doc ann
81+
renderThings heading [] = heading <> " -"
82+
renderThings heading things = hang 2 $ vsep $ heading : map (pretty' @'[Decoded, Infix]) things

0 commit comments

Comments
 (0)