A name like FFFDH, undeclared, gets help: write 0FFFDH A hexadecimal number starts with a digit; a name that would be one but for that is told so (hexLike in notDeclared). Nothing a program means changes. Met in rrem, writing U+FFFD.
| @@ -582,30 +582,3 @@ | ||
| 582 | 582 | spelling to use instead (`x* )` or a word). |
| 583 | 583 | |
| 584 | 584 | Met in rrem's parser, documenting `(?>x*)`. |
| 585 | - | |
| 586 | -## A hint for a hexadecimal name | |
| 587 | - | |
| 588 | -`FFFDH`, meant as a number, is an identifier, and the error is "FFFDH | |
| 589 | -isn't declared". The report is right (a hexadecimal number starts | |
| 590 | -with a digit, 2), but the message gives no clue. The proposal: when an | |
| 591 | -undeclared name is all hexadecimal digits and ends in `H`, the error | |
| 592 | -adds "a hexadecimal number starts with a digit: 0FFFDH". Nothing a | |
| 593 | -program means changes. | |
| 594 | - | |
| 595 | -Met in rrem's parser, writing U+FFFD. | |
| 596 | - | |
| 597 | -## Code fences that say they are raz | |
| 598 | - | |
| 599 | -The report, the library's book and the README fence their code with | |
| 600 | -bare lines of ``` (about 200 fences), so nothing that renders them can | |
| 601 | -tell raz from a shell session, a program's output or a grammar. rless | |
| 602 | -colours a fence marked `raz`, ```` ```raz ````, as the editors colour | |
| 603 | -raz; GitHub would too, given a grammar. A bare fence is one colour. | |
| 604 | - | |
| 605 | -The proposal: a fence around raz code says `raz`; one around anything | |
| 606 | -else stays bare. `tools/Doc` finds the report's examples by a fence | |
| 607 | -line that is exactly ```, so it takes ```` ```raz ```` as well, and | |
| 608 | -finds the same examples as before. Nothing in the language or the | |
| 609 | -library changes; the documents read the same as text. | |
| 610 | - | |
| 611 | -Met in rless, whose pager shows the report. |
| @@ -1501,7 +1501,8 @@ | ||
| 1501 | 1501 | points open: `giveUp` with none left ends the compile. A routine that |
| 1502 | 1502 | can't fail has no `ERROR` result (`declarations`, `declaration`). A name not declared is reported by |
| 1503 | 1503 | `notDeclared`, with what it may have meant: a module to import |
| 1504 | -(`moduleFile`) or a name spelled alike (`didYouMean`). It is then | |
| 1504 | +(`moduleFile`), a hexadecimal number without its first digit | |
| 1505 | +(`hexLike`), or a name spelled alike (`didYouMean`). It is then | |
| 1505 | 1506 | declared where it is used, with the type `tPoison` (`poison`), as are |
| 1506 | 1507 | the names of a declaration that had an error; a construct that uses |
| 1507 | 1508 | poison sets `Diag.quiet` (by `Diag.setQuiet`, since a variable |
| @@ -423,6 +423,18 @@ | ||
| 423 | 423 | return p[0..LEN(s)]; |
| 424 | 424 | end; |
| 425 | 425 | |
| 426 | +(* Whether s is a hexadecimal number but for the digit it must start | |
| 427 | + with, as FFFDH is: capitals A to F and digits, then H *) | |
| 428 | +proc hexLike(s: []U8): BOOL; | |
| 429 | +var i: INT; | |
| 430 | +begin | |
| 431 | + if (LEN(s) < 2) or (s[LEN(s) - 1] # 'H') then return false; end; | |
| 432 | + for i := 0 to LEN(s) - 2 do | |
| 433 | + if (Str.hexVal(s[i]) < 0) or (s[i] >= 'a') then return false; end; | |
| 434 | + end; | |
| 435 | + return true; | |
| 436 | +end; | |
| 437 | + | |
| 426 | 438 | (* Reports name n at p as not declared, with what it may have meant *) |
| 427 | 439 | proc notDeclared(p: Diag.Pos; n: INT); |
| 428 | 440 | var found: BOOL; low: []U8; |
| @@ -433,6 +445,7 @@ | ||
| 433 | 445 | if found then Diag.help(say2("{} is a module: import {}", nameOf(n), nameOf(n))); |
| 434 | 446 | elsif (nameOf(n) = "elif") or (nameOf(n) = "elseif") then Diag.help("raz writes elsif"); |
| 435 | 447 | elsif Scan.reserved(internName(low)) then Diag.help(say1("a reserved word is written in lower case: {}", low)); |
| 448 | + elsif hexLike(nameOf(n)) then Diag.help(say1("a hexadecimal number starts with a digit: 0{}", nameOf(n))); | |
| 436 | 449 | else didYouMean(Sym.closest(n, -1)); |
| 437 | 450 | end; |
| 438 | 451 | end; |
| @@ -0,0 +1,5 @@ | ||
| 1 | +test/err/DeclHexName.raz:6:13: error: FFFDH isn't declared | |
| 2 | + 6 | Out.int(FFFDH); | |
| 3 | + | ^^^^^ | |
| 4 | +help: a hexadecimal number starts with a digit: 0FFFDH | |
| 5 | +raz: 1 error |
| @@ -0,0 +1,8 @@ | ||
| 1 | +module DeclHexName; | |
| 2 | +(* FFFDH, meant as a number, is a name; the help says how to write it *) | |
| 3 | +import Out; | |
| 4 | +proc main*; | |
| 5 | +begin | |
| 6 | + Out.int(FFFDH); | |
| 7 | +end; | |
| 8 | +end DeclHexName. |