Skip to content
This repository was archived by the owner on Apr 1, 2025. It is now read-only.

Commit 76f79fd

Browse files
committed
Specialize pretty-printing to User.
1 parent da85c69 commit 76f79fd

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

semantic-core/src/Data/Core/Pretty.hs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,16 @@ import qualified Data.Text.Prettyprint.Doc as Pretty
2020
import qualified Data.Text.Prettyprint.Doc.Render.String as Pretty
2121
import qualified Data.Text.Prettyprint.Doc.Render.Terminal as Pretty
2222

23-
showCore :: Term Core Name -> String
23+
showCore :: Term Core User -> String
2424
showCore = Pretty.renderString . Pretty.layoutSmart Pretty.defaultLayoutOptions . Pretty.unAnnotate . prettyCore Ascii
2525

26-
printCore :: Term Core Name -> IO ()
26+
printCore :: Term Core User -> IO ()
2727
printCore p = Pretty.putDoc (prettyCore Unicode p) *> putStrLn ""
2828

29-
showFile :: File (Term Core Name) -> String
29+
showFile :: File (Term Core User) -> String
3030
showFile = showCore . fileBody
3131

32-
printFile :: File (Term Core Name) -> IO ()
32+
printFile :: File (Term Core User) -> IO ()
3333
printFile = printCore . fileBody
3434

3535
type AnsiDoc = Pretty.Doc Pretty.AnsiStyle
@@ -44,10 +44,8 @@ type Prec = Int
4444

4545
data Style = Unicode | Ascii
4646

47-
name :: Name -> AnsiDoc
48-
name = \case
49-
Gen p -> pretty p
50-
User n -> encloseIf (needsQuotation n) (symbol "#{") (symbol "}") (pretty n)
47+
name :: User -> AnsiDoc
48+
name n = encloseIf (needsQuotation n) (symbol "#{") (symbol "}") (pretty n)
5149

5250
with :: (Member (Reader Prec) sig, Carrier sig m) => Prec -> m a -> m a
5351
with n = local (const n)
@@ -63,7 +61,7 @@ prettify :: (Member (Reader [AnsiDoc]) sig, Member (Reader Prec) sig, Carrier si
6361
-> Core (Const (m AnsiDoc)) a
6462
-> m AnsiDoc
6563
prettify style = \case
66-
Let a -> pure $ keyword "let" <+> name (User a)
64+
Let a -> pure $ keyword "let" <+> name a
6765
Const a :>> Const b -> do
6866
prec <- ask @Prec
6967
fore <- with 12 a
@@ -108,7 +106,7 @@ prettify style = \case
108106

109107
-- Annotations are not pretty-printed, as it lowers the signal/noise ratio too profoundly.
110108
Ann _ (Const c) -> c
111-
where bind (Ignored x) f = let x' = name (User x) in (,) x' <$> local (x':) (getConst (unScope f))
109+
where bind (Ignored x) f = let x' = name x in (,) x' <$> local (x':) (getConst (unScope f))
112110
lambda = case style of
113111
Unicode -> symbol "λ"
114112
Ascii -> symbol "\\"
@@ -120,7 +118,7 @@ prettify style = \case
120118
appending :: Functor f => AnsiDoc -> f AnsiDoc -> f AnsiDoc
121119
appending k item = (keyword k <+>) <$> item
122120

123-
prettyCore :: Style -> Term Core Name -> AnsiDoc
121+
prettyCore :: Style -> Term Core User -> AnsiDoc
124122
prettyCore s = run . runReader @Prec 0 . runReader @[AnsiDoc] [] . cata id (prettify s) bound (pure . name)
125123
where bound (Z _) = asks (head @AnsiDoc)
126124
bound (S n) = local (tail @AnsiDoc) n

0 commit comments

Comments
 (0)