1
1
mirror of https://github.com/anoma/juvix.git synced 2024-12-11 08:25:46 +03:00

Add softlines between applications and hang definitions (#1578)

add softlines between applications and hang definitions
This commit is contained in:
janmasrovira 2022-10-06 02:56:33 +02:00 committed by GitHub
parent f4ca940c7a
commit fc75660774
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 10 deletions

View File

@ -117,7 +117,7 @@ instance SingI s => PrettyCode [Statement s] where
ppCode ss = vsep2 <$> mapM (fmap vsep . mapM (fmap endSemicolon . ppCode)) (groupStatements ss) ppCode ss = vsep2 <$> mapM (fmap vsep . mapM (fmap endSemicolon . ppCode)) (groupStatements ss)
instance SingI s => PrettyCode (Statement s) where instance SingI s => PrettyCode (Statement s) where
ppCode s = case s of ppCode = \case
StatementOperator op -> ppCode op StatementOperator op -> ppCode op
StatementTypeSignature sig -> ppCode sig StatementTypeSignature sig -> ppCode sig
StatementImport i -> ppCode i StatementImport i -> ppCode i
@ -248,7 +248,7 @@ instance SingI s => PrettyCode (InductiveConstructorDef s) where
constructorName' <- annDef _constructorName <$> ppSymbol _constructorName constructorName' <- annDef _constructorName <$> ppSymbol _constructorName
constructorType' <- ppExpression _constructorType constructorType' <- ppExpression _constructorType
doc' <- mapM ppCode _constructorDoc doc' <- mapM ppCode _constructorDoc
return $ doc' ?<> constructorName' <+> kwColon <+> constructorType' return $ doc' ?<> hang' (constructorName' <+> kwColon <+> constructorType')
instance PrettyCode BuiltinInductive where instance PrettyCode BuiltinInductive where
ppCode i = return (kwBuiltin <+> keyword (prettyText i)) ppCode i = return (kwBuiltin <+> keyword (prettyText i))
@ -422,7 +422,7 @@ instance SingI s => PrettyCode (TypeSignature s) where
sigType' <- ppExpression _sigType sigType' <- ppExpression _sigType
builtin' <- traverse ppCode _sigBuiltin builtin' <- traverse ppCode _sigBuiltin
doc' <- mapM ppCode _sigDoc doc' <- mapM ppCode _sigDoc
return $ doc' ?<> builtin' <?+> sigTerminating' <> sigName' <+> kwColon <+> sigType' return $ doc' ?<> builtin' <?+> sigTerminating' <> hang' (sigName' <+> kwColon <+> sigType')
instance SingI s => PrettyCode (Function s) where instance SingI s => PrettyCode (Function s) where
ppCode :: forall r. Members '[Reader Options] r => Function s -> Sem r (Doc Ann) ppCode :: forall r. Members '[Reader Options] r => Function s -> Sem r (Doc Ann)
@ -492,11 +492,12 @@ instance SingI s => PrettyCode (FunctionClause s) where
clauseBody' <- ppExpression _clauseBody clauseBody' <- ppExpression _clauseBody
clauseWhere' <- mapM ppCode _clauseWhere clauseWhere' <- mapM ppCode _clauseWhere
return $ return $
clauseOwnerFunction' hang' $
<+?> clausePatterns' clauseOwnerFunction'
<+> kwAssignment <+?> clausePatterns'
<+> clauseBody' <+> kwAssignment
<+?> ((line <>) <$> clauseWhere') <+> clauseBody'
<+?> ((line <>) <$> clauseWhere')
instance SingI s => PrettyCode (WhereBlock s) where instance SingI s => PrettyCode (WhereBlock s) where
ppCode WhereBlock {..} = indent' . (kwWhere <+>) <$> ppBlock whereClauses ppCode WhereBlock {..} = indent' . (kwWhere <+>) <$> ppBlock whereClauses
@ -513,7 +514,7 @@ instance SingI s => PrettyCode (AxiomDef s) where
axiomDoc' <- mapM ppCode _axiomDoc axiomDoc' <- mapM ppCode _axiomDoc
axiomType' <- ppExpression _axiomType axiomType' <- ppExpression _axiomType
builtin' <- traverse ppCode _axiomBuiltin builtin' <- traverse ppCode _axiomBuiltin
return $ axiomDoc' ?<> builtin' <?+> kwAxiom <+> axiomName' <+> kwColon <+> axiomType' return $ axiomDoc' ?<> builtin' <?+> hang' (kwAxiom <+> axiomName' <+> kwColon <+> axiomType')
instance SingI s => PrettyCode (Import s) where instance SingI s => PrettyCode (Import s) where
ppCode :: forall r. Members '[Reader Options] r => Import s -> Sem r (Doc Ann) ppCode :: forall r. Members '[Reader Options] r => Import s -> Sem r (Doc Ann)
@ -600,7 +601,7 @@ instance PrettyCode Application where
ppCode (Application l r) = do ppCode (Application l r) = do
l' <- ppLeftExpression appFixity l l' <- ppLeftExpression appFixity l
r' <- ppRightExpression appFixity r r' <- ppRightExpression appFixity r
return $ l' <+> r' return $ l' <> softline <> r'
instance PrettyCode Literal where instance PrettyCode Literal where
ppCode = \case ppCode = \case

View File

@ -94,6 +94,9 @@ hsepMaybe l
indent' :: Doc ann -> Doc ann indent' :: Doc ann -> Doc ann
indent' = indent 2 indent' = indent 2
hang' :: Doc ann -> Doc ann
hang' = hang 2
ordinal :: Int -> Doc a ordinal :: Int -> Doc a
ordinal = \case ordinal = \case
1 -> "first" 1 -> "first"