Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TRANSCODE /else on-error option #534

Closed
rebolbot opened this issue Jan 16, 2009 · 2 comments
Closed

TRANSCODE /else on-error option #534

rebolbot opened this issue Jan 16, 2009 · 2 comments

Comments

@rebolbot
Copy link
Collaborator

Submitted by: BrianH

I would like a TRANSCODE option that would allow you to provide a fallback function that would be called on REBOL syntax errors.

The argument function would take two parameters:

- The string being transcoded at the position the value was supposed to start.
- The block that TRANSCODE would have returned here, with the defanged error and the next position. This might be better passed as two parameters - a decision is needed here.

TRANSCODE is a low-level function so it should raise an error if the parameter list is not compatible (by APPLY rules).

The function would return a block containing two values:

- A REBOL value (or #[unset!])
- The input string at the position that is supposed to be after that value.

This is the same as a regular TRANSCODE return. The return block will then be treated by TRANSCODE as if it was what TRANSCODE found there. If you want to pass through the original error, return the original TRANSCODE return block (or create one if we go for the 3-parameter proposal above). TRANSCODE probably should raise an error if the return value doesn’t match the form it expects. We might consider allowing a return of #[none], and what that would mean.

This allows the user to specify fallback behavior that is possibly less strict than TRANSCODE would be. Or more – the fallback could raise the error, for instance. This would help with more advanced options for LOAD that have been proposed, and with more efficient use of TRANSCODE in combination with other proposals.


Three arg version:
transcode/else "," func [
    input [string!] error [error!] after [string!]
] [
    either parse/all input ["," after:] [
        reduce [copy/part input after after]
    ] [
        reduce [:error after]
    ]
]

Two arg version:
transcode/else "," func [
    input [string!] error [block!] /local after
] [
    either parse/all input ["," after:] [
        reduce [copy/part input after after]
    ] [:error]
]

CC – Data [ Version: alpha 31 Type: Wish Platform: All Category: n/a Reproduce: Always Fixed-in:none ]

@rebolbot
Copy link
Collaborator Author

Submitted by: BrianH

This would be needed to implement #671.

@rebolbot
Copy link
Collaborator Author

Submitted by: Carl

See comments for #671.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant