raz / commit f1077724

commit
f107772465a016f78135588f0160471f567474a6
author
Luis <42945842+ldiaz94@users.noreply.github.com>
date
parent
a1870932
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.

patch · log

5 files changed, +28 -28

PROPOSALS.md modified +0 -27

@@ -582,30 +582,3 @@
582582 spelling to use instead (`x* )` or a word).
583583
584584 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.

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

@@ -1501,7 +1501,8 @@
15011501 points open: `giveUp` with none left ends the compile. A routine that
15021502 can't fail has no `ERROR` result (`declarations`, `declaration`). A name not declared is reported by
15031503 `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
15051506 declared where it is used, with the type `tPoison` (`poison`), as are
15061507 the names of a declaration that had an error; a construct that uses
15071508 poison sets `Diag.quiet` (by `Diag.setQuiet`, since a variable

src/Parse.raz (history) modified +13 -0

@@ -423,6 +423,18 @@
423423 return p[0..LEN(s)];
424424 end;
425425
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+
426438 (* Reports name n at p as not declared, with what it may have meant *)
427439 proc notDeclared(p: Diag.Pos; n: INT);
428440 var found: BOOL; low: []U8;
@@ -433,6 +445,7 @@
433445 if found then Diag.help(say2("{} is a module: import {}", nameOf(n), nameOf(n)));
434446 elsif (nameOf(n) = "elif") or (nameOf(n) = "elseif") then Diag.help("raz writes elsif");
435447 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)));
436449 else didYouMean(Sym.closest(n, -1));
437450 end;
438451 end;

test/err/DeclHexName.err (history) added +5 -0

@@ -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

test/err/DeclHexName.raz (history) added +8 -0

@@ -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.