Verified Commit 2ab3f602 authored by Camil Staps's avatar Camil Staps 🚀

Print the correct =/:==/=: token for ExprWithLocalDefs in Clean.PrettyPrint

parent 32fa9c5b
Pipeline #43808 passed with stage
in 2 minutes and 32 seconds
......@@ -47,11 +47,11 @@ where
print st (PD_Function _ id isinfix args rhs fk)
= print stnp (id` :+: join_start stp " " args :+: if show_eq eq "" :+: rhs)
where
stnp = {st & cpp_parens=False}
stp = {st & cpp_parens=True}
stnp = {st & cpp_funkind=fk, cpp_parens=False}
stp = {st & cpp_funkind=fk, cpp_parens=True}
id` = if isinfix ("(" :+: id :+: ")") (id :+: PrintNil)
show_eq = not (compound_rhs rhs.rhs_alts)
eq = case fk of FK_Macro = " :== "; _ = " = "
eq = print st (" " :+: fk :+: " ")
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)
where
......
definition module Clean.PrettyPrint.Expression
from syntax import :: ParsedExpr, :: Rhs, :: OptGuardedAlts
from syntax import :: ParsedExpr, :: Rhs, :: OptGuardedAlts, :: FunKind
from Clean.PrettyPrint.Util import class print
instance print ParsedExpr, Rhs
instance print ParsedExpr, Rhs, FunKind
/**
* `True` iff the right-hand side is a {{`GuardedAlts`}} or {{`UnguardedExpr`}}
......
......@@ -11,6 +11,14 @@ import Clean.PrettyPrint.Util
import Clean.PrettyPrint.Common
import Clean.PrettyPrint.Definition
instance print FunKind
where
print _ (FK_Function _) = "="
print _ FK_Macro = ":=="
print _ FK_Caf = "=:"
print _ FK_NodeDefOrFunction = "="
print _ FK_Unknown = "="
// General expressions
instance print ParsedExpr
where
......@@ -219,7 +227,7 @@ where
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)
= print st (join_start st` ("\n" :+: st`) ewl_nodes :+: "\n" :+: st` :+: st.cpp_funkind :+: " " :+: ewl_expr)
where
st` = {st & cpp_indent = st.cpp_indent + 1}
print st {ewl_expr,ewl_locals}
......
......@@ -8,10 +8,13 @@ definition module Clean.PrettyPrint.Util
from StdOverloaded import class zero, class +++(+++)
:: CPPState
= { cpp_indent :: !Int
, cpp_parens :: !Bool
}
from syntax import :: FunKind
:: CPPState =
{ cpp_indent :: !Int
, cpp_parens :: !Bool
, cpp_funkind :: !FunKind
}
:: PrintList
= PrintNil
......
......@@ -2,11 +2,15 @@ implementation module Clean.PrettyPrint.Util
import StdEnv
from syntax import :: FunKind(FK_Unknown)
instance zero CPPState
where
zero = { cpp_indent = 0
, cpp_parens = False
}
zero =
{ cpp_indent = 0
, cpp_parens = False
, cpp_funkind = FK_Unknown
}
instance print String where print _ s = s
instance print Int where print _ i = toString i
......
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