From e817c8713df6055ef56a5c0271a0accd94f9c967 Mon Sep 17 00:00:00 2001 From: Jonathan Dowland Date: Sat, 15 Oct 2022 20:47:34 +0100 Subject: 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. 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. Fixes #3549. --- utils/unlit/unlit.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'utils') diff --git a/utils/unlit/unlit.c b/utils/unlit/unlit.c index 5a0e535109..2ec2af6058 100644 --- a/utils/unlit/unlit.c +++ b/utils/unlit/unlit.c @@ -224,9 +224,9 @@ static line readline(FILE *istream, FILE *ostream) { while(i > 0 && isspace(buf[i-1])) i--; buf[i] = 0; - if (strcmp(buf, BEGINCODE) == 0) + if (strncmp(buf, BEGINCODE, LENBEGINCODE) == 0) return BEGIN; - if (strcmp(buf, ENDCODE) == 0) + if (strncmp(buf, ENDCODE, LENENDCODE) == 0) return END; #if defined(PSEUDOCODE) else if (strcmp(buf, BEGINPSEUDOCODE) == 0) -- cgit v1.2.1