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

Clean.PrettyPrint: Resolve #1

parent 6afbfaa9
......@@ -50,7 +50,7 @@ where
= print st (id` :+: join_start st " " args :+: if show_eq eq "" :+: rhs)
where
id` = if isinfix ("(" :+: id :+: ")") (id :+: PrintNil)
show_eq = case rhs.rhs_alts of (GuardedAlts _ _) = False; _ = True
show_eq = not (compound_rhs rhs.rhs_alts)
eq = case fk of FK_Macro = " :== "; _ = " = "
print st (PD_Type {td_ident,td_args,td_attribute,td_rhs})
= print st (":: " :+: td_attribute :+: td_ident :+: join_start st " " td_args :+: equals :+: td_rhs)
......
......@@ -2,6 +2,8 @@ definition module CleanPrettyPrint.Expression
from CleanPrettyPrint.Util import class print
from syntax import :: ParsedExpr, :: Rhs
from syntax import :: ParsedExpr, :: Rhs, :: OptGuardedAlts
instance print ParsedExpr, Rhs
compound_rhs :: OptGuardedAlts -> Bool // True iff no guards or #-lets
......@@ -168,14 +168,23 @@ where
instance print ExprWithLocalDefs
where
print st {ewl_expr,ewl_locals=LocalParsedDefs []}
print st {ewl_expr,ewl_nodes=[],ewl_locals=LocalParsedDefs []}
= print st ewl_expr
print st {ewl_expr,ewl_nodes,ewl_locals=LocalParsedDefs []}
= print st (join_start st` ("\n" :+: st`) ewl_nodes :+: "\n" :+: st` :+: "= " :+: ewl_expr)
where
st` = {st & cpp_indent = st.cpp_indent + 1}
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}
instance print NodeDefWithLocals
where
print st {ndwl_strict,ndwl_def={bind_src,bind_dst},ndwl_locals}
= print st (if ndwl_strict "#! " "# " :+: bind_dst :+: " = " :+: bind_src)
// Guards
instance print OptGuardedAlts
where
......@@ -191,4 +200,9 @@ where
print st {alt_guard,alt_expr}
= print {st & cpp_indent = st.cpp_indent + 1} alt_guard +++ eq +++ print st alt_expr
where
eq = case alt_expr of (GuardedAlts _ _) = ""; _ = " = "
eq = if (compound_rhs alt_expr) "" " = "
compound_rhs :: OptGuardedAlts -> Bool
compound_rhs (GuardedAlts _ _) = True
compound_rhs (UnGuardedExpr {ewl_nodes=[_:_]}) = True
compound_rhs _ = 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