Skip to content

Commit 5795b41

Browse files
committed
pretty: print substitution as bindings, separate imports
1 parent 1a34695 commit 5795b41

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

dev-tools/package.yaml

Lines changed: 1 addition & 0 deletions
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

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,15 @@ module Main (
99
main,
1010
) where
1111

12+
import Control.Monad.Trans.Except
13+
import Data.Aeson (eitherDecode)
14+
import Data.ByteString.Lazy qualified as BS
15+
import Data.Map qualified as Map
16+
import Data.Text.IO qualified as Text
17+
import Prettyprinter
18+
import System.Environment (getArgs)
19+
20+
import Booster.Pattern.Base (Term, Variable (..))
1221
import Booster.Pattern.Pretty
1322
import Booster.Prettyprinter (renderDefault)
1423
import Booster.Syntax.Json (KoreJson (..))
@@ -21,12 +30,6 @@ import Booster.Syntax.Json.Internalise (
2130
pattern DisallowAlias,
2231
)
2332
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)
3033

3134
main :: IO ()
3235
main = do
@@ -40,9 +43,11 @@ main = do
4043
Left err -> putStrLn $ "Error: " ++ err
4144
Right KoreJson{term} -> do
4245
case runExcept $ internalisePattern DisallowAlias CheckSubsorts Nothing internalDef term of
43-
Right (trm, _subst, _unsupported) -> do
46+
Right (trm, subst, _unsupported) -> do
4447
putStrLn "Pretty-printing pattern: "
4548
putStrLn $ renderDefault $ pretty' @'[Decoded] trm
49+
putStrLn "Substitution: "
50+
mapM_ (putStrLn . prettyPrintSubstItem) (Map.toList subst)
4651
Left (NoTermFound _) ->
4752
case runExcept $ internalisePredicates DisallowAlias CheckSubsorts Nothing internalDef [term] of
4853
Left es -> error (show es)
@@ -53,7 +58,10 @@ main = do
5358
putStrLn "Ceil predicates: "
5459
mapM_ (putStrLn . renderDefault . pretty' @'[Decoded]) ts.ceilPredicates
5560
putStrLn "Substitution: "
56-
mapM_ (putStrLn . renderDefault . pretty' @'[Decoded]) ts.substitution
61+
mapM_ (putStrLn . prettyPrintSubstItem) (Map.toList ts.substitution)
5762
putStrLn "Unsupported predicates: "
5863
mapM_ print ts.unsupported
5964
Left err -> error (show err)
65+
66+
prettyPrintSubstItem :: (Variable, Term) -> String
67+
prettyPrintSubstItem (v, t) = show v.variableName <> " |-> " <> (renderDefault . pretty' @'[Decoded] $ t)

0 commit comments

Comments
 (0)