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

Zoltan Somogyi zoltan.somogyi at runbox.com
Wed Aug 17 19:49:50 AEST 2022


2022-08-17 17:48 GMT+10:00 "Sean Charles (emacstheviking)" <objitsu at gmail.com>:
> Thanks Zoltan.
> 
> That's killed that feature then,

I am not sure what feature you mean, but I don't see why that follows.
The directives that you got the errors for are all totally unnecessary,
and can be trivially deleted. This is because in code such as

:- pragma source_file(FileName).
#N
... first line of code ...
:- pragma source_file(FileName).
#N+1
... second line of code
:- pragma source_file(FileName).
#N+2

only the first source file pragma and the first line number
actually do anything. Any source_file pragma that names
the same file as the previous one is a no-op, and likewise
any occurrence of #N that occurs K lines after the previous
#M directive, where N = M + K, is also redundant, since
the parser's line counting would know that the current line
number is M + K.

For example, when generating C code, the Mercury compiler
emits #line directives just before the bodies of foreign_procs.
It does not emit a separate directive for *each line* of the
foreign_proc, since that would be unnecessary, for the same reason.

If you emit source_file pragmas and #Ms only if they are
not redundant, your tool will work for any literate program
where each clause and directive is contiguous in the
source code. This is as it should be: if you think you need
to explain one half of a clause separately from its other half,
then you probably should create a separate predicate
for one half or the other.

Zoltan.


More information about the users mailing list