GEditIOImpl.mesa; Edited by McGregor on December 9, 1982 9:48 am
DIRECTORY
Convert USING [IntFromRope, ValueToRope],
GEditIO,
GEditViewer,
Rope USING [Cat, Concat, Equal, Fetch, ROPE, Size, Substr];
GEditIOImpl: PROGRAM
IMPORTS Convert, Rope
EXPORTS GEditIO =
BEGIN OPEN GEditViewer;
GetInteger:
PUBLIC PROC [rope: Rope.
ROPE, offset:
INT]
RETURNS [value:
INTEGER, newOffset:
INT] =
BEGIN
token: Rope.ROPE;
[token, newOffset] ← GetToken[rope, offset];
value ← Convert.IntFromRope[token];
END;
GetInt:
PUBLIC PROC [rope: Rope.
ROPE, offset:
INT]
RETURNS [value:
INT, newOffset:
INT] =
BEGIN
token: Rope.ROPE;
[token, newOffset] ← GetToken[rope, offset];
value ← Convert.IntFromRope[token];
END;
GetBoolean:
PUBLIC PROC [rope: Rope.
ROPE, offset:
INT]
RETURNS [value:
BOOL, newOffset:
INT] =
BEGIN
token: Rope.ROPE;
[token, newOffset] ← GetToken[rope, offset];
value ← Rope.Equal[token, "T"];
END;
GetRope:
PUBLIC PROC [rope: Rope.
ROPE, offset:
INT]
RETURNS [value: Rope.
ROPE, newOffset:
INT] =
BEGIN
[value, newOffset] ← GetToken[rope, offset, TRUE];
END;
GetToken:
PROC [rope: Rope.
ROPE, offset:
INT ← 0, thruEnd:
BOOL ←
FALSE]
RETURNS [token: Rope.
ROPE, newOffset:
INT] =
BEGIN
size: INT = Rope.Size[rope];
start: INT;
Sep:
PROC [c:
CHARACTER]
RETURNS [
BOOL] =
INLINE
BEGIN
RETURN[
SELECT c
FROM
' , ',, 11C, 15C, 0C => TRUE,
ENDCASE => FALSE];
END;
IF offset>=size THEN RETURN["", offset];
WHILE offset<size
AND Sep[Rope.Fetch[rope, offset]]
DO
offset ← offset+1;
ENDLOOP;
start ← offset;
DO
IF offset>=size
THEN
EXIT;
IF Sep[Rope.Fetch[rope, offset]] THEN EXIT;
offset ← offset+1;
ENDLOOP;
RETURN[Rope.Substr[rope, start,
IF thruEnd
THEN size
ELSE offset-start], offset];
END;
PutInteger:
PUBLIC PROC [rope: Rope.
ROPE, value:
INTEGER]
RETURNS [newRope: Rope.
ROPE] =
{newRope ← Rope.Cat[rope, Convert.ValueToRope[[signed[value, 10]]], ","]};
PutInt:
PUBLIC PROC [rope: Rope.
ROPE, value:
INT]
RETURNS [newRope: Rope.
ROPE] =
{newRope ← Rope.Cat[rope, Convert.ValueToRope[[signed[value, 10]]], ","]};
PutBoolean:
PUBLIC PROC [rope: Rope.
ROPE, value:
BOOL]
RETURNS [newRope: Rope.
ROPE] =
{newRope ← Rope.Concat[rope, IF value THEN "T," ELSE "F,"]};
END.