Commit ddcffe17 authored by Camil Staps's avatar Camil Staps 🐧

Clean.PrettyPrint: Fix printing for instances

parent 22a47d26
definition module CleanPrettyPrint
from syntax import :: ParsedDefinition, :: ParsedExpr, :: Rhs, :: Type, :: TypeContext
from syntax import
:: AType,
:: ParsedDefinition,
:: ParsedExpr,
:: Rhs,
:: Type,
:: TypeContext
class cpp t :: t -> String
instance cpp
AType,
ParsedDefinition,
ParsedExpr,
Rhs,
......
......@@ -9,6 +9,7 @@ import CleanPrettyPrint.Common
import CleanPrettyPrint.Expression
import CleanPrettyPrint.Definition
instance cpp AType where cpp x = print zero x
instance cpp ParsedDefinition where cpp x = print zero x
instance cpp ParsedExpr where cpp x = print zero x
instance cpp Rhs where cpp x = print zero x
......
......@@ -18,14 +18,10 @@ where
st` = { st & cpp_indent = st.cpp_indent + 1 }
context = if (isEmpty cd.class_context) "" (" | " +++ join st " & " cd.class_context)
args = if (isEmpty cd.class_args) "" (join_start st " " cd.class_args)
print st (PD_Instance {pim_pi={pi_ident,pi_types,pi_context},pim_members})
= print st ("instance " :+: pi_ident :+: " " :+: join st ", " pi_types :+: pi_context` :+: members)
where
pi_context` = if (isEmpty pi_context) PrintNil (" | " :+: join st " & " pi_context)
members = if (isEmpty pim_members) PrintNil (" where" :+: join_start st` ("\n" :+: st`) pim_members)
st` = {st & cpp_indent = st.cpp_indent + 1}
print st (PD_Instance pim)
= print st pim
print st (PD_Instances pis=:[{pim_pi={pi_ident}}:_])
= print st ("instance " :+: pi_ident :+: " " :+: join st ", " (map (\i -> i.pim_pi.pi_types) pis))
= join st ("\n" :+: st) pis
print st (PD_Generic {gen_ident,gen_type,gen_vars})
= print st ("generic " :+: gen_ident :+: join_start st " " gen_vars :+: " :: " :+: gen_type)
print st (PD_Derive gencasedefs)
......@@ -203,6 +199,18 @@ where
print st _
= abort "UNKNOWN_TCCLASS"
instance print ParsedInstanceAndMembers
where
print st {pim_pi={pi_pos,pi_ident,pi_types,pi_context},pim_members}
= print st (pos :+: ": " :+: "instance " :+: pi_ident :+: " " :+: join st " " pi_types :+: pi_context` :+: members)
where
pi_context` = if (isEmpty pi_context) PrintNil (" | " :+: join st " & " pi_context)
members = if (isEmpty pim_members) PrintNil (" where" :+: join_start st` ("\n" :+: st`) pim_members)
st` = {st & cpp_indent = st.cpp_indent + 1}
pos = case pi_pos of
(FunPos f l n) = "<" :+: f :+: ";" :+: l :+: ";" :+: n :+: ">"
(LinePos f l) = "<" :+: f :+: ";" :+: l :+: ">"
// Generics
instance print GenericCaseDef
where
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment