[m-rev.] for post-commit review: start using string builders in parse_tree_out*.m

Zoltan Somogyi zoltan.somogyi at runbox.com
Sat Jul 8 23:04:18 AEST 2023


For review by anyone.

A heads-up about future changes: I intend to continue to convert
the rest of parse_tree_out*.m to use string builders. One issue
I have already noticed is that in some cases,  X_to_string and write_X
predicates do slightly different things. Reimplementing them both
in terms of a new format_X predicate will thus change the semantics
of one or the other.

The instance of this issue that is marked by an XXX in this diff is that
write_X escapes any graphic characters in the strings it contains, while
X_to_string does not. I propose to fix all such inconsistencies by
making both versions escape strings. The reasoning for this is that

- generating valid Mercury code (in .intN or .*opt files) requires such escapes
  for valid readback

- output generated for debugging use (e.g. in HLDS dumps) should be
  fine with both escaped and unescaped versions, given that most names
  contain nothing that needs to be escaped.

The one use case I can think of where we definitely want unescaped strings
is in error messages, for which it is sufficient to never call the functions that
do escaping from write_error_spec.m. Can anyone think of another such
use case?

I also propose that

- we should include either "escaped" or "unescaped" (or something similar)
  in the name of any operation that has both versions,

- we should not include "escaped" in the name of any operation
  that has no unescaped version, and vice versa, but that the documentation
  of each such operation should specify escaped vs unescaped.

Opinions?

Zoltan.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Log.pto
Type: application/octet-stream
Size: 2350 bytes
Desc: not available
URL: <http://lists.mercurylang.org/archives/reviews/attachments/20230708/642c65a4/attachment-0002.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: DIFF.pto
Type: application/octet-stream
Size: 65650 bytes
Desc: not available
URL: <http://lists.mercurylang.org/archives/reviews/attachments/20230708/642c65a4/attachment-0003.obj>


More information about the reviews mailing list