REBOL3 tracker
  0.9.12 beta
Ticket #0000671 User: anonymous

Project:



rss
TypeWish Statusdismissed Date25-Feb-2009 18:13
Versionalpha 35 Categoryn/a Submitted byBrianH
PlatformAll Severitymajor Priorityhigh

Summary LOAD /else on-error option
Description I would like a LOAD/else 'on-error option that would allow you to specify fallback behavior to handle REBOL syntax errors. The on-error parameter should be a lit-word! in the spec since it would accept keywords, though arguments of any word type should work.

The on-error actual argument would either be a keyword for a standard, built-in fallback behavior, or a block! that would be treated as the code block of a funct with two parameters:
- input: The input binary! at the position the next value was supposed to start.
- error: A block! with two elements, the error! and the input at the next position, same as what TRANSCODE would return at this point.

We pass a code block for FUNCT rather than a function! so the function parameters can be ensured to be correct without needing to screen them, and we can still have locals if we need them. We do the same thing with R3 GUI actions for the same reason.

The code block should return a block containing two values:
- A REBOL value (or #[unset!])
- The input binary! at the position that is supposed to be after that value.
This is the same as a regular LOAD/next return.

The block returned could be the same block passed as the error argument, perhaps modified, or a new block with the above contents. If the value returned in the first position is an error!, that error will be thrown - it could be the same error or something different. If something other than a block as described above is returned, an error will be thrown. We might consider allowing a return of #[none], and what that would mean. Any errors thrown by the code will be thrown by LOAD, not caught. RETURN and EXIT should be treated as code block returns, not passed through.

This allows the user to specify fallback behavior that is possibly less strict than LOAD would normally be (i.e. #124), or to localize their input, or to return better errors, or any number of other things. It may be possible to add new standard fallback behaviors at runtime, with new keywords.

LOAD/else on-error would be a wrapper of TRANSCODE/all/else on-error (#536 and #534). LOAD/next/else on-error would be a wrapper of TRANSCODE/next/else on-error (#535 and #534).

This proposal is derived from many requests over the years, and a well-populated debate in AltME 2 months ago.
Example code
; Some examples
>> load/else ", a b c" skip
== [a b c]
>> load/else "1,000.00" local
== 1000.0
>> load/else ", a b c" [either parse/all input ["," after:] [reduce [copy/part input after after]] [error]]
== ["," a b c]
; Note the local variable 'after.

Assigned ton/a Fixed in- Last Update26-Mar-2009 23:41


Comments
(0000477)
BrianH
25-Feb-2009 18:14

Waiting for #534, #535 and #536 to be implemented.
(0000506)
Carl
26-Mar-2009 06:38

The keywords are possible, the function callback part is not easy because for performance reasons TRANSCODE is not reentrant (although it is, in theory, REBOL thread safe.)

Also, the above description is complex so it's not entirely clear to me the benefit of this mechanism compared to iterative calls to TRANSCODE. The overhead of the callback and related state management would probably be about the same order as the top level calls into TRANSCODE, so there would not be a big win in speed.
(0000516)
BrianH
26-Mar-2009 23:41

This can be implemented as a separate function that calls TRANSCODE iteratively, now that alpha 39 adds the /error refinement.

Date User Field Action Change
26-Mar-2009 23:41 BrianH Comment : 0000516 Added -
26-Mar-2009 06:39 carl Status Modified waiting => dismissed
26-Mar-2009 06:39 carl Comment : 0000506 Modified -
26-Mar-2009 06:38 carl Comment : 0000506 Added -
26-Feb-2009 02:42 BrianH Priority Modified normal => high
25-Feb-2009 18:14 BrianH Comment : 0000477 Added -
25-Feb-2009 18:14 BrianH Description Modified -
25-Feb-2009 18:14 BrianH Code Modified -
25-Feb-2009 18:14 BrianH Status Modified submitted => waiting
25-Feb-2009 18:13 BrianH Ticket Added -