Closed idontgetoutmuch closed 10 years ago
I'm going to need a bit more info to be able to track this down (I see no reason why C blocks should interact with the ghci
feature at all). Could you provide a test file containing [ghci]
which works as expected, but fails to work when adding a block of C code? Or at the very least, a complete example file which does not give the expected results (with a description of the flags used and expected/actual results).
With following (substitute ~ for tilde)
This is a test.
> foo = 2 + 3
tilde tilde tilde tilde {.c}
#include <stdio.h>
int main(void)
{
printf("Hello, world!\n");
return 0;
}
tilde tilde tilde tilde
What is the value of foo?
[ghci]
foo
I get
<p>What is the value of foo?</p>
<pre><code><span style="color: gray;">ghci> </span>foo</code></pre>
<div class="references">
</div>
If I indent
#include <stdio.h>
by one space I get
<p>What is the value of foo?</p>
<pre><code><span style="color: gray;">ghci> </span>foo
5
</code></pre>
<div class="references">
</div>
so somehow the # on the first line is causing a problem,
Did you want me to create a gist or are you ok to copy and paste the code block above? Let me know which is more convenient for you? Thanks for looking into this.
Thanks, this is perfect. No need to create a gist.
OK, I see what the problem is. To implement the [ghci]
feature, the entire file gets loaded into ghci
. However, GHC's lhs
parser fails when a line begins with #
(I'm not sure why). I will have to think a bit about a good workaround.
Obviously while I'd be very happy with a workaround, shouldn't we also ask the ghc guys why ghci has a problem with # in the first column? I'm happy to do that.
Also I can manually workaround the situation by moving the # into the second column and then editing the html afterwards. Not very satisfactory but I only have to do it when I upload a blog post.
Perhaps we should close this since it really is a ghci issue:
:-) - I may try and work on this at the next Zurihac
No, let's leave it open. Even if it is a ghci problem at root, it still makes sense to implement a workaround in BlogLiterately
. (I doubt ghci will be fixed anytime soon.)
As for a workaround, I think the best option is to create a temporary file which is the same as the input file but with lines beginning with #
stripped, and give that as input to ghci
instead. A bit of a hack, but then again BlogLiterately
's ghci feature is one giant hack already ;-).
Uploaded as BlogLiterately-0.7.1.4
. Can you confirm that this workaround fixes your issue?
Fixed! Thanks very much :-)
I am writing a blog on Haskell Vs C for performance and am including the C files
And I then do e.g.
This works fine apart from syntax highlighting for C but when I try to use [ghci] then I think the fact that the included C file contains # causes whatever calls ghci to fail silently (or perhaps ghci fails and the return is silent)
Any ideas on a workround would be appreciated.