问题描述
我有以下编程语言语法:
data Expr = ...
data Stmt = SExpr Expr | SBlock Block | SLet Fundef | ...
data Block = Block [Stmt]
data Fundef = Fundef String [String] Block
data TopDef = TopFun Fundef
使用以下示例语法:
function long_function_name () = {
let g() = {
{
h()
};
3
}
}
我正在尝试使用HughesPJ pretty
库为该语言创建漂亮的打印机。到目前为止,我的尝试如下:
instance Pretty Stmt where
pPrint = \case
SExpr e -> pPrint e
SBlock b -> pPrint b
SLet f -> text "let" <+> pPrint f
instance Pretty Block where
pPrint (Block stmts) = lbrace $+$
nest 2 (vcat (punctuate semi (map pPrint stmts))) $+$
rbrace
instance Pretty Fundef where
pPrint (Fundef name args body) = pPrint name <> parens (...) <+> text "=" <+> pPrint body
instance Prettty TopDef where
pPrint (TopFun f) = text "function" <+> pPrint f
问题是,我想在函数声明的同一行中包含{
,但它总是使后面几行相对于括号列缩进,而不是绝对的。应该在上面的示例的漂亮字体中可见;
function long_function_name () = {
let g() = {
{
h()
};
3
}
}
为什么会发生这种情况,我该如何解决这个问题?我想尽可能避免重复代码。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)