Skip to content

utils/unlit: adjust parser to match Report spec

The Haskell 2010 Report says that, for Latex-style Literate format, "Program code begins on the first line following a line that begins \begin{code}". (This is unchanged from the 98 Report)

However the unlit.c implementation only matches a line that contains \begin{code} and nothing else. One consequence of this is that one cannot suffix Latex options to the code environment. I.e., this does not work:

\begin{code}[label=foo,caption=Foo Code]

Adjust the matcher to conform to the specification from the Report.

The Haskell Wiki currently recommends suffixing a '%' to \begin{code} in order to deliberately hide a code block from Haskell. This is bad advice, as it's relying on an implementation quirk rather than specified behaviour. None-the-less, some people have tried to use it, c.f. https://mail.haskell.org/pipermail/haskell-cafe/2009-September/066780.html

An alternative solution is to define a separate, equivalent Latex environment to "code", that is functionally identical in Latex but ignored by unlit. This should not be a burden: users are required to manually define the code environment anyway, as it is not provided by the Latex verbatim or lstlistings packages usually used for presenting code in documents.

WIth respect to the commit checklist, I have

  • not added comments inline to unlit.c for this change as it did not seem appropriate
  • provided a test. There is no test coverage for unlit yet at all. So far as I can tell the test harness is not appropriate for testing an ancillary tool written in C. Please guide me if I'm mistaken.

Closes #3549 (closed)

Merge request reports