From f107772465a016f78135588f0160471f567474a6 Mon Sep 17 00:00:00 2001 From: Luis <42945842+ldiaz94@users.noreply.github.com> Date: Fri, 16 Oct 2026 12:17:50 +0100 Subject: [PATCH] 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. --- diff --git a/PROPOSALS.md b/PROPOSALS.md index eac5926..6067fa3 100644 --- a/PROPOSALS.md +++ b/PROPOSALS.md @@ -582,30 +582,3 @@ spelling to use instead (`x* )` or a word). Met in rrem's parser, documenting `(?>x*)`. - -## A hint for a hexadecimal name - -`FFFDH`, meant as a number, is an identifier, and the error is "FFFDH -isn't declared". The report is right (a hexadecimal number starts -with a digit, 2), but the message gives no clue. The proposal: when an -undeclared name is all hexadecimal digits and ends in `H`, the error -adds "a hexadecimal number starts with a digit: 0FFFDH". Nothing a -program means changes. - -Met in rrem's parser, writing U+FFFD. - -## Code fences that say they are raz - -The report, the library's book and the README fence their code with -bare lines of ``` (about 200 fences), so nothing that renders them can -tell raz from a shell session, a program's output or a grammar. rless -colours a fence marked `raz`, ```` ```raz ````, as the editors colour -raz; GitHub would too, given a grammar. A bare fence is one colour. - -The proposal: a fence around raz code says `raz`; one around anything -else stays bare. `tools/Doc` finds the report's examples by a fence -line that is exactly ```, so it takes ```` ```raz ```` as well, and -finds the same examples as before. Nothing in the language or the -library changes; the documents read the same as text. - -Met in rless, whose pager shows the report. diff --git a/doc/compiler.md b/doc/compiler.md index 97fee8b..2e5a5a2 100644 --- a/doc/compiler.md +++ b/doc/compiler.md @@ -1501,7 +1501,8 @@ points open: `giveUp` with none left ends the compile. A routine that can't fail has no `ERROR` result (`declarations`, `declaration`). A name not declared is reported by `notDeclared`, with what it may have meant: a module to import -(`moduleFile`) or a name spelled alike (`didYouMean`). It is then +(`moduleFile`), a hexadecimal number without its first digit +(`hexLike`), or a name spelled alike (`didYouMean`). It is then declared where it is used, with the type `tPoison` (`poison`), as are the names of a declaration that had an error; a construct that uses poison sets `Diag.quiet` (by `Diag.setQuiet`, since a variable diff --git a/src/Parse.raz b/src/Parse.raz index 0411d92..d2c63e5 100644 --- a/src/Parse.raz +++ b/src/Parse.raz @@ -423,6 +423,18 @@ return p[0..LEN(s)]; end; +(* Whether s is a hexadecimal number but for the digit it must start + with, as FFFDH is: capitals A to F and digits, then H *) +proc hexLike(s: []U8): BOOL; +var i: INT; +begin + if (LEN(s) < 2) or (s[LEN(s) - 1] # 'H') then return false; end; + for i := 0 to LEN(s) - 2 do + if (Str.hexVal(s[i]) < 0) or (s[i] >= 'a') then return false; end; + end; + return true; +end; + (* Reports name n at p as not declared, with what it may have meant *) proc notDeclared(p: Diag.Pos; n: INT); var found: BOOL; low: []U8; @@ -433,6 +445,7 @@ if found then Diag.help(say2("{} is a module: import {}", nameOf(n), nameOf(n))); elsif (nameOf(n) = "elif") or (nameOf(n) = "elseif") then Diag.help("raz writes elsif"); elsif Scan.reserved(internName(low)) then Diag.help(say1("a reserved word is written in lower case: {}", low)); + elsif hexLike(nameOf(n)) then Diag.help(say1("a hexadecimal number starts with a digit: 0{}", nameOf(n))); else didYouMean(Sym.closest(n, -1)); end; end; diff --git a/test/err/DeclHexName.err b/test/err/DeclHexName.err new file mode 100644 index 0000000..2d51680 --- /dev/null +++ b/test/err/DeclHexName.err @@ -0,0 +1,5 @@ +test/err/DeclHexName.raz:6:13: error: FFFDH isn't declared + 6 | Out.int(FFFDH); + | ^^^^^ +help: a hexadecimal number starts with a digit: 0FFFDH +raz: 1 error diff --git a/test/err/DeclHexName.raz b/test/err/DeclHexName.raz new file mode 100644 index 0000000..5661dc7 --- /dev/null +++ b/test/err/DeclHexName.raz @@ -0,0 +1,8 @@ +module DeclHexName; +(* FFFDH, meant as a number, is a name; the help says how to write it *) +import Out; +proc main*; +begin + Out.int(FFFDH); +end; +end DeclHexName.