.cabal 中的 {} 用于 Haskell 中的 Haddock 文档

发布于 2024-09-16 14:24:33 字数 365 浏览 9 评论 0原文

收到该行

> { -# OPTIONS_GHC -fglasgow-exts -XTemplateHaskell #- }

如果我在 .cabal 文件的文档部分(描述)中

haddock: parsing haddock prologue failed

,则在运行时

$ cabal haddock

我会收到错误消息,但如果我去掉 {}一切正常。是否有某种方法可以转义 {} 以便可以在说明中使用它们?

If I got the line

> { -# OPTIONS_GHC -fglasgow-exts -XTemplateHaskell #- }

in the documentation-part (description) of the .cabal-file I'll get the error message

haddock: parsing haddock prologue failed

when running

$ cabal haddock

but if I get rid of the { and } everything works fine. Is there some way to escape {} so they can be used in the description?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

-柠檬树下少年和吉他 2024-09-23 14:24:33

Haddock 有两种代码块语法——用 @ 分隔块的语法允许您使用 HTML 转义符,它可用于嵌入 Cabal 解析器无法处理的字符。

不幸的是,Cabal 似乎从 @ 分隔的块中去除了前导空格,因此您还必须在任何带有空格的行前面加上 HTML 编码的空格

这是一个示例:

description:
  My package with a code example!
  .
  @
  {-\# LANGUAGE TemplateHaskell \#-}
  .
  main = do
      $templatePrint "hello!"
      $templatePrint "world!"
  @

它呈现为:

我的包带有代码示例!

{-# LANGUAGE TemplateHaskell #-}

主要=做
    $templatePrint“你好!”
    $templatePrint“你好!”

Haddock has two syntaxes for code blocks -- the syntax that delimits blocks with @ allows you to use HTML escapes, which can be used to embed characters that Cabal's parser can't deal with.

Unfortunately, it seems that Cabal strips the leading whitespace from @-delimited blocks, so you also have to prefix any lines with spaces with an HTML-encoded space .

Here's am example:

description:
  My package with a code example!
  .
  @
  {-\# LANGUAGE TemplateHaskell \#-}
  .
  main = do
      $templatePrint "hello!"
      $templatePrint "world!"
  @

Which renders to:

My package with a code example!

{-# LANGUAGE TemplateHaskell #-}

main = do
    $templatePrint "hello!"
    $templatePrint "hello!"
屋檐 2024-09-23 14:24:33

OPTIONS_GHC 本身并未被弃用(例如,您可以利用它来启用特定的构建选项),但使用它来打开/关闭语言功能并不被认为是好的做法。请改用 {-# LANGUAGE ... #-} 编译指示。

例如 {-# LANGUAGE TemplateHaskell,foreignFunctionInterface, RankNTypes #-}

另外,使用包罗万象的 -fglasgow-exts 被认为是不好的形式。最好只包含您需要的扩展,这样对于任何刚接触您的代码的人来说都更清楚需要哪些扩展。

OPTIONS_GHC itself is not deprecated (you'd utilize this to enable particular build options, for example), but using it to turn on/off language features is not considered good practice . Use {-# LANGUAGE ... #-} pragmas instead.

e.g. {-# LANGUAGE TemplateHaskell, ForeignFunctionInterface, RankNTypes #-}

Also, it's considered bad form to utilize the all-encompassing -fglasgow-exts. Better to just include the extensions you need, and that way it's clearer which are required for anyone new to your code.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文