Much simplified text reader using Texts.Scanner (somewhat like the original Templ code.)

This commit is contained in:
David Brown 2016-07-12 20:06:47 +01:00
parent 7dc38e98ea
commit 8c702a716e
2 changed files with 102 additions and 118 deletions

View file

@ -1,3 +1,8 @@
The first line of this file is ignored.
Any line not starting /^ *[0-9]/ is ignored.
There should be only one space between the number and the message text.
Compiler error messages
0 undeclared identifier 0 undeclared identifier
1 multiply defined identifier 1 multiply defined identifier
2 illegal character in number 2 illegal character in number

View file

@ -1,40 +1,19 @@
MODULE errors; MODULE errors;
IMPORT Files, Console; IMPORT Texts, Console;
VAR f: Files.File; r: Files.Rider; VAR T: Texts.Text; S: Texts.Scanner;
PROCEDURE eoln(c: CHAR): BOOLEAN; BEGIN RETURN (c = 0DX) OR (c = 0AX) END eoln;
PROCEDURE Write*(n: INTEGER); PROCEDURE Write*(n: INTEGER);
VAR done: BOOLEAN; e: INTEGER; c: CHAR; VAR l: INTEGER; c: CHAR;
BEGIN BEGIN
IF f = NIL THEN f := Files.Old("VishapOberonErrors.txt") END; IF T = NIL THEN NEW(T); Texts.Open(T, "VishapOberonErrors.txt") END;
ASSERT(f # NIL); Texts.OpenScanner(S, T, 0);
Files.Set(r, f, 0); Files.Read(r, c); done := r.eof; REPEAT l := S.line; Texts.Scan(S)
WHILE ~done DO (* Process one line each time round this loop *) UNTIL (l # S.line) & (S.class = Texts.Int) & (S.i = n) OR S.eot;
IF (c >= '0') & (c <= '9') THEN (* Line begins with a number, parse it *) IF ~S.eot THEN Texts.Read(S, c);
e := ORD(c) - ORD('0'); Files.Read(r, c); WHILE ~S.eot & (c >= ' ') DO Console.Char(c); Texts.Read(S, c) END
WHILE (c >= '0') & (c <= '9') DO
e := e * 10 + ORD(c) - ORD('0');
Files.Read(r, c)
END END
ELSE
e := n+1; (* Line does not begin with a number, make sure we don't match *)
END;
IF e = n THEN
WHILE c = ' ' DO Files.Read(r, c) END; (* Rest of this line is the message we want *)
WHILE ~eoln(c) & ~r.eof DO Console.Char(c); Files.Read(r, c) END;
done := TRUE
ELSE
(* This line does not contain our message *)
WHILE ~eoln(c) & ~r.eof DO Files.Read(r, c) END;
WHILE eoln(c) DO Files.Read(r, c) END;
done := r.eof
END
END;
END Write; END Write;
BEGIN
END errors. END errors.