I have a small question relating to literate haskell programs that use the \begin{code} \end{code} style. Am I correct to assume that \end{code} inside a string should be recognized as being inside a string. The report seems to say this, but the unlit that is distributed with ghc doesn't grok this. Has anyone written an Unlit module in Haskell? Immanuel *************************************************************************** It makes me uncomfortable to see An English spinster of the middle class Describe the amorous effects of `brass', Reveal so frankly and with such sobriety The economic basis of society. W.H. Auden -- Immanuel Litzroth Software Development Engineer Enfocus Software Kleindokkaai 3-5 B-9000 Gent Belgium Voice: +32 9 269 23 90 Fax : +32 9 269 16 91 Email: Immanuell@enfocus.be web : www.enfocus.be ***************************************************************************
Immanuel Litzroth <immanuell@enfocus.be> writes:
I have a small question relating to literate haskell programs that use the \begin{code} \end{code} style. Am I correct to assume that \end{code} inside a string should be recognized as being inside a string. The report seems to say this, but the unlit that is distributed with ghc doesn't grok this. Has anyone written an Unlit module in Haskell?
I have attached the Unlit.hs module from the nhc98 compiler, based on the original specification in the the Haskell 1.2 Report. Use the exported function unlit :: String -> String -> String whose first argument is the filename (for error messages), the second argument is the file content, and whose result is the un-literated file. Regards, Malcolm
"Malcolm" == Malcolm Wallace <Malcolm.Wallace@cs.york.ac.uk> writes:
Malcolm> Immanuel Litzroth <immanuell@enfocus.be> writes: >> I have a small question relating to literate haskell programs >> that use the \begin{code} \end{code} style. Am I correct to >> assume that \end{code} inside a string should be recognized as >> being inside a string. The report seems to say this, but the >> unlit that is distributed with ghc doesn't grok this. Has >> anyone written an Unlit module in Haskell? Malcolm> I have attached the Unlit.hs module from the nhc98 Malcolm> compiler, based on the original specification in the the Malcolm> Haskell 1.2 Report. Use the exported function unlit :: Malcolm> String -> String -> String whose first argument is the Malcolm> filename (for error messages), the second argument is the Malcolm> file content, and whose result is the un-literated file. thanks for your code. Perhaps I was not completely clear in my question: I specifically want to know if unliterating should include lexing so that it recognizes strings (comments) or if it can be a separate phase. The following compiles without problems in ghc. \begin{code} main :: IO () main = putStr " \end{code} " \begin{code} " \end{code} The report says Program code ends just before a subsequent line that begins \end{code} (ignoring string literals, of course). I was writing an unlit module to toy around with the Language.Haskell.* stuff when I started wondering about this. Immanuel -- *************************************************************************** It makes me uncomfortable to see An English spinster of the middle class Describe the amorous effects of `brass', Reveal so frankly and with such sobriety The economic basis of society. W.H. Auden -- Immanuel Litzroth Software Development Engineer Enfocus Software Kleindokkaai 3-5 B-9000 Gent Belgium Voice: +32 9 269 23 90 Fax : +32 9 269 16 91 Email: Immanuell@enfocus.be web : www.enfocus.be ***************************************************************************
Immanuel Litzroth <immanuell@enfocus.be> writes:
thanks for your code. Perhaps I was not completely clear in my question: I specifically want to know if unliterating should include lexing so that it recognizes strings (comments) or if it can be a separate phase. The following compiles without problems in ghc.
\begin{code} main :: IO () main = putStr " \end{code} " \begin{code} " \end{code}
Ghc should not accept this code, because, no matter how the unliterating is achieved, it is illegal for a literal string to contain a literal newline character. (You must use '\n' for the character, and/or string-gaps if your intention is to make the layout more readable.)
The report says Program code ends just before a subsequent line that begins \end{code} (ignoring string literals, of course).
Certainly if the unliteration spec in the Haskell 1.2 Report is still valid (?) I believe the intention is that all unliteration is done in a line-by-line manner before any interpretation of the "code" text. Therefore, the unliteration engine does not need to lex the program code at all. Regards, Malcolm
participants (2)
-
Immanuel Litzroth -
Malcolm Wallace