Skip to content

Commit

Permalink
✨ Added GPretty class
Browse files Browse the repository at this point in the history
  • Loading branch information
lsrcz committed Jul 20, 2023
1 parent e870bc1 commit 0dab0e7
Show file tree
Hide file tree
Showing 14 changed files with 847 additions and 8 deletions.
5 changes: 5 additions & 0 deletions grisette.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ library
Grisette.Core.Data.Class.ExtractSymbolics
Grisette.Core.Data.Class.Function
Grisette.Core.Data.Class.GenSym
Grisette.Core.Data.Class.GPretty
Grisette.Core.Data.Class.Mergeable
Grisette.Core.Data.Class.ModelOps
Grisette.Core.Data.Class.SafeArith
Expand Down Expand Up @@ -139,6 +140,7 @@ library
, loch-th >=0.2.2 && <0.3
, mtl >=2.2.2 && <2.4
, parallel >=3.2.2.0 && <3.3
, prettyprinter >=1.5.0 && <1.8
, sbv >=8.11 && <10.3
, template-haskell >=2.16 && <2.21
, text >=1.2.4.1 && <2.1
Expand Down Expand Up @@ -176,6 +178,7 @@ test-suite doctest
, loch-th >=0.2.2 && <0.3
, mtl >=2.2.2 && <2.4
, parallel >=3.2.2.0 && <3.3
, prettyprinter >=1.5.0 && <1.8
, sbv >=8.11 && <10.3
, template-haskell >=2.16 && <2.21
, text >=1.2.4.1 && <2.1
Expand All @@ -199,6 +202,7 @@ test-suite spec
Grisette.Backend.SBV.Data.SMT.TermRewritingTests
Grisette.Core.Control.Monad.UnionMTests
Grisette.Core.Data.BVTests
Grisette.Core.Data.Class.GPrettyTests
Grisette.IR.SymPrim.Data.Prim.BitsTests
Grisette.IR.SymPrim.Data.Prim.BoolTests
Grisette.IR.SymPrim.Data.Prim.BVTests
Expand Down Expand Up @@ -226,6 +230,7 @@ test-suite spec
, loch-th >=0.2.2 && <0.3
, mtl >=2.2.2 && <2.4
, parallel >=3.2.2.0 && <3.3
, prettyprinter >=1.5.0 && <1.8
, sbv >=8.11 && <10.3
, tasty >=1.1.0.3 && <1.5
, tasty-hunit ==0.10.*
Expand Down
11 changes: 6 additions & 5 deletions hie.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
cradle:
stack:
components:
- path: "src"
- path: "./src"
component: "grisette:lib"
- path: "test"
component: "grisette:test:spec"
- path: "doctest"

- path: "./doctest"
component: "grisette:test:doctest"

- path: "./test"
component: "grisette:test:spec"
1 change: 1 addition & 0 deletions package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ dependencies:
- parallel >= 3.2.2.0 && < 3.3
- text >= 1.2.4.1 && < 2.1
- QuickCheck >= 2.13.2 && < 2.15
- prettyprinter >= 1.5.0 && < 1.8

flags: {
fast: {
Expand Down
4 changes: 4 additions & 0 deletions src/Grisette/Core.hs
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,9 @@ module Grisette.Core
ToCon (..),
ToSym (..),

-- * Pretty printing
GPretty (..),

-- * Symbolic Generation

-- | It is usually useful to generate complex symbolic values. For example,
Expand Down Expand Up @@ -1020,6 +1023,7 @@ import Grisette.Core.Data.Class.Error
import Grisette.Core.Data.Class.Evaluate
import Grisette.Core.Data.Class.ExtractSymbolics
import Grisette.Core.Data.Class.Function
import Grisette.Core.Data.Class.GPretty
import Grisette.Core.Data.Class.GenSym
import Grisette.Core.Data.Class.Mergeable
import Grisette.Core.Data.Class.ModelOps
Expand Down
13 changes: 13 additions & 0 deletions src/Grisette/Core/Control/Monad/UnionM.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
{-# LANGUAGE GADTs #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TemplateHaskellQuotes #-}
{-# LANGUAGE Trustworthy #-}
Expand Down Expand Up @@ -55,6 +56,7 @@ import Grisette.Core.Data.Class.Bool
import Grisette.Core.Data.Class.Evaluate
import Grisette.Core.Data.Class.ExtractSymbolics
import Grisette.Core.Data.Class.Function
import Grisette.Core.Data.Class.GPretty
import Grisette.Core.Data.Class.GenSym
import Grisette.Core.Data.Class.Mergeable
import Grisette.Core.Data.Class.SOrd
Expand All @@ -71,6 +73,12 @@ import Grisette.IR.SymPrim.Data.TabularFun
import Language.Haskell.TH.Syntax
import Language.Haskell.TH.Syntax.Compat (unTypeSplice)

#if MIN_VERSION_prettyprinter(1,7,0)
import Prettyprinter
#else
import Data.Text.Prettyprint.Doc
#endif

-- $setup
-- >>> import Grisette.Core
-- >>> import Grisette.IR.SymPrim
Expand Down Expand Up @@ -239,6 +247,11 @@ instance Show1 UnionM where
. liftShowsPrecUnion sp sl 0
$ a

instance (GPretty a) => GPretty (UnionM a) where
gpretty = \case
(UAny a) -> groupedEnclose "<" ">" $ gpretty a
(UMrg _ a) -> groupedEnclose "{" "}" $ gpretty a

Check warning on line 253 in src/Grisette/Core/Control/Monad/UnionM.hs

View check run for this annotation

Codecov / codecov/patch

src/Grisette/Core/Control/Monad/UnionM.hs#L250-L253

Added lines #L250 - L253 were not covered by tests

-- | Extract the underlying Union. May be unmerged.
underlyingUnion :: UnionM a -> Union a
underlyingUnion (UAny a) = a
Expand Down
Loading

0 comments on commit 0dab0e7

Please sign in to comment.