REBOL3 tracker
  0.9.12 beta
Ticket #0002154 User: anonymous

Project:

Previous Next
rss
TypeWish Statusdismissed Date12-Jun-2014 11:56
Versionr3 master CategoryParse Submitted byfork
PlatformAll Severityminor Prioritynormal

Summary Parse keyword for "match up TO and then SKIP" - UNTIL?
Description A recurring pattern is something like:

>> parse "abc$$def" [copy left to "$$" skip skip copy right to end]

...where your goal is that left be "abc" and right be "def". It might also be expressed as:

>> parse "abc$$def" [copy left to "$$" "$$" copy right to end]

Or if you want to follow the DRY principle at the cost of having to name something you don't really feel like naming:

>> pattern: "$$"
>> parse "abc$$def" [copy left to pattern pattern copy right to end]

All are suboptimal. The issue is that sometimes you want to go up TO something for the purposes of the match... but then find yourself wanting it to act as if it had been a THRU for the purposes of the position when you are done.

There's no good workaround for this pattern, so it would be nice to have a keyword that did it. UNTIL is the idea that came up in chat:

>> parse "abc$$def" [copy left until "$$" copy right to end]

Maybe there is a better name. But as with other PARSE keywords, there's an advantage of using an existing Rebol function is to not be taking any more words from the user for variables.
Example code

			

Assigned ton/a Fixed in- Last Update2-Sep-2014 01:14


Comments
(0004437)
kealist
12-Jun-2014 23:54

I like the idea of adding something like that because I commonly run across the repetition often:

copy to space space

There may be a better name than UNTIL, but TO-THRU isn't it!
(0004439)
abolka
13-Jun-2014 16:45

+1 for something like that. I, too, often encounter that repetition (or the "to space skip" pattern) first hand.
(0004440)
fork
13-Jun-2014 16:49

Noticed that there is an existing proposal for UNTIL:

http://www.rebol.net/wiki/Parse_Project#UNTIL_operator

I don't know enough to say whether that is important enough to trump the use of UNTIL for this purpose.
(0004456)
BrianH
22-Jun-2014 01:18

Ladislav seems to think that you can do his UNTIL using a particular combination of WHILE, ACCEPT and REJECT. And looking at your example scenario, I can't easily think of a way to phrase what you want using his UNTIL. Nonetheless, both proposals have merit, so if you can come up with a better name than UNTIL for your proposal that would be great.
(0004501)
Ladislav
28-Aug-2014 16:42

This proposal is erratic. If implemented, the above UNTIL would be equivalent to THRU, but in such case the

>> parse "abc$$def" [copy left until "$$" copy right to end]

would not work as expected
(0004503)
Ladislav
1-Sep-2014 16:30

Unless changed to something feasible, this proposal should be dismissed.

To be constructive, here is a way how the goal of the proposal could be achieved, as opposed to the original proposal:

Define a new keyword COPY-TO with the syntax:

COPY-TO word rule

and with the behaviour similar to

COPY word TO rule rule
(0004504)
fork
1-Sep-2014 22:10

@Ladislav Not sure I understand here, as you have said that the proposal doesn't do what it is proposed to do.

>> parse "abc$$def" [copy left until "$$" copy right to end]

By definition it's supposed to give you "abc" for left and "def" for right. As in--that is what the proposal *is*. Renaming it COPY-TO and saying "oh, then it could work" makes no sense.

Perhaps what you mean is that the UNTIL word you have defined in a previous proposal does not do this? If so...yes, right, this is a different idea for how to use the word UNTIL. An alternative name suggestion for this is welcome, but I do not think COPY-TO conveys a construct that does more than "COPY" and "TO". It needs to convey "COPY-TO-AND-MATCH", and UNTIL was the best name idea for that so far I thought.
(0004505)
Ladislav
1-Sep-2014 22:36

"Not sure I understand here, as you have said that the proposal doesn't do what it is proposed to do." - it looks that I need to explain to you why this proposal would not do what you think it would do. See below for the explanation. Also, please note that I am not the one comparing it to the other UNTIL proposal, and that thinking that I do is yet another source of misunderstanding here.

To realize where the problem with this proposal is, check what happens when the following RULE1 is used:

rule1: [until "$$"]

According to your proposal, the behaviour would be the same as if this RULE2 was used:

rule2: [thru "$$"]

Now, compare the behaviour of:

rule3: [copy left rule1]

and

rule4: [copy left rule2]

Since the behaviour of RULE1 and RULE2 is the same, the behaviour of RULE3 and RULE4 will be the same as well. Dismissing the proposal as erratic.
(0004506)
kealist
1-Sep-2014 23:23

I didn't get it at first, but Ladislav is right. This functionality needs to be defined as an alternative to COPY rather than an alternative to TO/THRU because the UNTIL proposal isn't meaningful without COPY.
(0004507)
fork
2-Sep-2014 01:14

Okay, so it relates to defining a behavior for UNTIL as a functional unit in its own right when not used with a COPY, and having that unit fit a modular pattern of other match rules that interact with COPY. A better counterexample would be something like:

rule: [until "b" thru "c"]

parse "abc" [copy x rule]

Fair enough to say this UNTIL doesn't stand on its own, and would wind up being framed as an option to COPY. However: technically there is nothing stopping one from having the syntax for that be COPY VAR UNTIL RULE vs. COPY VAR RULE and just saying the above is not legal. There's no holy canon for dialect design, and also the "express option as an extra word you throw in" has made it in proposals for Parse like with INSERT ONLY vs INSERT. Hence my response about the name not being the issue.

Leaving the goodness or badness of that syntax aside, a larger question is semantic. COPY has a formulation which is to copy from the current position to wherever the rule it is given ends up positioning. It is not sensitive to whether you used TO or THRU in the rule or any combination thereof. So what would COPY VAR UNTIL [TO RULE] mean (however you express it), given it can't mean COPY VAR TO RULE TO RULE ?

Perhaps it's best to focus back on the intention; which was how to get "abc" and "def" out of "abc$$def". It *seems* a good solution could exist that lets us use the literal string "$$" only once, without requiring putting it into a variable. I guess we just have to think about whether that is true or Parse cannot be reasonably adapted in the current design to do so.

Date User Field Action Change
2-Sep-2014 01:18 Fork Comment : 0004507 Modified -
2-Sep-2014 01:14 Fork Comment : 0004507 Added -
1-Sep-2014 23:27 Ladislav Comment : 0004501 Modified -
1-Sep-2014 23:23 kealist Comment : 0004506 Added -
1-Sep-2014 22:37 Ladislav Status Modified problem => dismissed
1-Sep-2014 22:36 Ladislav Comment : 0004505 Added -
1-Sep-2014 22:10 Fork Comment : 0004504 Added -
1-Sep-2014 16:30 Ladislav Comment : 0004503 Added -
28-Aug-2014 16:43 Ladislav Status Modified reviewed => problem
28-Aug-2014 16:42 Ladislav Comment : 0004501 Added -
22-Jun-2014 01:18 BrianH Status Modified submitted => reviewed
22-Jun-2014 01:18 BrianH Category Modified Unspecified => Parse
22-Jun-2014 01:18 BrianH Comment : 0004456 Added -
13-Jun-2014 16:49 Fork Comment : 0004440 Added -
13-Jun-2014 16:45 abolka Comment : 0004439 Added -
12-Jun-2014 23:54 kealist Comment : 0004437 Added -
12-Jun-2014 11:57 Fork Description Modified -
12-Jun-2014 11:56 Fork Ticket Added -