raz / commit b17e69bd

commit
b17e69bd2ee9c3f06c47621b5505596fc90e8299
author
Luis <42945842+ldiaz94@users.noreply.github.com>
date
parent
c8d9a160
tools/Scan.raz takes the scanner by var, or const to read it

Scan.init and next move the scanner and take var s: Scanner; text and
is only read it and take const. Doc, Mutate and Pretty drop their ADRs;
Pretty's endsOperand takes its scanner const. rmacs and ravite, which
use Scan as a tool, mend theirs when they move their pins, in the same
release as the library's, so that they break once.

patch · log

4 files changed, +61 -61

tools/Doc.raz (history) modified +4 -4

@@ -38,7 +38,7 @@
3838 docStart := -1;
3939 newLine := false;
4040 repeat
41- Scan.next(ADR(sc));
41+ Scan.next(sc);
4242 newLine := newLine or sc.lineBreak;
4343 if (sc.kind = Scan.comment) and newLine then
4444 docStart := sc.start; docEnd := sc.stop;
@@ -76,7 +76,7 @@
7676
7777 proc text: []U8;
7878 begin
79- return Scan.text(ADR(sc));
79+ return Scan.text(sc);
8080 end;
8181
8282 proc is(s: []U8): BOOL;
@@ -114,7 +114,7 @@
114114 while (stop < LEN(src)) and ((src[stop] = ' ') or (src[stop] = 9)) do INC(stop); end;
115115 t := sc;
116116 t.pos := stop;
117- Scan.next(ADR(t));
117+ Scan.next(t);
118118 if (t.kind = Scan.comment) and (t.start = stop) then return t.stop; end;
119119 return stop;
120120 end;
@@ -307,7 +307,7 @@
307307 Buf.init(b, Heap.heap);
308308 if not Files.read(path, b) then Rt.stop("Doc: can't read the file"); end;
309309 src := Buf.bytes(b);
310- Scan.init(ADR(sc), src);
310+ Scan.init(sc, src);
311311 next;
312312 while (sc.kind # Scan.eof) and not is("module") do next; end;
313313 if sc.kind = Scan.eof then Rt.stop("Doc: no module"); end;

tools/Mutate.raz (history) modified +10 -10

@@ -36,12 +36,12 @@
3636 proc count(): INT;
3737 var sc: Scan.Scanner; n: INT;
3838 begin
39- Scan.init(ADR(sc), src);
40- Scan.next(ADR(sc));
39+ Scan.init(sc, src);
40+ Scan.next(sc);
4141 n := 0;
4242 while sc.kind # Scan.eof do
4343 if sc.kind # Scan.comment then INC(n); end;
44- Scan.next(ADR(sc));
44+ Scan.next(sc);
4545 end;
4646 return n;
4747 end;
@@ -50,9 +50,9 @@
5050 proc symbol(k: INT): Scan.Scanner;
5151 var sc: Scan.Scanner;
5252 begin
53- Scan.init(ADR(sc), src);
53+ Scan.init(sc, src);
5454 repeat
55- Scan.next(ADR(sc));
55+ Scan.next(sc);
5656 if sc.kind # Scan.comment then DEC(k); end;
5757 until k < 0;
5858 return sc;
@@ -77,17 +77,17 @@
7777 if op = 0 then
7878 Out.str(src[a.stop..b.start]);
7979 elsif op = 1 then
80- Out.str(Scan.text(ADR(a)));
80+ Out.str(Scan.text(a));
8181 Out.str(" ");
82- Out.str(Scan.text(ADR(a)));
82+ Out.str(Scan.text(a));
8383 Out.str(src[a.stop..b.start]);
8484 elsif op = 2 then
85- Out.str(Scan.text(ADR(b)));
85+ Out.str(Scan.text(b));
8686 Out.str(src[a.stop..b.start]);
87- Out.str(Scan.text(ADR(a)));
87+ Out.str(Scan.text(a));
8888 b.start := b.stop; (* b has been written, as the first *)
8989 else
90- Out.str(Scan.text(ADR(c)));
90+ Out.str(Scan.text(c));
9191 Out.str(src[a.stop..b.start]);
9292 end;
9393 Out.str(src[b.start..LEN(src)]);

tools/Pretty.raz (history) modified +28 -28

@@ -94,10 +94,10 @@
9494 end;
9595
9696 (* Whether s ends an operand, so that a - after it subtracts. *)
97-proc endsOperand(s: ^Scan.Scanner): BOOL;
97+proc endsOperand(const s: Scan.Scanner): BOOL;
9898 begin
99- if s^.kind = Scan.word then return not Scan.reserved(Scan.text(s)); end;
100- return (s^.kind = Scan.number) or (s^.kind = Scan.literal)
99+ if s.kind = Scan.word then return not Scan.reserved(Scan.text(s)); end;
100+ return (s.kind = Scan.number) or (s.kind = Scan.literal)
101101 or Scan.is(s, ")") or Scan.is(s, "]") or Scan.is(s, "}") or Scan.is(s, "^");
102102 end;
103103
@@ -106,7 +106,7 @@
106106 var s: Scan.Scanner;
107107 begin
108108 s := sc;
109- repeat Scan.next(ADR(s)); until s.kind # Scan.comment;
109+ repeat Scan.next(s); until s.kind # Scan.comment;
110110 return s;
111111 end;
112112
@@ -115,18 +115,18 @@
115115 proc binary: BOOL;
116116 var n: Scan.Scanner;
117117 begin
118- if sc.kind = Scan.word then return Scan.among(Scan.text(ADR(sc)), binaryWords); end;
119- if (sc.kind # Scan.symbol) or not Scan.among(Scan.text(ADR(sc)), binarySymbols) then
118+ if sc.kind = Scan.word then return Scan.among(Scan.text(sc), binaryWords); end;
119+ if (sc.kind # Scan.symbol) or not Scan.among(Scan.text(sc), binarySymbols) then
120120 return false;
121121 end;
122122 (* a | after an operand is or; one after anything else starts an arm *)
123- if Scan.is(ADR(sc), "-") or Scan.is(ADR(sc), "+") or Scan.is(ADR(sc), "|") then
124- return endsOperand(ADR(prev));
123+ if Scan.is(sc, "-") or Scan.is(sc, "+") or Scan.is(sc, "|") then
124+ return endsOperand(prev);
125125 end;
126- if Scan.is(ADR(sc), "*") and (prev.kind = Scan.word) then
126+ if Scan.is(sc, "*") and (prev.kind = Scan.word) then
127127 n := following();
128- if Scan.among(Scan.text(ADR(n)), "; , : = )") then return false; end;
129- if Scan.is(ADR(n), "(") and Scan.is(ADR(prev2), "proc") then return false; end;
128+ if Scan.among(Scan.text(n), "; , : = )") then return false; end;
129+ if Scan.is(n, "(") and Scan.is(prev2, "proc") then return false; end;
130130 end;
131131 return true;
132132 end;
@@ -136,10 +136,10 @@
136136 proc continues: BOOL;
137137 var t: []U8;
138138 begin
139- if (brackets > 0) or prevBinary or Scan.is(ADR(prev), ",") then return true; end;
140- t := Scan.text(ADR(sc));
139+ if (brackets > 0) or prevBinary or Scan.is(prev, ",") then return true; end;
140+ t := Scan.text(sc);
141141 if sc.kind = Scan.word then return Scan.among(t, binaryWords) or Scan.among(t, "then do of"); end;
142- if Scan.is(ADR(sc), "|") then return endsOperand(ADR(prev)); end;
142+ if Scan.is(sc, "|") then return endsOperand(prev); end;
143143 return (sc.kind = Scan.symbol) and Scan.among(t, binarySymbols);
144144 end;
145145
@@ -147,10 +147,10 @@
147147 procedure type. *)
148148 proc declaration(s: Scan.Scanner): BOOL;
149149 begin
150- if (s.kind # Scan.word) or not Scan.among(Scan.text(ADR(s)), declarations) then return false; end;
151- if not Scan.is(ADR(s), "proc") then return true; end;
152- Scan.next(ADR(s));
153- return not Scan.is(ADR(s), "(");
150+ if (s.kind # Scan.word) or not Scan.among(Scan.text(s), declarations) then return false; end;
151+ if not Scan.is(s, "proc") then return true; end;
152+ Scan.next(s);
153+ return not Scan.is(s, "(");
154154 end;
155155
156156 (* The indent of the block's own lines, or of its end. *)
@@ -182,10 +182,10 @@
182182 end;
183183 if declaration(sc) then
184184 depth := 0;
185- inSection := Scan.among(Scan.text(ADR(sc)), "const type var");
185+ inSection := Scan.among(Scan.text(sc), "const type var");
186186 return 0;
187187 end;
188- if Scan.among(Scan.text(ADR(sc)), "end until else elsif |") then
188+ if Scan.among(Scan.text(sc), "end until else elsif |") then
189189 return outer();
190190 end;
191191 return inner();
@@ -216,8 +216,8 @@
216216 spaces(n);
217217 elsif afterComment then
218218 Buf.str(out, src[last..sc.start]);
219- elsif Scan.is(ADR(sc), ",") or Scan.is(ADR(sc), ";") then
220- elsif Scan.is(ADR(prev), ",") or Scan.is(ADR(prev), ";") or binaryNow or prevBinary then
219+ elsif Scan.is(sc, ",") or Scan.is(sc, ";") then
220+ elsif Scan.is(prev, ",") or Scan.is(prev, ";") or binaryNow or prevBinary then
221221 if not prevUnary then spaces(1); end;
222222 elsif not prevUnary then
223223 Buf.str(out, src[last..sc.start]);
@@ -254,7 +254,7 @@
254254 proc track(binaryNow: BOOL);
255255 var t: []U8;
256256 begin
257- t := Scan.text(ADR(sc));
257+ t := Scan.text(sc);
258258 if sc.kind = Scan.word then
259259 if Scan.among(t, openers) then
260260 if depth = LEN(bases) then Rt.stop("Pretty: blocks nested too deep"); end;
@@ -268,8 +268,8 @@
268268 elsif Scan.among(t, ") ] }") and (brackets > 0) then DEC(brackets);
269269 end;
270270 end;
271- prevUnary := (Scan.is(ADR(sc), "-") or Scan.is(ADR(sc), "+")) and not binaryNow
272- or Scan.is(ADR(sc), "~");
271+ prevUnary := (Scan.is(sc, "-") or Scan.is(sc, "+")) and not binaryNow
272+ or Scan.is(sc, "~");
273273 prevBinary := binaryNow;
274274 prev2 := prev;
275275 prev := sc;
@@ -296,14 +296,14 @@
296296 inSection := false;
297297 stmtIndent := 0;
298298 stmtDelta := 0;
299- Scan.init(ADR(sc), src);
299+ Scan.init(sc, src);
300300 prev := sc;
301301 prev2 := sc;
302302 prevBinary := false;
303303 prevUnary := false;
304304 afterComment := false;
305305 last := 0;
306- Scan.next(ADR(sc));
306+ Scan.next(sc);
307307 while sc.kind # Scan.eof do
308308 b := (sc.kind # Scan.comment) and binary();
309309 if sc.lineBreak then
@@ -316,7 +316,7 @@
316316 afterComment := sc.kind = Scan.comment;
317317 if not afterComment then track(b); end;
318318 last := sc.stop;
319- Scan.next(ADR(sc));
319+ Scan.next(sc);
320320 end;
321321 lineBreaks(last, LEN(src));
322322 trim;

tools/Scan.raz (history) modified +19 -19

@@ -60,9 +60,9 @@
6060 end;
6161
6262 (* The scanner at the start of src; next gives the first symbol. *)
63-proc init*(s: ^Scanner; src: []U8);
63+proc init*(var s: Scanner; src: []U8);
6464 begin
65- s^ := {src: src, kind: eof};
65+ s := {src: src, kind: eof};
6666 end;
6767
6868 (* Past the comment that starts at p, its nested comments with it. *)
@@ -121,32 +121,32 @@
121121 end;
122122
123123 (* On to the next symbol. *)
124-proc next*(s: ^Scanner);
124+proc next*(var s: Scanner);
125125 var src: []U8; p: INT; c: U8;
126126 begin
127- src := s^.src;
128- p := s^.pos;
129- s^.lineBreak := p = 0;
127+ src := s.src;
128+ p := s.pos;
129+ s.lineBreak := p = 0;
130130 while (p < LEN(src)) and isSpace(src[p]) do
131- if src[p] = '\n' then s^.lineBreak := true; end;
131+ if src[p] = '\n' then s.lineBreak := true; end;
132132 INC(p);
133133 end;
134- s^.start := p;
134+ s.start := p;
135135 if p >= LEN(src) then
136- s^.kind := eof;
136+ s.kind := eof;
137137 else
138138 c := src[p];
139139 if at(src, p, "(*") then
140- s^.kind := comment; p := pastComment(src, p);
140+ s.kind := comment; p := pastComment(src, p);
141141 elsif isDigit(c) then
142- s^.kind := number; p := pastNumber(src, p);
142+ s.kind := number; p := pastNumber(src, p);
143143 elsif isWord(c) then
144- s^.kind := word;
144+ s.kind := word;
145145 while (p < LEN(src)) and isWord(src[p]) do INC(p); end;
146146 elsif (c = '"') or (c = '\'') or (c = '`') then
147- s^.kind := literal; p := pastLiteral(src, p);
147+ s.kind := literal; p := pastLiteral(src, p);
148148 else
149- s^.kind := symbol;
149+ s.kind := symbol;
150150 if at(src, p, "...") then INC(p, 3);
151151 elsif at(src, p, ":=") or at(src, p, "<=") or at(src, p, ">=") or at(src, p, "..") then
152152 INC(p, 2);
@@ -155,17 +155,17 @@
155155 end;
156156 end;
157157 end;
158- s^.stop := p;
159- s^.pos := p;
158+ s.stop := p;
159+ s.pos := p;
160160 end;
161161
162-proc text*(s: ^Scanner): []U8;
162+proc text*(const s: Scanner): []U8;
163163 begin
164- return s^.src[s^.start..s^.stop];
164+ return s.src[s.start..s.stop];
165165 end;
166166
167167 (* Whether the current symbol is t. *)
168-proc is*(s: ^Scanner; t: []U8): BOOL;
168+proc is*(const s: Scanner; t: []U8): BOOL;
169169 begin
170170 return text(s) = t;
171171 end;