Skip to content

Commit

Permalink
improve formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
janmasrovira committed Dec 13, 2023
1 parent 5838988 commit d64d489
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
9 changes: 4 additions & 5 deletions src/Juvix/Compiler/Nockma/Pretty/Base.hs
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,13 @@ instance PrettyCode Natural where
instance (PrettyCode a) => PrettyCode (Cell a) where
ppCode c = do
m <- asks (^. optPrettyMode)
case m of
inside <- case m of
AllDelimiters -> do
l' <- ppCode (c ^. cellLeft)
r' <- ppCode (c ^. cellRight)
return (brackets (oneLineOrNextNoSpace (l' <+> r')))
MinimizeDelimiters -> do
l <- mapM ppCode (unfoldCell c)
return (brackets (oneLineOrNextNoSpace (sep l)))
return (l' <+> r')
MinimizeDelimiters -> sep <$> mapM ppCode (unfoldCell c)
return (oneLineOrNextBrackets inside)

unfoldCell :: Cell a -> NonEmpty (Term a)
unfoldCell c = c ^. cellLeft :| go [] (c ^. cellRight)
Expand Down
9 changes: 6 additions & 3 deletions src/Juvix/Prelude/Pretty.hs
Original file line number Diff line number Diff line change
Expand Up @@ -183,17 +183,20 @@ spaceOrEmpty = flatAlt (pretty ' ') mempty
oneLineOrNext :: Doc a -> Doc a
oneLineOrNext x = PP.group (flatAlt (line <> indent' x) (space <> x))

oneLineOrNextNoSpace :: Doc a -> Doc a
oneLineOrNextNoSpace x = PP.group (flatAlt (line <> indent' x) x)
oneLineOrNextBrackets :: Doc a -> Doc a
oneLineOrNextBrackets = oneLineOrNextDelims lbracket rbracket

oneLineOrNextNoIndent :: Doc a -> Doc a
oneLineOrNextNoIndent x = PP.group (flatAlt (line <> x) (space <> x))

oneLineOrNextBlock :: Doc a -> Doc a
oneLineOrNextBlock x = PP.group (flatAlt (line <> indent' x <> line) (space <> x <> space))

oneLineOrNextDelims :: Doc a -> Doc a -> Doc a -> Doc a
oneLineOrNextDelims l r x = PP.group (flatAlt (l <> line <> indent' x <> line <> r) (l <> x <> r))

oneLineOrNextBraces :: Doc a -> Doc a
oneLineOrNextBraces x = PP.group (flatAlt (lbrace <> line <> indent' x <> line <> rbrace) (lbrace <> x <> rbrace))
oneLineOrNextBraces = oneLineOrNextDelims lbrace rbrace

nextLine :: Doc a -> Doc a
nextLine x = PP.group (line <> x)
Expand Down

0 comments on commit d64d489

Please sign in to comment.