From 639f4eaae9869c727135af22112018c78ec55113 Mon Sep 17 00:00:00 2001 From: Luis <42945842+ldiaz94@users.noreply.github.com> Date: Wed, 14 Oct 2026 22:07:12 +0000 Subject: [PATCH] Report 2026-10.25: indented raw strings, Str.next A raw string whose opening backquote ends its line and whose closing one has only blanks before it is indented: those blanks come off the start of every line, and a line without them is an error. Str.next walks a string a character at a time. --- diff --git a/doc/raz-lib.md b/doc/raz-lib.md index 5d88524..e30e1e1 100644 --- a/doc/raz-lib.md +++ b/doc/raz-lib.md @@ -423,6 +423,7 @@ proc encode*(c: I32): ([4]U8, INT); (* c in UTF-8: its bytes, and how many *) proc decode*(s: []U8): (I32, INT); (* the character s starts with, and its length in bytes *) proc decodeLast*(s: []U8): (I32, INT); (* the character s ends with, and its length in bytes *) +proc next*(s: []U8; i: INT): (I32, INT); (* the character at i, and where the next starts; -1 at the end *) proc valid*(s: []U8): BOOL; (* s is UTF-8, every character rightly spelled *) proc chars*(s: []U8): INT; (* the characters in s, as decode reads them *) proc toInt*(s: []U8): (I64, BOOL); (* s, in decimal; false if it isn't a number an I64 holds *) @@ -516,15 +517,16 @@ 10FFFFH or one spelled in more bytes than it needs. `decodeLast` reads the last character in the same way, to walk a string backwards. `valid` says that `decode` finds no such byte in `s`, and `chars` -counts the characters, each such byte one. A string is walked a -character at a time so: +counts the characters, each such byte one. `next` walks a string a +character at a time, as `decode` reads them: from 0, it gives the +character at `i` and where the one after it starts, and 0 and -1 when +`i` is at the end, or past it: ``` -i := 0; -while i < LEN(s) do - c, n := Str.decode(s[i..LEN(s)]); - ... - i := i + n; +c, i := Str.next(s, 0); +while i >= 0 do + ... (* c is a character of s *) + c, i := Str.next(s, i); end; ``` diff --git a/doc/raz.md b/doc/raz.md index cdaa30f..5848fc9 100644 --- a/doc/raz.md +++ b/doc/raz.md @@ -21,8 +21,8 @@ procedures written for 2026-10.11. 2026-10.20 is a third, for `try` (section 7.8); it breaks a program that has a name `try`. 2026-10.25 is a fourth, for strings: raw strings, which may run over lines -(section 2), and `match` on a string (section 7.4); it breaks no -program. +and may be indented with the code around them (section 2), and +`match` on a string (section 7.4); it breaks no program. The compiler follows version 2026-10.24 until it has what 2026-10.25 adds. @@ -120,19 +120,31 @@ backquotes: its bytes are the text between them as it stands, with no escapes, so `\` and `"` are themselves. A raw string may run over lines, and each line break in it is a line feed, part of the string; a -carriage return in it is left out, and so is a line break right after -the opening backquote, so that a long text may start on a line of its -own: +carriage return in it is left out. + +A raw string whose opening backquote ends its line, and whose closing +backquote has only blanks (spaces and tabs) before it on its line, is +indented: the text is its lines between those two, each without the +closing line's blanks at its start, and each ending in a line feed. So +a long text may stand at the indentation of the code around it: ``` -const Usage = ` -usage: tool [-v] file ... - -v say what is done -`; +proc usage; +begin + Out.str(` + usage: tool [-v] file ... + -v say what is done + `); +end; ``` -is `"usage: tool [-v] file ...\n -v say what is done\n"`. A raw -string can't hold a backquote; a text that needs one joins it with +writes `"usage: tool [-v] file ...\n -v say what is done\n"`. Each +line of an indented raw string must start with the closing line's +blanks, the same spaces and tabs in the same order, or it is an error; +a line holding only blanks is an empty line of the text. A raw string +that isn't indented is the text between its backquotes as it stands. + +A raw string can't hold a backquote; a text that needs one joins it with `+`, as ``"`"``. Everywhere else a raw string is a string, as one in double quotes is. diff --git a/doc/report-history.md b/doc/report-history.md index f91dd90..ea80cec 100644 --- a/doc/report-history.md +++ b/doc/report-history.md @@ -135,9 +135,10 @@ `memFile` and `mapFile`. `Thread` works in a program that uses C, and no longer says `link static` (volume 2). - **2026-10.25.** A thaw, for strings. A raw string, between - backquotes, has no escapes and may run over lines (section 2 and - appendix B); `match` takes a string, with string constants as labels + backquotes, has no escapes and may run over lines, indented with + the code around it (section 2 and appendix B); `match` takes a string, with string constants as labels (section 7.4). It breaks no program. `Str` gains `eqFold`, `findLast`, `hasSuffix`, `trim`, `trimLeft`, `trimRight`, `cut`, - `field`, `lower`, `upper`, `join`, `replace`, `decodeLast`, `valid`, - `chars`, `toHex` and `fromInt`; `Math` gains `toReal` (volume 2). + `field`, `lower`, `upper`, `join`, `replace`, `decodeLast`, + `next`, `valid`, `chars`, `toHex` and `fromInt`; `Math` gains + `toReal` (volume 2).