[Git][ghc/ghc][master] utils/unlit: adjust parser to match Report spec

Marge Bot (@marge-bot) gitlab at gitlab.haskell.org
Tue Nov 22 21:00:49 UTC 2022



Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC


Commits:
e817c871 by Jonathan Dowland at 2022-11-22T16:00:14-05:00
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.

- - - - -


1 changed file:

- utils/unlit/unlit.c


Changes:

=====================================
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)



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/e817c8713df6055ef56a5c0271a0accd94f9c967

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/e817c8713df6055ef56a5c0271a0accd94f9c967
You're receiving this email because of your account on gitlab.haskell.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20221122/f0248431/attachment.html>


More information about the ghc-commits mailing list