raz / commit 972ed02a

commit
972ed02a2598ef8d2dc8bedb8623ee63563515b2
author
Luis <42945842+ldiaz94@users.noreply.github.com>
date
parent
c290b2c8
Docs, tutorial and tour for strings; the compiler follows report 2026-10.25

The tour's strings lesson takes strings apart with Str.cut and
Str.field, shows raw strings, indented and not, and walks UTF-8 with
Str.next; the variants lesson matches strings; the memory lesson
builds with Str.join and Str.replace; the advanced tour reads numbers
with Str.cut, Str.toHex, Math.toReal and Str.fromInt. The tutorial,
raz(7), the README and the home page say the same. examples/Settings
reads settings from an indented raw string, Sh picks its builtins by a
match on a string, and Words takes its text apart with Str.field;
tools/Doc uses Str.trim, and reads \(ga in a page as a backquote, as
the site's builder does. The editors' colour test has a raw string.

patch · log

24 files changed, +333 -100

CLAUDE.md modified +3 -1

@@ -78,7 +78,9 @@
7878
7979 ## Where things stand
8080
81-v0.12.0, report 2026-10.24, is the latest release. `src/` is the
81+v0.12.0, report 2026-10.24, is the latest release; `main` has report
82+2026-10.25, the thaw for strings (raw strings, `match` on a string,
83+`Str`'s new procedures, `Math.toReal`), not yet released. `src/` is the
8284 compiler in raz, built by itself (Self, done); the seed in `seed/` is
8385 frozen, and v0.9.1 was the last release it built. The compiler takes
8486 1.4 times the Pascal one's time; `make kernels` measures `test/bench`

README.md (history) modified +4 -1

@@ -150,6 +150,9 @@
150150 size, in the order written. `CAS`, `XCHG`, `XADD`, `FENCE`.
151151 - `and`, `or` and `not` for `BOOL`s; `&`, `|`, `xor` and `~` for bits;
152152 `=` on arrays and strings.
153+- Strings are `[]U8`, in UTF-8; raw strings between backquotes run over
154+ lines and keep the indent of the code around them; `match` takes a
155+ string.
153156 - Several results, `ERROR` values compared by identity, `defer`.
154157 - Modules with bodies; generic modules with type and procedure
155158 arguments, `Map(K, V; hash, eq)`.
@@ -158,7 +161,7 @@
158161 - `extern` procedures and variables from C; code procedures written in
159162 the target's assembly language; `SYSCALL`.
160163
161-The report, `doc/raz.md` and `doc/raz-lib.md`, says all of it in about 2,100 lines.
164+The report, `doc/raz.md` and `doc/raz-lib.md`, says all of it in about 2,300 lines.
162165
163166 ## The library
164167

doc/compiler.md (history) modified +1 -1

@@ -1,6 +1,6 @@
11 # Reading the raz compiler
22
3-The compiler is eleven files of raz, about 10,800 lines of code (the
3+The compiler is eleven files of raz, about 10,900 lines of code (the
44 budget is a soft 10,000, never past 11,000). It is its own compiler: the
55 frozen Pascal compiler in `seed/` builds `src/` the first time, and
66 after that a raz builds `src/` (`make fixpoint` checks that it makes

doc/raz-tutorial.7 (history) modified +32 -4

@@ -2,7 +2,7 @@
22 .\" Every whole module in a literal block here is a program that make
33 .\" check compiles and runs, against test/man/Name.expect; see
44 .\" tools/Doc.raz.
5-.Dd October 12, 2026
5+.Dd October 14, 2026
66 .Dt RAZ-TUTORIAL 7
77 .Os
88 .Sh NAME
@@ -308,7 +308,7 @@
308308 end;
309309
310310 proc main*;
311-var a: [5]INT; i: INT; s: []U8; name: [8]U8;
311+var a: [5]INT; i: INT; s, val: []U8; name: [8]U8; ok: BOOL;
312312 begin
313313 for i := 0 to 4 do a[i] := i * i; end;
314314 Out.int(sum(a)); Out.ln; (* the array, as a slice *)
@@ -317,9 +317,15 @@
317317 Out.str(s[7..LEN(s)]); Out.ln;
318318 if s[0..5] = "hello" then Out.str("it says hello\en"); end;
319319 Out.int(Str.find(s, "world")); Out.ln;
320+ _, val, ok := Str.cut(" size = 42 ", "=");
321+ if ok then Out.str(Str.trim(val)); Out.ln; end;
320322 name := "raz"; (* a copy, the program's own *)
321323 name[0] := 'R';
322324 Out.str(name[0..3]); Out.ln;
325+ Out.str(\(ga
326+ C:\etmp\e "as it stands"
327+ over lines
328+ \(ga);
323329 end;
324330
325331 end Slices.
@@ -330,7 +336,10 @@
330336 world
331337 it says hello
332338 7
339+42
333340 Raz
341+C:\etmp\e "as it stands"
342+ over lines
334343 .Ed
335344 .Pp
336345 .Cm [5]INT
@@ -358,8 +367,15 @@
358367 and
359368 .Cm # ;
360369 .Cm Str
361-has the rest: ordering, finding, hashing, UTF-8 and reading a number.
370+has the rest: ordering, finding, trimming, cutting a string into
371+parts, which are slices of it, UTF-8, and numbers to and from text.
362372 .Pp
373+A string between backquotes is raw: no escapes, and it may run over
374+lines.
375+When the opening backquote ends its line and the closing one has
376+only blanks before it, those blanks come off every line, so the text
377+stands at the indent of the code around it.
378+.Pp
363379 A
364380 .Cm for
365381 loop takes its bounds once, and never steps past the last: with an
@@ -740,6 +756,15 @@
740756 end;
741757 end;
742758
759+proc colour(name: []U8): Colour;
760+begin
761+ match name of
762+ | "red", "rose": return red;
763+ | "green": return green;
764+ | else: return blue;
765+ end;
766+end;
767+
743768 proc main*;
744769 var shapes: [3]Shape; i: INT; warm: Colours; c: Colour;
745770 begin
@@ -753,6 +778,7 @@
753778 for c := red to blue do
754779 if c in warm then Out.int(I64(c)); Out.ln; end;
755780 end;
781+ Out.int(I64(colour("rose"))); Out.int(I64(colour("green"))); Out.ln;
756782 end;
757783
758784 end Shapes.
@@ -764,6 +790,7 @@
764790 digit letter other
765791 0
766792 1
793+01
767794 .Ed
768795 .Pp
769796 An enumeration is a list of names, in order; a
@@ -786,7 +813,8 @@
786813 comes last.
787814 On an integer,
788815 .Cm match
789-takes constants and ranges, and must have an
816+takes constants and ranges, and on a string, string constants; both
817+must have an
790818 .Cm "| else:" .
791819 .Sh 12. GENERIC MODULES
792820 A module may take types, and the procedures it needs on them, as

doc/raz.7 (history) modified +10 -1

@@ -1,5 +1,5 @@
11 .\" raz(7) - the raz language at a glance
2-.Dd October 12, 2026
2+.Dd October 14, 2026
33 .Dt RAZ 7
44 .Os
55 .Sh NAME
@@ -45,6 +45,11 @@
4545 .It Strings
4646 .Cm \(dqhello\en\(dq ,
4747 its UTF-8 bytes, ending on its line.
48+.It Raw strings
49+.Cm \(gaC:\etmp\(ga ,
50+the text between backquotes as it stands, no escapes, over lines; if
51+the opening backquote ends its line and the closing one has only
52+blanks before it, those blanks come off every line.
4853 .It Escapes
4954 .Cm \en \et \er \e0 \e\e \e' \e\(dq \eu{E9} ,
5055 and in strings
@@ -432,6 +437,10 @@
432437 enumeration, an arm for each name; on an integer, arms of constants
433438 and ranges,
434439 .Cm "| '0' .. '9':" ,
440+and an
441+.Cm "| else:" ;
442+on a string, arms of string constants,
443+.Cm "| \(dqadd\(dq, \(dqplus\(dq:" ,
435444 and an
436445 .Cm "| else:" ,
437446 which any

doc/raz.md (history) modified +0 -3

@@ -24,9 +24,6 @@
2424 and may be indented with the code around them (section 2), and
2525 `match` on a string (section 7.4); it breaks no program.
2626
27-The compiler follows version 2026-10.24 until it has what 2026-10.25
28-adds.
29-
3027 The language is frozen, softly, from this version on: it changes only
3128 to mend a defect, and its library grows only by what breaks no program
3229 written for it. What anyone wishes it had waits on a list, for a later

examples/Settings.expect (history) added +4 -0

@@ -0,0 +1,4 @@
1+line 5: colour = "green"
2+line 6: depth
3+raz \ settings: 80 by 24, at 1.5
4+5 characters in naïve

examples/Settings.raz (history) added +65 -0

@@ -0,0 +1,65 @@
1+(* Strings: reads settings from a text of its own, written as a raw
2+ string that keeps the indent of the code around it. Each line is a
3+ name, =, and a value; # starts a comment. Str takes the lines apart
4+ without copying them, and a match on a string picks what each name
5+ sets. *)
6+module Settings;
7+import Out, Fmt, Str, Math;
8+
9+const
10+ Text = `
11+ # a window
12+ title = raz \ settings
13+ width = 80
14+ Height=24
15+ scale = 1.5
16+ colour = "green"
17+ depth
18+ `;
19+
20+var
21+ title: []U8;
22+ width, height: I64;
23+ scale: F64;
24+
25+(* One setting: false if the name isn't known, or its value is wrong. *)
26+proc setting(name, value: []U8): BOOL;
27+var ok: BOOL; lower: [16]U8;
28+begin
29+ if LEN(name) > LEN(lower) then return false; end;
30+ COPY(lower, name);
31+ Str.lower(lower[0..LEN(name)]);
32+ ok := true;
33+ match lower[0..LEN(name)] of
34+ | "title": title := value;
35+ | "width": width, ok := Str.toInt(value);
36+ | "height": height, ok := Str.toInt(value);
37+ | "scale": scale, ok := Math.toReal(value);
38+ | else: ok := false;
39+ end;
40+ return ok;
41+end;
42+
43+proc main*;
44+var line, rest, name, value: []U8; more, found: BOOL; n: INT;
45+begin
46+ rest := Text;
47+ more := true;
48+ while more do
49+ line, rest, more := Str.cut(rest, "\n");
50+ line, _, _ := Str.cut(line, "#");
51+ line := Str.trim(line);
52+ if LEN(line) > 0 then
53+ INC(n);
54+ name, value, found := Str.cut(line, "=");
55+ if not found or not setting(Str.trim(name), Str.trim(value)) then
56+ Fmt.print("line {}: {}\n", [Fmt.int(n), Fmt.str(line)]);
57+ end;
58+ end;
59+ end;
60+ Fmt.print("{}: {} by {}, at {}\n", [Fmt.str(title), Fmt.int(width), Fmt.int(height),
61+ Fmt.real(scale, 1)]);
62+ Out.int(Str.chars("naïve")); Out.str(" characters in naïve\n");
63+end;
64+
65+end Settings.

examples/Sh.raz (history) modified +5 -4

@@ -208,21 +208,22 @@
208208 proc builtin(c: ^Command): BOOL;
209209 var dir: []U8; n: I64; pid, _code: INT; ok: BOOL; _st: Sys.Status;
210210 begin
211- if c^.args[0] = "cd" then
211+ match c^.args[0] of
212+ | "cd":
212213 if c^.n > 1 then dir := c^.args[1]; else dir := Sys.env("HOME"); end;
213214 status := 0;
214215 if Sys.setWorkDir(dir) < 0 then say("cd: can't go to {}", [Fmt.str(dir)]); status := 1; end;
215- elsif c^.args[0] = "wait" then
216+ | "wait":
216217 repeat pid, _st, _code := Sys.wait(-1, true); until pid < 0;
217218 status := 0;
218- elsif c^.args[0] = "exit" then
219+ | "exit":
219220 n := status;
220221 if c^.n > 1 then
221222 n, ok := Str.toInt(c^.args[1]);
222223 if not ok then say("exit: {} isn't a number", [Fmt.str(c^.args[1])]); n := 2; end;
223224 end;
224225 Rt.exit(INT(n));
225- else
226+ | else:
226227 return false;
227228 end;
228229 return true;

examples/Words.raz (history) modified +11 -13

@@ -1,5 +1,6 @@
1-(* Generic modules: counts the words of a text in a Map from []U8 to
2- INT, hashed and compared by Str's procedures, keeps them in order of
1+(* Generic modules: counts the words of a text, taken apart by
2+ Str.field, in a Map from []U8 to INT, hashed and compared by Str's
3+ procedures, keeps them in order of
34 first sight in a List([]U8), and prints them with Fmt. *)
45 module Words;
56 import Fmt, Str, Heap, Count := Map([]U8, INT, Str.hash, Str.eq), Names := List([]U8);
@@ -9,20 +10,17 @@
910 proc main*;
1011 var
1112 counts: Count.Map; order: Names.List; n: ^Names.Node;
12- i, start, k, total: INT; found, _ok: BOOL; w: []U8;
13+ k, total: INT; found, _ok: BOOL; w, rest: []U8;
1314 begin
1415 Count.init(ADR(counts), Heap.heap);
1516 Names.init(ADR(order), Heap.heap);
16- start := 0;
17- for i := 0 to LEN(Text) do
18- if (i = LEN(Text)) or (Text[i] = ' ') then
19- w := Text[start..i];
20- INC(total);
21- k, found := Count.get(ADR(counts), w);
22- if not found then _ok := Names.push(ADR(order), w); end;
23- _ok := Count.put(ADR(counts), w, k + 1);
24- start := i + 1;
25- end;
17+ w, rest := Str.field(Text);
18+ while LEN(w) > 0 do
19+ INC(total);
20+ k, found := Count.get(ADR(counts), w);
21+ if not found then _ok := Names.push(ADR(order), w); end;
22+ _ok := Count.put(ADR(counts), w, k + 1);
23+ w, rest := Str.field(rest);
2624 end;
2725 Names.reverse(ADR(order));
2826 n := order.head;

site/build.py modified +4 -3

@@ -57,7 +57,7 @@
5757
5858 TOKEN = re.compile(r"""
5959 (?P<comment>\(\*.*?\*\)) |
60- (?P<string>"(?:\\.|[^"\\\n])*"|'(?:\\.|[^'\\\n])*') |
60+ (?P<string>"(?:\\.|[^"\\\n])*"|'(?:\\.|[^'\\\n])*'|`[^`]*`) |
6161 (?P<number>\b\d[0-9A-Fa-f]*(?:\.\d+)?(?:E[-+]?\d+)?H?\b) |
6262 (?P<word>[A-Za-z_][A-Za-z_0-9]*)
6363 """, re.X | re.S)
@@ -92,8 +92,9 @@
9292 blocks.append("\n".join(cur) + "\n")
9393 cur = None
9494 elif cur is not None:
95- # roff writes a backslash as \e and a dot at a line's start as \&.
96- cur.append(line.replace("\\&", "").replace("\\e", "\\"))
95+ # roff writes a backslash as \e, a backquote as \(ga and a dot
96+ # at a line's start as \&.
97+ cur.append(line.replace("\\&", "").replace("\\(ga", "`").replace("\\e", "\\"))
9798 return blocks
9899
99100 def tutorial_module(name):

site/content/advanced/02-bytes.txt (history) modified +16 -11

@@ -171,33 +171,38 @@
171171
172172 ## Numbers and text
173173
174-`Str.toInt` reads a decimal number with an optional sign and nothing else, and says whether it was one. `Fmt` goes the other way. `Str.encode` and `Str.decode` move between characters and UTF-8, as the first tour showed.
174+`Str.toInt` reads a decimal number with an optional sign and nothing else, and says whether it was one; `Str.toHex` reads hexadecimal digits, and `Math.toReal` a real, as a constant is written but with `e` for `E` too, to the nearest `F64` exactly. `Str.fromInt` goes the other way into an array of 20 bytes, with no allocator, and `Fmt` does the rest. `Str.encode` and `Str.decode` move between characters and UTF-8, as the first tour showed.
175175
176176 ```raz Numbers run
177177 module Numbers;
178-import Out, Str;
178+import Out, Str, Math, Fmt;
179179
180180 (* the sum of the numbers in a comma separated list, or -1 if any isn't *)
181181 proc total(s: []U8): I64;
182-var start, i: INT; sum, n: I64; ok: BOOL;
182+var part: []U8; sum, n: I64; ok, more: BOOL;
183183 begin
184- start := 0;
185- for i := 0 to LEN(s) do
186- if (i = LEN(s)) or (s[i] = ',') then
187- n, ok := Str.toInt(s[start..i]);
188- if not ok then return -1; end;
189- sum := sum + n;
190- start := i + 1;
191- end;
184+ more := true;
185+ while more do
186+ part, s, more := Str.cut(s, ",");
187+ n, ok := Str.toInt(part);
188+ if not ok then return -1; end;
189+ sum := sum + n;
192190 end;
193191 return sum;
194192 end;
195193
196194 proc main*;
195+var u: U64; x: F64; ok: BOOL; digits: [20]U8; k: INT;
197196 begin
198197 Out.int(total("10,20,-5,+7")); Out.ln;
199198 Out.int(total("10,x,20")); Out.ln;
200199 Out.int(total("10,,20")); Out.ln;
200+ u, ok := Str.toHex("ff00");
201+ if ok then Out.hex(u, 1); Out.ln; end;
202+ x, ok := Math.toReal("-1.5e3");
203+ if ok then Fmt.print("{}\n", [Fmt.real(x, 1)]); end;
204+ digits, k := Str.fromInt(-9223372036854775807 - 1);
205+ Out.str(digits[0..k]); Out.ln;
201206 end;
202207
203208 end Numbers.

site/content/advanced/03-collections.txt (history) modified +7 -10

@@ -92,18 +92,15 @@
9292
9393 proc main*;
9494 var
95- m: Count.Map; entries: [32]Entry; i, start, k, n, found: INT;
96- w: []U8; key: []U8; v: INT;
95+ m: Count.Map; entries: [32]Entry; i, k, n, found: INT;
96+ w, rest: []U8; key: []U8; v: INT;
9797 begin
9898 Count.init(ADR(m), Heap.heap);
99- start := 0;
100- for i := 0 to LEN(Text) do
101- if (i = LEN(Text)) or (Text[i] = ' ') then
102- w := Text[start..i];
103- k, _ := Count.get(ADR(m), w);
104- _ := Count.put(ADR(m), w, k + 1);
105- start := i + 1;
106- end;
99+ w, rest := Str.field(Text);
100+ while LEN(w) > 0 do
101+ k, _ := Count.get(ADR(m), w);
102+ _ := Count.put(ADR(m), w, k + 1);
103+ w, rest := Str.field(rest);
107104 end;
108105 n := 0;
109106 found, key, v := Count.next(ADR(m), 0);

site/content/home.html (history) modified +1 -0

@@ -39,6 +39,7 @@
3939 <li>Integers of 8 to 64 bits, signed and unsigned, which wrap; <code>BOOL</code>, <code>F32</code>, <code>F64</code>. Nothing converts unless it is written.</li>
4040 <li>Arrays, checked slices, pointers, records laid out as C lays them out, packed records, enumerations, sets, and variants with <code>match</code>.</li>
4141 <li>Every index and slice is checked; a failure says where it was, with the values, and the calls under way.</li>
42+ <li>Strings of UTF-8 bytes, raw strings over lines that keep the code's indent, and <code>match</code> on a string.</li>
4243 <li>Every variable starts at zero. Behaviour is defined everywhere but through pointers.</li>
4344 <li>No garbage collector: memory comes from an allocator the program chooses and passes.</li>
4445 <li>Several results, <code>ERROR</code> values and <code>defer</code>, in place of exceptions.</li>

site/content/tour/01-hello.txt (history) modified +1 -1

@@ -37,7 +37,7 @@
3737
3838 ## What `Out` can write
3939
40-`Out` is the library's buffered output. It writes strings, single characters, numbers in decimal or hexadecimal, and a line feed. A string is written as it is, with `\n` for a line feed, `\t` for a tab, `\"` and `\\`.
40+`Out` is the library's buffered output. It writes strings, single characters, numbers in decimal or hexadecimal, and a line feed. A string is written as it is, with `\n` for a line feed, `\t` for a tab, `\"` and `\\`; or between backquotes, as a raw string with no escapes at all, which may run over lines (lesson 6).
4141
4242 ```raz Numbers run
4343 module Numbers;

site/content/tour/06-slices.txt (history) modified +92 -20

@@ -1,6 +1,6 @@
11 title: Arrays, slices and strings
22 part: Set
3-summary: Five in a row, a window onto them, bytes in UTF-8, and checks on every index.
3+summary: Five in a row, a window onto them, bytes in UTF-8, raw strings over lines, and checks on every index.
44 ---
55 ```raz Slices run
66 ```
@@ -90,7 +90,7 @@
9090
9191 ## Strings
9292
93-A string is a slice of bytes, `[]U8`, in UTF-8, and a string constant's bytes are constant. A `[8]U8` made from one is a copy you can change. Arrays and slices of integers compare with `=` and `#`, so strings do too. `Str` has the rest: ordering, finding, hashing, prefixes, UTF-8 and reading a number.
93+A string is a slice of bytes, `[]U8`, in UTF-8, and a string constant's bytes are constant. A `[8]U8` made from one is a copy you can change. Arrays and slices of integers compare with `=` and `#`, so strings do too. `Str` has the rest: ordering, finding, hashing, prefixes and suffixes, trimming, taking apart, ASCII case, UTF-8, and numbers to and from text.
9494
9595 ```raz Words run
9696 module Words;
@@ -104,8 +104,12 @@
104104 if s[0..5] = "hello" then Out.str("it says hello\n"); end;
105105 Out.int(Str.find(s, "world")); Out.ln; (* 7 *)
106106 Out.int(Str.find(s, "xyz")); Out.ln; (* -1 *)
107+ Out.int(Str.findLast("abcabc", "bc")); Out.ln; (* 4 *)
107108 if Str.hasPrefix(s, "hell") then Out.str("prefix\n"); end;
109+ if Str.hasSuffix(s, "world") then Out.str("suffix\n"); end;
108110 Out.int(Str.cmp("apple", "banana")); Out.ln; (* -1 *)
111+ if Str.eqFold("RAZ", "raz") then Out.str("the same, but for case\n"); end;
112+ Out.str("["); Out.str(Str.trim(" padded \t\n")); Out.str("]\n");
109113
110114 n, ok := Str.toInt("-1234");
111115 if ok then Out.int(n + 1); Out.ln; end;
@@ -115,47 +119,115 @@
115119 name := "raz"; (* a copy, the program's own *)
116120 name[0] := 'R';
117121 Out.str(name[0..3]); Out.ln;
122+ Str.upper(name[0..3]); (* in place: name is a variable *)
123+ Out.str(name[0..3]); Out.ln;
118124 end;
119125
120126 end Words.
121127 ```
122128
123-## UTF-8
129+## Taking a string apart
124130
125-A character is an `I32`, its code point. `Str.decode` reads the first character of a string and says how many bytes it took; `Str.encode` goes the other way. Byte length and character count are different things, and the program is the one that says which it wants.
131+`Str.cut` splits a string at the first place a separator is: what comes before it, what comes after, and whether it was there at all. `Str.field` gives the first word, past any spaces, and the rest. Neither copies anything: every part is a slice of the string it came from, so taking a line or a file apart costs no memory.
126132
127-```raz Runes run
128-module Runes;
133+```raz Parts run
134+module Parts;
129135 import Out, Str;
130136
131-(* the characters of s, not its bytes *)
132-proc chars(s: []U8): INT;
133-var i, n, size: INT;
137+const Text = "name = raz\nkind = language\nyear = 2026\n";
138+
139+proc main*;
140+var line, rest, key, val, w: []U8; more, ok: BOOL;
134141 begin
135- i := 0;
136- n := 0;
137- while i < LEN(s) do
138- _, size := Str.decode(s[i..LEN(s)]);
139- INC(i, size);
140- INC(n);
142+ (* line by line, then each line at its = *)
143+ line, rest, more := Str.cut(Text, "\n");
144+ while more do
145+ key, val, ok := Str.cut(line, "=");
146+ if ok then
147+ Out.str(Str.trim(key)); Out.str(" is "); Out.str(Str.trim(val)); Out.ln;
148+ end;
149+ line, rest, more := Str.cut(rest, "\n");
141150 end;
142- return n;
151+
152+ (* word by word *)
153+ w, rest := Str.field(" the quick brown fox ");
154+ while LEN(w) > 0 do
155+ Out.str("<"); Out.str(w); Out.str(">");
156+ w, rest := Str.field(rest);
157+ end;
158+ Out.ln;
143159 end;
144160
161+end Parts.
162+```
163+
164+When `Str.cut` finds no separator it gives the whole string, an empty one and `false`, so the loop above ends after the last line that has a line feed. Building a string goes the other way, in a `Buf`: `Str.join` adds parts with a separator between them, and `Str.replace` adds a string with every match of one text replaced by another (lesson 9 shows `Buf`).
165+
166+## Raw strings
167+
168+A string between backquotes is raw: its bytes are the text as it stands, with no escapes, so a backslash or a double quote is itself, and it may run over lines. When the opening backquote ends its line and the closing one has only spaces and tabs before it, those blanks come off the start of every line between, and the text keeps the indent of the code it sits in. Each line ends in a line feed, the last one too.
169+
170+```raz Raw run
171+module Raw;
172+import Out;
173+
174+const Path = `C:\Users\raz\"notes".txt`;
175+
176+proc usage;
177+begin
178+ Out.str(`
179+ usage: tool [-v] file ...
180+ -v say what is done
181+ file read this, not standard input
182+ `);
183+end;
184+
145185 proc main*;
146-var s: []U8; c: I32; size: INT; bytes: [4]U8; k: INT;
147186 begin
187+ Out.str(Path); Out.ln;
188+ usage;
189+ Out.str(`a raw string on one line, \n and all`); Out.ln;
190+end;
191+
192+end Raw.
193+```
194+
195+A line of an indented raw string that doesn't start with the closing line's blanks is an error, so a slip in the indent is caught where it is made, not printed. A raw string can't hold a backquote; join one in with `+` and an ordinary string that holds it.
196+
197+## UTF-8
198+
199+A character is an `I32`, its code point. A string stays bytes; UTF-8 is how `Str` reads them. `Str.next` walks a string a character at a time, giving each one and where the next starts, -1 at the end. `Str.decode` reads the first character of a string and says how many bytes it took, `Str.decodeLast` the last, and `Str.encode` goes the other way. `Str.chars` counts characters and `Str.valid` says whether a string is UTF-8 at all; a byte that doesn't start a character rightly reads as FFFDH, the character that stands for a wrong one. Byte length and character count are different things, and the program is the one that says which it wants.
200+
201+```raz Runes run
202+module Runes;
203+import Out, Str;
204+
205+proc main*;
206+var s: []U8; c: I32; i, size: INT; bytes: [4]U8; k: INT;
207+begin
148208 s := "caf\u{E9} \u{3BB}";
149209 Out.int(LEN(s)); Out.str(" bytes, ");
150- Out.int(chars(s)); Out.str(" characters\n");
151- c, size := Str.decode(s[3..LEN(s)]);
152- Out.int(I64(c)); Out.str(" took "); Out.int(size); Out.str(" bytes\n");
210+ Out.int(Str.chars(s)); Out.str(" characters\n");
211+
212+ (* each character, as its code point *)
213+ c, i := Str.next(s, 0);
214+ while i >= 0 do
215+ Out.int(I64(c)); Out.str(" ");
216+ c, i := Str.next(s, i);
217+ end;
218+ Out.ln;
219+
220+ c, size := Str.decodeLast(s);
221+ Out.int(I64(c)); Out.str(" is last, in "); Out.int(size); Out.str(" bytes\n");
153222 bytes, k := Str.encode(955);
154223 Out.str(bytes[0..k]); Out.ln;
224+ if not Str.valid(s[0..4]) then Out.str("cut in the middle of a character\n"); end;
155225 end;
156226
157227 end Runes.
158228 ```
229+
230+`Str` knows UTF-8 and no more of Unicode: its case is ASCII's, and it doesn't say how wide a character is on a terminal or which spellings of a text are the same. Those need tables bigger than the rest of the library.
159231
160232 ## Loops over lengths
161233

site/content/tour/08-variants.txt (history) modified +40 -0

@@ -163,3 +163,43 @@
163163
164164 end Classify.
165165 ```
166+
167+## Matching strings
168+
169+On a string, `match` takes string constants, several to an arm if need be, and compares them as `=` does. It too must have an `| else:`. It is how a program reads a command, an option or a keyword without a chain of `elsif`s.
170+
171+```raz Commands run
172+module Commands;
173+import Out;
174+
175+type Op = (none, add, sub, show);
176+
177+proc op(word: []U8): Op;
178+begin
179+ match word of
180+ | "add", "plus", "+": return add;
181+ | "sub", "minus", "-": return sub;
182+ | "show": return show;
183+ | else: return none;
184+ end;
185+end;
186+
187+proc main*;
188+var total: INT; words: [6][]U8; i: INT;
189+begin
190+ words := ["add", "plus", "sub", "show", "times", "-"];
191+ for i := 0 to 5 do
192+ match op(words[i]) of
193+ | add: INC(total);
194+ | sub: DEC(total);
195+ | show: Out.int(total); Out.ln;
196+ | none: Out.str(words[i]); Out.str("?\n");
197+ end;
198+ end;
199+ Out.int(total); Out.ln;
200+end;
201+
202+end Commands.
203+```
204+
205+Two labels that are the same string are an error, as two arms for one case are.

site/content/tour/09-memory.txt (history) modified +9 -1

@@ -95,7 +95,7 @@
9595
9696 ```raz Build run
9797 module Build;
98-import Out, Buf, Heap;
98+import Out, Buf, Heap, Str;
9999
100100 proc main*;
101101 var b: Buf.Buf; i: INT;
@@ -109,10 +109,18 @@
109109 end;
110110 Out.str(Buf.bytes(ADR(b))); Out.ln;
111111 Out.int(b.len); Out.str(" bytes\n");
112+ Buf.reset(ADR(b));
113+ Str.join(ADR(b), ["red", "green", "blue"], ", ");
114+ Out.str(Buf.bytes(ADR(b))); Out.ln;
115+ Buf.reset(ADR(b));
116+ Str.replace(ADR(b), "a-b-c", "-", " and ");
117+ Out.str(Buf.bytes(ADR(b))); Out.ln;
112118 end;
113119
114120 end Build.
115121 ```
122+
123+`Str.join` and `Str.replace` build into a `Buf` too: the parts with a separator between them, or a string with one text replaced by another wherever it is.
116124
117125 ## Pages
118126

src/Raz.raz (history) modified +1 -1

@@ -29,7 +29,7 @@
2929 import Sys, Out, Version, Files, Fmt, Diag, Scan, Sym, Chunk, X64, Gen, Parse, Link, Elf;
3030
3131 const
32- Report = "2026-10.24"; (* the version of doc/raz.md it follows *)
32+ Report = "2026-10.25"; (* the version of doc/raz.md it follows *)
3333 MemfdCreate = 319; (* the system call *)
3434 MfdCloexec = 1; (* an ELF still executes: the kernel opens it first *)
3535 Execve = 59;

src/check.sh modified +2 -1

@@ -10,7 +10,8 @@
1010 # so are those whose message says what match takes.
1111 newer="conform/run/RawStrings.raz conform/err/ScanRawOpen.raz conform/err/ScanRawIndent.raz
1212 conform/run/MatchStr.raz conform/err/MatchStrTwice.raz conform/err/MatchStrNoElse.raz
13- conform/err/MatchStrVar.raz conform/err/MatchReal.raz conform/err/AtMatch.raz"
13+ conform/err/MatchStrVar.raz conform/err/MatchReal.raz conform/err/AtMatch.raz
14+ examples/Sh.raz examples/Settings.raz"
1415 newer() {
1516 for g in $newer; do [ $g = $1 ] && return 0; done
1617 return 1

test/editors/Colours.expect (history) modified +11 -5

@@ -5,8 +5,14 @@
55 3 39 string
66 3 49 string
77 3 53 string
8-4 8 type
9-4 17 type
10-6 5 builtin
11-6 19 constant
12-5 1 keyword
8+4 1 keyword
9+4 16 string
10+4 17 string
11+5 14 string
12+6 1 string
13+6 5 string
14+7 8 type
15+7 17 type
16+9 5 builtin
17+9 19 constant
18+8 1 keyword

test/editors/Colours.raz (history) modified +3 -0

@@ -1,6 +1,9 @@
11 (* outer (* nested *) still comment *)
22 module Colours;
33 const big = 0FFH; small = 2.5E-3; q = '\''; s = "a\"b";
4+const raw = `C:\`;
5+ lines = `begin
6+end (* x *)`;
47 var x: I64; ok: BOOL;
58 begin
69 INC(x); ok := true;

test/editors/colours.vim (history) modified +1 -1

@@ -1,6 +1,6 @@
11 " Checks each token of Colours.expect has the colour group it should.
22 let s:kinds = {'razComment': 'comment', 'razKeyword': 'keyword', 'razNumber': 'number',
3- \ 'razString': 'string', 'razChar': 'string', 'razType': 'type',
3+ \ 'razString': 'string', 'razRawString': 'string', 'razChar': 'string', 'razType': 'type',
44 \ 'razBuiltin': 'builtin', 'razConstant': 'constant'}
55 for s:want in readfile('test/editors/Colours.expect')
66 let [s:l, s:c, s:k] = split(s:want)

tools/Doc.raz (history) modified +10 -18

@@ -306,20 +306,9 @@
306306 end;
307307 end;
308308
309-(* line, without the spaces at its ends *)
310-proc trim(line: []U8): []U8;
311-var i, j: INT;
312-begin
313- i := 0;
314- j := LEN(line);
315- while (i < j) and Scan.isSpace(line[i]) do INC(i); end;
316- while (j > i) and Scan.isSpace(line[j - 1]) do DEC(j); end;
317- return line[i..j];
318-end;
319-
320309 (* line, from the report or a manual page's literal block, added to b
321- as the program has it: in a page, \e is a backslash and \& is
322- nothing. *)
310+ as the program has it: in a page, \e is a backslash, \(ga a
311+ backquote and \& nothing. *)
323312 proc addLine(b: ^Buf.Buf; line: []U8; page: BOOL);
324313 var i: INT;
325314 begin
@@ -328,6 +317,9 @@
328317 if page and (line[i] = '\\') and (i + 1 < LEN(line)) and (line[i + 1] = 'e') then
329318 Buf.add(b, '\\');
330319 INC(i);
320+ elsif page and Str.hasPrefix(line[i..LEN(line)], "\\(ga") then
321+ Buf.add(b, '`');
322+ INC(i, 3);
331323 elsif page and (line[i] = '\\') and (i + 1 < LEN(line)) and (line[i + 1] = '&') then
332324 INC(i);
333325 else Buf.add(b, line[i]);
@@ -368,7 +360,7 @@
368360 k := i;
369361 while (k < LEN(s)) and (s[k] # 10) do INC(k); end;
370362 line := s[i..k];
371- fence := not page and (trim(line) = "```");
363+ fence := not page and (Str.trim(line) = "```");
372364 if inBlock and (fence or page and (line = ".Ed")) then
373365 if whole and Str.hasPrefix(first, "module ") and Str.hasPrefix(last, "end ") then
374366 name := first[7..LEN(first)];
@@ -391,10 +383,10 @@
391383 whole := true;
392384 elsif inBlock then
393385 addLine(ADR(prog), line, page);
394- if trim(line) = "..." then whole := false; end;
395- if LEN(trim(line)) > 0 then
396- if LEN(first) = 0 then first := trim(line); end;
397- last := trim(line);
386+ if Str.trim(line) = "..." then whole := false; end;
387+ if LEN(Str.trim(line)) > 0 then
388+ if LEN(first) = 0 then first := Str.trim(line); end;
389+ last := Str.trim(line);
398390 end;
399391 end;
400392 i := k + 1;