Dear colleagues,
the documentation for TextModels.Reader.ReadRun states:
Read next attribute run, stops at next view.
I interpret "read next attribute run" as:
(* Not a quote, markup just for highliting *)
Post:
(attr = AttributeOf(rd.Pos() - 1)) & (rd.eot OR (attr # AttributeOf(rd.Pos()))
My example demonstrates that TextModels.StdReader.ReadRun fails to adhere to this interpretation - it does not stop the reader at exactly the end of the run having attr and thus fails to be useful in iterating text stretches of uniform attributes. While I understand that this is not exactly a bug - it fails to adhere to my interpretation, not the explicitly stated conditions - I move to amend the documentation to include my interpretation (boldface), which is I believe soundly grounded.
All in favor say I )
Now it's a bug! Just kidding.
The following text in ReadRun's documentation is also inconsistent with my interpretation:
Except for performance, equivalent to:
Code: Select all
VAR a: Attributes;
a := rd.attr;
REPEAT rd.Read UNTIL (rd.attr # a) OR (rd.view # NIL) OR rd.eot;
IF rd.eot THEN attr := NIL ELSE attr := rd.attr END
Thus I propose a fix to this issue. The fix is generic to Reader, not specific to StdReader (the reason is, I'm not competent in StdReader/StdModel internals):
REPLACE in TextModels
Code: Select all
PROCEDURE (rd: Reader) ReadRun* (OUT attr: Attributes), NEW, ABSTRACT;
With the following:
Code: Select all
PROCEDURE (rd: Reader) ReadRun* (OUT attr: TextModels.Attributes), NEW, EXTENSIBLE;
(** post: rd.eot OR a # NIL, rd.view = ViewAt(rd.Pos() - 1) **)
BEGIN
rd.Read; attr := rd.attr;
IF rd.view = NIL THEN
WHILE (rd.attr = attr) & (rd.view = NIL) & ~rd.eot DO rd.Read END;
IF ~rd.eot OR (rd.view # NIL) THEN rd.ReadPrev END
END
END ReadRun;
AND comment out
- maybe someone will be willing to fix it at the level of internals.
I have searched thru standard BlackBox codebase, and found 2 uses of ReadRun, both would not be broken by my proposal (they don't use .Pos() right after .ReadRun). Good news: no dependencies will be broken. Bad news (for me): not exactly a relevant bug
. But it bugged me nonetheless in my little tool.
Attached is the module with the aforementioned example and fix.
P.S. SOOOO unfortunate we still don't have a native BB forum to be able to easily use BB texts in posts!