kosmikus / lhs2tex

Preprocessor for typesetting Haskell sources with LaTeX
Other
99 stars 28 forks source link

Support in --pre mode for comment,spec,evaluate,perform,eval, etc. #95

Closed sgraf812 closed 10 months ago

sgraf812 commented 11 months ago

I noticed that lhs2TeX --pre would crash as soon as there was an intervening \begin{comment} or \begin{spec}, or ... block.

I also removed travis.yml.patch (realised that .travis.yml is very much alive and kicking?) and added dist-newstyle to the .gitignore, and bumped the cabal-version to 2.0 autogen-modules are used.

Is there a recommended way to add a regression test? If so, I couldn't find one...


To be precise about what the bug is:

$ cat tmp.lhs
%include polycode.fmt
\begin{spec}
s = "should not crash"
\end{spec}
\eval{"should not crash either"}
\perform{"should not crash either"}
$ lhs2TeX --pre tmp.lhs
... <polycode.fmt stuff> ...
lhs2TeX: The `impossible' happened in "display.select"
CallStack (from HasCallStack):
  error, called at src/Auxiliaries.lhs:112:36 in main:Auxiliaries

If you put the eval or perform first, you'll instead get

lhs2TeX: fd:6: hGetLine: end of file

which sounds a bit like https://github.com/kosmikus/lhs2tex/issues/87, where the error message is triggered by

$ Starting external process: ghci -XRankNTypes -fprint-explicit-foralls -v0 -ignore-dot-ghci ./dist/build/lhs2TeX/doc/InteractiveGhci.lhs
lhs2TeX: fd:7: hGetLine: end of file

My patch seems to fix matters for the reproducer above; not sure about #87.

sgraf812 commented 11 months ago

It seems that my PR arose out of a misconception about --pre mode; apparently, Pre is not an actual code style but hands off to NewCode, but only if the number arguments matches. E.g., literate preprocessors are called like -h file.lhs file.lhs outfile and this scenario is detected in the options parser.

So when I tried to reproduce an issue with the literate preprocessor, calling lhs2TeX --pre file.lhs -o outfile actually is a bogus invokation and exercises a completely different code path.

Rather than going through that code path and ultimately crashing in display.select and inline.select, I'd rather have it crash early when [Pre,Help] | length n >= 3 did not match.

sgraf812 commented 10 months ago

Closing in favor of #97.