Skip to content

Commit

Permalink
fix non-top comments
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszcz committed Aug 19, 2024
1 parent d368911 commit d2e1752
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 11 deletions.
23 changes: 14 additions & 9 deletions src/Juvix/Compiler/Backend/Isabelle/Pretty/Base.hs
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,16 @@ ppParams = \case
ps <- mapM ppCode params
return $ Just $ parens (hsep (punctuate comma ps))

ppJudocComment :: Maybe Text -> Sem r (Doc Ann)
ppJudocComment = \case
ppTextComment :: Maybe Text -> Sem r (Doc Ann)
ppTextComment = \case
Nothing -> return ""
Just c -> return $ annotate AnnComment "text \\<open>" <> line <> annotate AnnComment (pretty c) <> line <> annotate AnnComment "\\<close>" <> line

ppComment :: Maybe Text -> Sem r (Doc Ann)
ppComment = \case
Nothing -> return ""
Just c -> return $ annotate AnnComment "(* " <> annotate AnnComment (pretty c) <> annotate AnnComment " *)" <> line

instance PrettyCode Name where
ppCode = return . prettyName False

Expand Down Expand Up @@ -195,15 +200,15 @@ instance PrettyCode Statement where

instance PrettyCode Definition where
ppCode Definition {..} = do
comment <- ppJudocComment _definitionComment
comment <- ppTextComment _definitionComment
n <- ppCode _definitionName
ty <- ppCodeQuoted _definitionType
body <- ppCode _definitionBody
return $ comment <> kwDefinition <+> n <+> "::" <+> ty <+> kwWhere <> line <> indent' (dquotes (n <+> "=" <> oneLineOrNext body))

instance PrettyCode Function where
ppCode Function {..} = do
comment <- ppJudocComment _functionComment
comment <- ppTextComment _functionComment
n <- ppCode _functionName
ty <- ppCodeQuoted _functionType
cls <- mapM ppCode _functionClauses
Expand All @@ -218,37 +223,37 @@ instance PrettyCode Clause where

instance PrettyCode Synonym where
ppCode Synonym {..} = do
comment <- ppJudocComment _synonymComment
comment <- ppTextComment _synonymComment
n <- ppCode _synonymName
ty <- ppCodeQuoted _synonymType
return $ comment <> kwTypeSynonym <+> n <+> "=" <> oneLineOrNext ty

instance PrettyCode Datatype where
ppCode Datatype {..} = do
comment <- ppJudocComment _datatypeComment
comment <- ppTextComment _datatypeComment
n <- ppCode _datatypeName
params <- ppParams _datatypeParams
ctrs <- mapM ppCode _datatypeConstructors
return $ comment <> kwDatatype <+> params <?+> n <> line <> indent' ("=" <+> align (vsep (punctuate (space <> kwPipe) ctrs)))

instance PrettyCode Constructor where
ppCode Constructor {..} = do
comment <- ppJudocComment _constructorComment
comment <- ppComment _constructorComment
n <- ppCode _constructorName
tys <- mapM ppCodeQuoted _constructorArgTypes
return $ comment <> hsep (n : tys)

instance PrettyCode Record where
ppCode Record {..} = do
comment <- ppJudocComment _recordComment
comment <- ppTextComment _recordComment
n <- ppCode _recordName
params <- ppParams _recordParams
fields <- mapM ppCode _recordFields
return $ comment <> kwRecord <+> params <?+> n <+> "=" <> line <> indent' (vsep fields)

instance PrettyCode RecordField where
ppCode RecordField {..} = do
comment <- ppJudocComment _recordFieldComment
comment <- ppComment _recordFieldComment
n <- ppCode _recordFieldName
ty <- ppCodeQuoted _recordFieldType
return $ comment <> n <+> "::" <+> ty
Expand Down
6 changes: 5 additions & 1 deletion tests/positive/Isabelle/Program.juvix
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,11 @@ funkcja (n : Nat) : Nat :=
in plusOne n + nat1 + nat2;

--- An Either' type
type Either' A B := Left' A | Right' B;
type Either' A B :=
--- Left constructor
Left' A
| --- Right constructor
Right' B;

-- Records

Expand Down
4 changes: 3 additions & 1 deletion tests/positive/Isabelle/isabelle/Program.thy
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,9 @@ text \<open>
An Either' type
\<close>
datatype ('A, 'B) Either'
= Left' 'A |
= (* Left constructor *)
Left' 'A |
(* Right constructor *)
Right' 'B

fun bf :: "bool \<Rightarrow> bool \<Rightarrow> bool" where
Expand Down

0 comments on commit d2e1752

Please sign in to comment.