Skip to content

Commit

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

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

instance PrettyCode Name where
ppCode = return . prettyName False
Expand Down Expand Up @@ -195,15 +195,15 @@ instance PrettyCode Statement where

instance PrettyCode Definition where
ppCode Definition {..} = do
comment <- ppComment _definitionComment
comment <- ppJudocComment _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 <- ppComment _functionComment
comment <- ppJudocComment _functionComment
n <- ppCode _functionName
ty <- ppCodeQuoted _functionType
cls <- mapM ppCode _functionClauses
Expand All @@ -218,37 +218,37 @@ instance PrettyCode Clause where

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

instance PrettyCode Datatype where
ppCode Datatype {..} = do
comment <- ppComment _datatypeComment
comment <- ppJudocComment _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 <- ppComment _constructorComment
comment <- ppJudocComment _constructorComment
n <- ppCode _constructorName
tys <- mapM ppCodeQuoted _constructorArgTypes
return $ comment <> hsep (n : tys)

instance PrettyCode Record where
ppCode Record {..} = do
comment <- ppComment _recordComment
comment <- ppJudocComment _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 <- ppComment _recordFieldComment
comment <- ppJudocComment _recordFieldComment
n <- ppCode _recordFieldName
ty <- ppCodeQuoted _recordFieldType
return $ comment <> n <+> "::" <+> ty
Expand Down
2 changes: 1 addition & 1 deletion src/Juvix/Compiler/Concrete/Pretty.hs
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ ppTrace :: (PrettyPrint c) => c -> Text
ppTrace = toAnsiText True . ppOut traceOptions

ppPrintJudoc :: (SingI s) => Judoc s -> Text
ppPrintJudoc = toAnsiText True . Print.ppOutJudoc
ppPrintJudoc = toAnsiText False . Print.ppOutJudoc
9 changes: 9 additions & 0 deletions tests/positive/Isabelle/isabelle/Program.thy
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ fun bool_fun :: "bool \<Rightarrow> bool \<Rightarrow> bool \<Rightarrow> bool"
fun bool_fun' :: "bool \<Rightarrow> bool \<Rightarrow> bool \<Rightarrow> bool" where
"bool_fun' x y z = (x \<and> y \<or> z)"

text \<open>
A type of Queues
\<close>
datatype 'A Queue
= queue "'A list" "'A list"

Expand All @@ -74,6 +77,9 @@ fun push_back :: "'A Queue \<Rightarrow> 'A \<Rightarrow> 'A Queue" where
[] \<Rightarrow> queue [x] (qsnd q) |
q' \<Rightarrow> queue q' (x # qsnd q))"

text \<open>
Checks if the queue is empty
\<close>
fun is_empty :: "'A Queue \<Rightarrow> bool" where
"is_empty q =
(case qfst q of
Expand All @@ -95,6 +101,9 @@ fun funkcja :: "nat \<Rightarrow> nat" where
n' \<Rightarrow> n' + 1
in plusOne n + nat1 + nat2)"

text \<open>
An Either' type
\<close>
datatype ('A, 'B) Either'
= Left' 'A |
Right' 'B
Expand Down

0 comments on commit 63a2abb

Please sign in to comment.