raz / commit 09da0cd0

commit
09da0cd0eae66f1003043598f70aa88909793c1c
author
Luis <42945842+ldiaz94@users.noreply.github.com>
date
parent
23f6bd0d
PROPOSALS: eight met in rrem and rwalk

Errors told at the wrong token, Vec.tryPush/tryAdd, Fmt.eprint, Str
character tests, Sys.errorText, Sys.setEnv, Str.findFrom, a hint for
FFFDH.

patch · log

1 file changed, +139 -0

PROPOSALS.md modified +139 -0

@@ -701,3 +701,142 @@
701701
702702 Met in concha's `Ccore`, in `bufVal` and `listVal`, and in `Sys` over
703703 C, before each call that takes a buffer.
704+
705+## An error told where the wrong token is
706+
707+A comment that quotes a regular expression, `(* matches (?>x*) *)`,
708+ends at the `*)` inside `x*)`, and the rest of it is read as code.
709+The compiler is right to refuse what follows; but it told the error
710+at the start of an earlier declaration, 40 lines from the token that
711+was wrong, and the comment that caused it was hard to find.
712+
713+The proposal: an error is told at the token where the parse failed,
714+as most already are; where the parser reports at the start of a
715+declaration instead, it reports the token as well. A comment that has
716+just closed on a line with more text after it could add a hint:
717+"a comment ended here". Nothing a program means changes.
718+
719+A comment can't quote `*)` at all. That is the report's rule, and
720+Oberon's, and stays; the report could say it in a line, with the
721+spelling to use instead (`x* )` or a word).
722+
723+Met in rrem's parser, documenting `(?>x*)`.
724+
725+## Adding to a `Vec` without stopping the program
726+
727+`Vec.push` and `Vec.add` stop the program when memory runs out. A
728+library that returns an error such as `NoRoom` instead must call
729+`Vec.room(v, 1)` before each one, and the two are apart, so the check
730+is easy to leave out: rrem's parser left it out once, and a pattern
731+too big for memory would have stopped the program, not returned the
732+error.
733+
734+The proposal, in `Vec`:
735+
736+```
737+proc tryPush*(v: ^Vec; x: T): BOOL; (* x added at the end; false, and v as it was, if there is no room *)
738+proc tryAdd*(v: ^Vec): (^T, BOOL); (* a new element at the end, to fill; false if there is no room *)
739+```
740+
741+They are `room` and `push` (or `add`) in one call. It breaks no
742+program, so it could come with any release.
743+
744+Met in rrem's parser, which builds its tree in a `Vec`.
745+
746+## A line to standard error
747+
748+A message to standard error takes a `Buf`, `Fmt.write` into it,
749+`Out.flush` (so what was printed before comes first) and `Sys.write`
750+to `Sys.stderr`. Every tool writes its errors so, and each writes the
751+same few lines.
752+
753+The proposal, in `Fmt`, beside `print`:
754+
755+```
756+proc eprint*(f: []U8; args: []Arg); (* as print, to standard error, after Out is flushed *)
757+```
758+
759+It breaks no program.
760+
761+Met in rwalk's `Rwfiles` and rrem's `rre`.
762+
763+## Character tests in `Str`
764+
765+`Str` has `lower` and `upper`, ASCII, and inside it the private
766+`small` and `space`. Every parser writes its own `isDigit`,
767+`isLetter`, `isSpace`, `isPunct` and `hexVal` beside them.
768+
769+The proposal, in `Str`, all ASCII as `lower` and `upper` are:
770+
771+```
772+proc isDigit*(c: U8): BOOL; (* 0 to 9 *)
773+proc isLetter*(c: U8): BOOL; (* A to Z, a to z *)
774+proc isSpace*(c: U8): BOOL; (* space, tab, line feed, carriage return, form feed, vertical tab *)
775+proc isPunct*(c: U8): BOOL; (* the printable characters that are neither letters, digits nor space *)
776+proc hexVal*(c: U8): INT; (* c's value as a hexadecimal digit, or -1 *)
777+```
778+
779+`isSpace` is today's `space`, exported. It breaks no program.
780+
781+Met in rrem's parser.
782+
783+## The text of an errno
784+
785+`Sys` returns minus an errno, and a tool that tells the user what
786+failed must turn it into words: `Rwfiles` maps four by hand, and says
787+"error 13" for the rest.
788+
789+The proposal, in `Sys`:
790+
791+```
792+proc errorText*(err: INT): []U8; (* what errno err (or minus it) means, as strerror says; "unknown error" otherwise *)
793+```
794+
795+a fixed table of Linux's names, so it needs no C. It breaks no
796+program.
797+
798+Met in rwalk's `Rwfiles`.
799+
800+## Setting an environment variable
801+
802+`Sys.env` reads a variable; nothing sets one. A test can't give the
803+programs it runs, or the code it tests, an environment of its own:
804+rwalk's tests read the user's real global ignore file, since they
805+can't point `XDG_CONFIG_HOME` at a directory of their own.
806+
807+The proposal, in `Sys`:
808+
809+```
810+proc setEnv*(name, value: []U8): INT; (* sets name to value, for this program and those it starts; 0, or minus an errno *)
811+```
812+
813+It breaks no program.
814+
815+Met in rwalk's tests.
816+
817+## Finding from a place
818+
819+`Str.find(s, sub)` searches the whole of `s`. To search from `i`, a
820+program writes `Str.find(s[i..LEN(s)], sub)` and adds `i` back when
821+the result isn't -1, which is clumsy and easy to get off by one.
822+
823+The proposal, in `Str`:
824+
825+```
826+proc findFrom*(s, sub: []U8; from: INT): INT; (* the first place at or after from where sub is in s, or -1 *)
827+```
828+
829+It breaks no program.
830+
831+Met in rwalk's `Rwglob`.
832+
833+## A hint for a hexadecimal name
834+
835+`FFFDH`, meant as a number, is an identifier, and the error is "FFFDH
836+isn't declared". The report is right (a hexadecimal number starts
837+with a digit, 2), but the message gives no clue. The proposal: when an
838+undeclared name is all hexadecimal digits and ends in `H`, the error
839+adds "a hexadecimal number starts with a digit: 0FFFDH". Nothing a
840+program means changes.
841+
842+Met in rrem's parser, writing U+FFFD.