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

PARSE returns input on success, PARSE? variant #202

Merged
merged 1 commit into from
Dec 28, 2015
Merged

PARSE returns input on success, PARSE? variant #202

merged 1 commit into from
Dec 28, 2015

Conversation

hostilefork
Copy link
Member

This implements #2165 where PARSE is to return the input series on
success, and NONE on false, unless a RETURN is used to override it
(in the future, COLLECT would override it as well).

It also implements a twist, with a PARSE? variation that can only
return TRUE or FALSE. Since it ends in a question mark, the idea that
it act exactly like the old PARSE isn't a precise match...as the rule
is that functions ending in question mark return only true or false.
As one possible way of pushing that rule through, the PARSE? variant
does not tolerate RETURN (unless it is a return of a LOGIC!) and
will error.

This makes PARSE? suitable for use in practically every case where the
previous desire to return a TRUE or a FALSE was desired. In the cases
where it was not, the PARSE variant makes more sense.

Legacy support uses a heuristic to make a good guess about what the
original PARSE output would have been, but can be tripped up if a
RETURN happened to return the series at the input position.

This is an experiment to see how it goes and if it turns out to be
of benefit.

This implements #2165 where PARSE is to return the input series on
success, and NONE on false, unless a RETURN is used to override it
(in the future, COLLECT would override it as well).

It also implements a twist, with a PARSE? variation that can only
return TRUE or FALSE.  Since it ends in a question mark, the idea that
it act exactly like the old PARSE isn't a precise match...as the rule
is that functions ending in question mark return *only* true or false.
As one possible way of pushing that rule through, the PARSE? variant
does not tolerate RETURN (unless it is a return of a LOGIC!) and
will error.

This makes PARSE? suitable for use in practically every case where the
previous desire to return a TRUE or a FALSE was desired.  In the cases
where it was not, the PARSE variant makes more sense.

Legacy support uses a heuristic to make a good guess about what the
original PARSE output would have been, but can be tripped up if a
RETURN happened to return the series at the input position.

This is an experiment to see how it goes and if it turns out to be
of benefit.
@giuliolunati
Copy link

Optime!

I think also could be handy if on false the index of input series is placed at "critical" point, where fail occurs

@hostilefork
Copy link
Member Author

I think also could be handy if on false the index of input series is placed at "critical" point, where fail occurs

That's an interesting idea; though I don't know it should be modifying the input value as a requirement. Besides semantics, it may be in a protected variable--you should be able to parse read-only data).

Something I have thought is that the functionality of TRANSCODE should be part of PARSE. So that is to say that you should be able to say parse {1234 "abcd"} [set foo integer! space set bar string!], and get foo as INTEGER! 1234 and bar as STRING! abcd. When I have thought about what all would be useful with that, I have thought about the importance of knowing where in the parse a failure occurred. To make this truly useful (and possibly a tool for making Rebol's loading process based on PARSE) it would be important to know the lines and columns for reporting failure messages. I'll just mention that as something in the "same area to think about".

@hostilefork hostilefork merged commit d4689c2 into metaeducation:master Dec 28, 2015
@hostilefork hostilefork deleted the parse-returns-input branch December 28, 2015 14:28
@codebybrett
Copy link

Relating to the idea from @giuliolunati... From my experience with my Rebol 2 parse debugging tools, one of the most useful bits of information is to show the maximum point through the input that the parsing process reached before ultimately failing. In most cases this can quickly draw attention to the parse rules that require debugging. In the case of block mode this may mean the deepest level.

I'm unsure of the ultimate use of returning the input series upon success, but I think it is a good step. I think that one day it would be more useful if Parse returned a parsed structure resulting from the input and the rules by default.

As Parse is little interpreter maintaining state variables such as Input-Position, Rule-Success and maybe one day Furthest-Postion and Parsed-Structure, it maybe useful to be able return all of them when required.

This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants