pp icon indicating copy to clipboard operation
pp copied to clipboard

`!flushlit` fails when path doesn't exist

Open ngirard opened this issue 5 years ago • 2 comments

I'm experimenting with Pp's literate programming capabilities, and took parts of test/pp-test.md into the following test.md file:

Literate programming
====================

Lets write and test a useful library:

!lit{stack-work/mylib.h}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// This is a C library
@functionDeclarations
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

!lit{stack-work/mylib.c}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// This is a C library
@functionImplementations
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The `fib` function computes Fibonacci's numbers:

!lit{@functionDeclarations}{C}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
int fib(int n);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

!lit{@functionImplementations}{C}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
int fib(int n)
{
    return (n < 2) ? 1 : fib(n-1) + fib(n-2);
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The `fact` function computes factorial numbers:

!lit{@functionDeclarations}{int fact(int n);}
!lit{@functionImplementations}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
int fact(int n)
{
    return (n <= 1) ? 1 : n * fact(n-1);
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

!flushlit

Running

pp test.md

outputs

pp: stack-work/mylib.c: openBinaryFile: does not exist (No such file or directory)

Is there something I'm doing wrong ?

Incidentally, the error message would be much more useful with an additional line number.

ngirard avatar Aug 28 '19 10:08 ngirard

The problem comes from the fact, that pp doesn't create the stack-work directory if it doesn't exist.

This is not the default behavior of the other LP systems I've tried (e.g. Org-mode).

I'd suggest changing the default behavior.

ngirard avatar Aug 28 '19 19:08 ngirard

In fact this is intentional. I prefer crashing when a directory is not found instead of saying nothing when a file is created in the wrong misspelled directory. It's always possible to create a directory explicitly: !sh(mkdir -p some_directory). The tests documents are meant to be rendered by make which is supposed to (indirectly) create the stack-work directory.

CDSoft avatar Oct 06 '19 08:10 CDSoft