summaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
authorJonathan Dowland <jon@dow.land>2022-10-15 20:47:34 +0100
committerMarge Bot <ben+marge-bot@smart-cactus.org>2022-11-22 16:00:14 -0500
commite817c8713df6055ef56a5c0271a0accd94f9c967 (patch)
treec8836d9e91ad2ae1c9b06044d624935649d232ac /utils
parent9d61c182739c415f4283cca3c692e25c82b274f1 (diff)
downloadhaskell-e817c8713df6055ef56a5c0271a0accd94f9c967.tar.gz
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. Fixes #3549.
Diffstat (limited to 'utils')
-rw-r--r--utils/unlit/unlit.c4
1 files changed, 2 insertions, 2 deletions
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)