mirror of
https://github.com/vishapoberon/compiler.git
synced 2026-04-05 23:22:25 +00:00
Much simplified text reader using Texts.Scanner (somewhat like the original Templ code.)
This commit is contained in:
parent
7dc38e98ea
commit
8c702a716e
2 changed files with 102 additions and 118 deletions
|
|
@ -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
|
||||
1 multiply defined identifier
|
||||
2 illegal character in number
|
||||
|
|
|
|||
|
|
@ -1,40 +1,19 @@
|
|||
MODULE errors;
|
||||
|
||||
IMPORT Files, Console;
|
||||
IMPORT Texts, Console;
|
||||
|
||||
VAR f: Files.File; r: Files.Rider;
|
||||
|
||||
PROCEDURE eoln(c: CHAR): BOOLEAN; BEGIN RETURN (c = 0DX) OR (c = 0AX) END eoln;
|
||||
VAR T: Texts.Text; S: Texts.Scanner;
|
||||
|
||||
PROCEDURE Write*(n: INTEGER);
|
||||
VAR done: BOOLEAN; e: INTEGER; c: CHAR;
|
||||
VAR l: INTEGER; c: CHAR;
|
||||
BEGIN
|
||||
IF f = NIL THEN f := Files.Old("VishapOberonErrors.txt") END;
|
||||
ASSERT(f # NIL);
|
||||
Files.Set(r, f, 0); Files.Read(r, c); done := r.eof;
|
||||
WHILE ~done DO (* Process one line each time round this loop *)
|
||||
IF (c >= '0') & (c <= '9') THEN (* Line begins with a number, parse it *)
|
||||
e := ORD(c) - ORD('0'); Files.Read(r, c);
|
||||
WHILE (c >= '0') & (c <= '9') DO
|
||||
e := e * 10 + ORD(c) - ORD('0');
|
||||
Files.Read(r, c)
|
||||
IF T = NIL THEN NEW(T); Texts.Open(T, "VishapOberonErrors.txt") END;
|
||||
Texts.OpenScanner(S, T, 0);
|
||||
REPEAT l := S.line; Texts.Scan(S)
|
||||
UNTIL (l # S.line) & (S.class = Texts.Int) & (S.i = n) OR S.eot;
|
||||
IF ~S.eot THEN Texts.Read(S, c);
|
||||
WHILE ~S.eot & (c >= ' ') DO Console.Char(c); Texts.Read(S, 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;
|
||||
|
||||
|
||||
BEGIN
|
||||
END errors.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue