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.
| @@ -423,6 +423,7 @@ | ||
| 423 | 423 | proc encode*(c: I32): ([4]U8, INT); (* c in UTF-8: its bytes, and how many *) |
| 424 | 424 | proc decode*(s: []U8): (I32, INT); (* the character s starts with, and its length in bytes *) |
| 425 | 425 | proc decodeLast*(s: []U8): (I32, INT); (* the character s ends with, and its length in bytes *) |
| 426 | +proc next*(s: []U8; i: INT): (I32, INT); (* the character at i, and where the next starts; -1 at the end *) | |
| 426 | 427 | proc valid*(s: []U8): BOOL; (* s is UTF-8, every character rightly spelled *) |
| 427 | 428 | proc chars*(s: []U8): INT; (* the characters in s, as decode reads them *) |
| 428 | 429 | proc toInt*(s: []U8): (I64, BOOL); (* s, in decimal; false if it isn't a number an I64 holds *) |
| @@ -516,15 +517,16 @@ | ||
| 516 | 517 | 10FFFFH or one spelled in more bytes than it needs. `decodeLast` reads |
| 517 | 518 | the last character in the same way, to walk a string backwards. |
| 518 | 519 | `valid` says that `decode` finds no such byte in `s`, and `chars` |
| 519 | -counts the characters, each such byte one. A string is walked a | |
| 520 | -character at a time so: | |
| 520 | +counts the characters, each such byte one. `next` walks a string a | |
| 521 | +character at a time, as `decode` reads them: from 0, it gives the | |
| 522 | +character at `i` and where the one after it starts, and 0 and -1 when | |
| 523 | +`i` is at the end, or past it: | |
| 521 | 524 | |
| 522 | 525 | ``` |
| 523 | -i := 0; | |
| 524 | -while i < LEN(s) do | |
| 525 | - c, n := Str.decode(s[i..LEN(s)]); | |
| 526 | - ... | |
| 527 | - i := i + n; | |
| 526 | +c, i := Str.next(s, 0); | |
| 527 | +while i >= 0 do | |
| 528 | + ... (* c is a character of s *) | |
| 529 | + c, i := Str.next(s, i); | |
| 528 | 530 | end; |
| 529 | 531 | ``` |
| 530 | 532 |
| @@ -21,8 +21,8 @@ | ||
| 21 | 21 | procedures written for 2026-10.11. 2026-10.20 is a third, for `try` |
| 22 | 22 | (section 7.8); it breaks a program that has a name `try`. 2026-10.25 |
| 23 | 23 | is a fourth, for strings: raw strings, which may run over lines |
| 24 | -(section 2), and `match` on a string (section 7.4); it breaks no | |
| 25 | -program. | |
| 24 | +and may be indented with the code around them (section 2), and | |
| 25 | +`match` on a string (section 7.4); it breaks no program. | |
| 26 | 26 | |
| 27 | 27 | The compiler follows version 2026-10.24 until it has what 2026-10.25 |
| 28 | 28 | adds. |
| @@ -120,19 +120,31 @@ | ||
| 120 | 120 | backquotes: its bytes are the text between them as it stands, with no |
| 121 | 121 | escapes, so `\` and `"` are themselves. A raw string may run over |
| 122 | 122 | lines, and each line break in it is a line feed, part of the string; a |
| 123 | -carriage return in it is left out, and so is a line break right after | |
| 124 | -the opening backquote, so that a long text may start on a line of its | |
| 125 | -own: | |
| 123 | +carriage return in it is left out. | |
| 124 | + | |
| 125 | +A raw string whose opening backquote ends its line, and whose closing | |
| 126 | +backquote has only blanks (spaces and tabs) before it on its line, is | |
| 127 | +indented: the text is its lines between those two, each without the | |
| 128 | +closing line's blanks at its start, and each ending in a line feed. So | |
| 129 | +a long text may stand at the indentation of the code around it: | |
| 126 | 130 | |
| 127 | 131 | ``` |
| 128 | -const Usage = ` | |
| 129 | -usage: tool [-v] file ... | |
| 130 | - -v say what is done | |
| 131 | -`; | |
| 132 | +proc usage; | |
| 133 | +begin | |
| 134 | + Out.str(` | |
| 135 | + usage: tool [-v] file ... | |
| 136 | + -v say what is done | |
| 137 | + `); | |
| 138 | +end; | |
| 132 | 139 | ``` |
| 133 | 140 | |
| 134 | -is `"usage: tool [-v] file ...\n -v say what is done\n"`. A raw | |
| 135 | -string can't hold a backquote; a text that needs one joins it with | |
| 141 | +writes `"usage: tool [-v] file ...\n -v say what is done\n"`. Each | |
| 142 | +line of an indented raw string must start with the closing line's | |
| 143 | +blanks, the same spaces and tabs in the same order, or it is an error; | |
| 144 | +a line holding only blanks is an empty line of the text. A raw string | |
| 145 | +that isn't indented is the text between its backquotes as it stands. | |
| 146 | + | |
| 147 | +A raw string can't hold a backquote; a text that needs one joins it with | |
| 136 | 148 | `+`, as ``"`"``. Everywhere else a raw string is a string, as one in |
| 137 | 149 | double quotes is. |
| 138 | 150 |
| @@ -135,9 +135,10 @@ | ||
| 135 | 135 | `memFile` and `mapFile`. `Thread` works in a program that uses C, |
| 136 | 136 | and no longer says `link static` (volume 2). |
| 137 | 137 | - **2026-10.25.** A thaw, for strings. A raw string, between |
| 138 | - backquotes, has no escapes and may run over lines (section 2 and | |
| 139 | - appendix B); `match` takes a string, with string constants as labels | |
| 138 | + backquotes, has no escapes and may run over lines, indented with | |
| 139 | + the code around it (section 2 and appendix B); `match` takes a string, with string constants as labels | |
| 140 | 140 | (section 7.4). It breaks no program. `Str` gains `eqFold`, |
| 141 | 141 | `findLast`, `hasSuffix`, `trim`, `trimLeft`, `trimRight`, `cut`, |
| 142 | - `field`, `lower`, `upper`, `join`, `replace`, `decodeLast`, `valid`, | |
| 143 | - `chars`, `toHex` and `fromInt`; `Math` gains `toReal` (volume 2). | |
| 142 | + `field`, `lower`, `upper`, `join`, `replace`, `decodeLast`, | |
| 143 | + `next`, `valid`, `chars`, `toHex` and `fromInt`; `Math` gains | |
| 144 | + `toReal` (volume 2). |