Commit 3b2a69cb authored by Camil Staps's avatar Camil Staps 🐧

Clean.PrettyPrint: rule alternative local definitions (with blocks)

parent c985a0dc
......@@ -153,14 +153,24 @@ where
print st ca = print st (ca.calt_pattern :+: " = " :+: ca.calt_rhs)
// Local definitions
instance join LocalDefs
instance Join LocalDefs
where
join st glue (LocalParsedDefs lds) = join st glue lds
join st glue _ = abort "JOIN: UNKNOWN_LOCALDEFS"
isNil (LocalParsedDefs []) = True
isNil (LocalParsedDefs _) = False
isNil _ = abort "JOIN: UNKNOWN_LOCALDEFS"
instance print ExprWithLocalDefs
where
print st {ewl_expr} = print st ewl_expr
print st {ewl_expr,ewl_locals=LocalParsedDefs []}
= print st ewl_expr
print st {ewl_expr,ewl_locals}
= print st (ewl_expr :+: "\n" :+: st` :+: "with" :+: join_start st`` ("\n" :+: st``) ewl_locals)
where
st` = {st & cpp_indent = st.cpp_indent + 1}
st`` = {st & cpp_indent = st.cpp_indent + 2}
// Guards
instance print OptGuardedAlts
......
......@@ -18,14 +18,15 @@ class print t where
printp :: CPPState t -> String | print t
printp st x :== if st.cpp_parens ("(" +++ print st x +++ ")") (print {st & cpp_parens=True} x)
class join e where
class Join e where
join :: CPPState t e -> String | print t
isNil :: e -> Bool
join_start :: CPPState t e -> String | print t
join_start st glue elems :== if (isEmpty elems) "" (print st glue) +++ join st glue elems
join_start st glue elems :== if (isNil elems) "" (print st glue) +++ join st glue elems
instance zero CPPState
instance print String, Int, [t] | print t, CPPState, PrintList
instance join [u] | print u
instance Join [u] | print u
......@@ -18,8 +18,11 @@ where
print _ PrintNil = ""
print st (a :+: b) = print st a +++ print st b
instance join [u] | print u
instance Join [u] | print u
where
join _ _ [] = ""
join st _ [e] = print st e
join st glue [e:es] = print st e +++ print st glue +++ join st glue es
isNil [] = True
isNil _ = False
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