[m-users.] Correct use of pragma source_file and #N directives together ?

Sean Charles (emacstheviking) objitsu at gmail.com
Wed Aug 17 17:48:29 AEST 2022


Thanks Zoltan.

That's killed that feature then, I guess I can leave the line numbers in. I didn't fully appreciate that the directives had that restriction on them, I checked section 19 of the reference manual again but couldn't find a hard and fast statement to that effect but ultimately the compiler is the final arbiter.

I will attempt to check that the current line I am about to output begins with ':-', in which case it feels like it ought to be safe to emit a pragma source_file first, otherwise I will skip it. If that doesn't work then I will have to park the feature; the tool is meant to be generic and I don't want to have to know exactly what context the pragma might be rendered within as I output the code, first world problem.

Thanks again.
Sean





> On 16 Aug 2022, at 22:57, Zoltan Somogyi <zoltan.somogyi at runbox.com> wrote:
> 
> 
> 2022-08-17 07:34 GMT+10:00 "Sean Charles (emacstheviking)" <objitsu at gmail.com>:
>> Hi, I am trying to complete my literate programming tool by having it intersperse the above mentioned directives into the generated source, but having read section "19.6 Source file name" until I glazed over, I just cannot fathom my obvious error!
>> I have two small markdown files, which when rendered without the --mercury-lines option, an option to my program, stitch together and run just fine:
> 
>> main(!IO) :-
>> :- pragma source_file("mtest2.md").
>> #7
>>    io.format("Yay\n", [], !IO),
>> :- pragma source_file("mtest2.md").
>> #8
>>    io.format("Yay once again\n", [], !IO),
>> :- pragma source_file("mtest.md").
>> #19
>>    io.format("-- line counter test--\n", [], !IO),
>> :- pragma source_file("mtest.md").
>> #20
>>    io.format("this is the final and\n", [], !IO),
>> :- pragma source_file("mtest.md").
>> #21
>>    io.format("last word\n", [], !IO).
> 
> Source file directives, like other directives, may not occur in the middle
> of clauses, or in the middle of other directives. You get errors about
> the code above because it tries to put source_file directives into the middle
> of a clause.
> 
> Zoltan.



More information about the users mailing list