World: r3wp
[Parse] Discussion of PARSE dialect
older newer | first last |
Steeve 30-Sep-2009 [4285x2] | not enough.... |
yep, you have to check that for | |
BrianH 30-Sep-2009 [4287x5] | rule: [(p: 0) any [#"(" (++ p) | #")" if (1 <= -- p) then none | break] if (p = 0)] |
That works. If there is remaining input when you run out of rules, that coounts as failure. | |
It took reversing the if then condition to do it. | |
>> parse "(()" [(p: 0) any [#"(" (++ p) | #")" if (1 <= -- p) then none | break] if (p = 0)] == false >> parse "(())" [(p: 0) any [#"(" (++ p) | #")" if (1 <= -- p) then none | break] if (p = 0)] == true >> parse "())" [(p: 0) any [#"(" (++ p) | #")" if (1 <= -- p) then none | break] if (p = 0)] == false >> parse ")(" [(p: 0) any [#"(" (++ p) | #")" if (1 <= -- p) then none | break] if (p = 0)] == false | |
This kind of thing is why I suggested IF (as CHECK) 5 years ago :) | |
Steeve 30-Sep-2009 [4292x2] | to optimize a little, i would prevent from useless entering in the any loop: [#"(" (p: 1) some [#"(" (++ p) | #")" if (1 <= -- p) then none | break] if (p = 0)] |
but now, the (1 <= -- p) condition is false i mean | |
BrianH 30-Sep-2009 [4294x2] | [(p: 0) some [#"(" (++ p) | #")" if (1 <= -- p) then none | break] if (p = 0)] Handles the empty string. Given the | break alternate, ANY and SOME are equivalent. |
Yours would work, but wouldn't recognize an empty string. | |
Steeve 30-Sep-2009 [4296x2] | still, aren't the condition (1 <= -- p) wrong ? |
-- decrements but returns previous value | |
BrianH 30-Sep-2009 [4298] | You want the condition to be false, so the break is chosen. |
Steeve 30-Sep-2009 [4299] | if p = 1 then it must break |
BrianH 30-Sep-2009 [4300x2] | No, you want to break when p is 0 or less. |
Even in your version. | |
Steeve 30-Sep-2009 [4302] | wait... |
BrianH 30-Sep-2009 [4303x2] | The | break is not only the else for the if (), it is also the alternate chosen if #"(" or #")" are not matched. |
That is what THEN gives us: the ability to overload alternates. | |
Steeve 30-Sep-2009 [4305] | oh ok, it's not exiting the loop for such case [()()()()] |
BrianH 30-Sep-2009 [4306] | Right :) |
Steeve 30-Sep-2009 [4307] | Am ok now |
BrianH 30-Sep-2009 [4308] | But we *want* to exit the loop in this case: ")(" |
Steeve 30-Sep-2009 [4309] | yep |
BrianH 30-Sep-2009 [4310] | I find myself liking THEN quite a bit :) |
Steeve 30-Sep-2009 [4311x3] | But we still have a problem with break not being able encapable in a block. We can't construct reusable rules with such logic. |
i mean we can't push the part [if (1 <= -- p) then none | break] in a separated rule | |
we need a parameter for break | |
BrianH 30-Sep-2009 [4314] | It's tricky, true. There was either a proposal or a bug report to make BREAK break out of the closest enclosing ANY or SOME... |
Steeve 30-Sep-2009 [4315x3] | break level |
break 0 | |
break -1 | |
BrianH 30-Sep-2009 [4318] | Counted back, not negative. |
Steeve 30-Sep-2009 [4319x2] | if you prefer |
time for a new proposal Brian | |
Maxim 30-Sep-2009 [4321] | 'ROLLBACK anyone ;-) |
BrianH 30-Sep-2009 [4322] | Done, as n BREAK :) |
Maxim 30-Sep-2009 [4323] | funny I suggested it 2 hours ago, and you guys end up with a path with a use case implementing a simple rule :-) |
BrianH 30-Sep-2009 [4324] | I had to figure out how to make it fit in. Done. Off to dinner. |
Pekr 1-Oct-2009 [4325x6] | guys, what have you created for the simple recursive replacement of paren: [#"(" paren #")"] looks like regexp hell in comparison ... |
Not having proper recursion support is big downside of REBOL. | |
>> parse d: "abc" [change skip 123] >> d == "123bc" | |
Isn't it weird? I would expect a123 | |
hmm, maybe it is correct, just need a bit more of thought. Skip is not skipping "a", it is "matching" "a", hence defining, what should be replaced ... | |
The stack limit is so lame, almost unusable: REBOL level recursion: >> cnt: 0 recursion: does [++ cnt recursion] recursion ** Internal error: stack overflow >> cnt == 4004 Parse level recursion: >> cnt: 0 rule: [(++ cnt) rule] parse "123" [some rule] ** Internal error: internal limit reached: parse >> cnt == 512 | |
Henrik 1-Oct-2009 [4331] | I never bumped into the stack limit in R2 with parse. Is it smaller in R3? |
Pekr 1-Oct-2009 [4332x3] | will try ... |
no, it is exactly the same ... | |
But function example gives me == 14265 .... so - is function recursion stack lower in R3? | |
older newer | first last |