[m-users.] Free and Ground in the same error line?

Zoltan Somogyi zoltan.somogyi at runbox.com
Tue Oct 31 17:55:04 AEDT 2023


On 2023-10-30 23:05 +11:00 AEDT, "Sean Charles (emacstheviking)" <objitsu at gmail.com> wrote:
> I am using 22.01.6, and looking down into mercury_term_lexer.m, the list of returned token types
> doesn't include comments, not that I could see

The lexer for Mercury was adapted from an existing one for Prolog. Both were intended
to be used to implement their respective language, for which preserving comments
would have been a hindrance rather than help.

> so it might be harder scanning for documentation but given that the '%' being first on the line is the trigger
> I am sure a workaround could be done.

Sure, it could.

> The mmc-doc tool locates the predicate being asked for and then backtracks up the file to find the nearest comment block, for example

The problem of what to do with comments in prettyprinters is quite old.
It has no standard solution, because there is no one standard commenting style.
There are many, and they conflict. If two programmers write two identical constructs
and put a comment in an identical position between those two constructs,
one programmer may intend that comment to apply to the first construct,
while the second programmer may intend that comment to apply to the second construct.
This makes the problem ill-defined, which means there is no universal solution.

The only way around this is to explicitly define a set of rules about
"a comment placed *this* way means that it is about *that* construct".
Practically, such rules are probably useless unless they are imposed
at the very beginning of a language's existence, because otherwise
far too many projects grow their own incompatible comment conventions.
See Javadoc for a successful attempt at this. For Mercury, it is too late.

Zoltan.


More information about the users mailing list