Hi Petr, 6-Jan-2000 you wrote:
[...]
>> How about this:
>>
>> >> a: [skip a | "ing"]
>> == [skip a | "ing"]
>> >> parse "ringin" a
>> == false
>> >> parse "ringing" a
>> == true
>>
>> It should do the job. So actually backtracking in Parse can be achieved by
use
>> of the "|" operator in Parse blocks.
>What? | is simple OR or am I wrong? You will end up in recursion imho.
That was the very point.
>Try this:
>a: [skip mark: (print mark) a | "ing"]
>you will get following result:
>ingin
>ngin
>gin
>in
>n
>== false
...which was exactly what I wanted.
>"ing" is never going to be considered imho, unless skip fails, and that's
when?
>When we reach end. Then it fails, as at the end, "ing" is not applicable.
Because I wanted to match a string _ending_ with "ing". I guess we have just
misunderstood each other?
>How's that your second example works? Let's extend the rule:
> a: [skip mark1: (print ["mark1: " mark1 index? mark1]) a | mark2: (print
["mark2:
>" mark2 index? mark2]) "ing"]
>mark1: inging 2
>mark1: nging 3
>mark1: ging 4
>mark1: ing 5
>mark1: ng 6
>mark1: g 7
>mark1: 8
>mark2: 8
>mark2: g 7
>mark2: ng 6
>mark2: ing 5
>== true
>Hmm, strange, at mark1: 8 skip fails as we are at the end of the string,
parse
>tries to aply "ing" - not a succes, it then returns from recursion one level
upon.
>How's that 'skip fails here (mark2: 7)? In real - it doesn't, as the rule is:
>[skip a | "ing"]
>and we are just behind the skip, back from the nested 'a, which failed, so it
>tries to aply "ing" ....
>Whee ya, backtracking as a wine? :-)
>I am just starting to learn some simple parse rules, so take my comments
easy, if
>wrong :-)
I just don't see what the problem is. The examples above do exactly as I
wanted. I used "|" as "a backtracker", since it appears to do this:
First, call recursively on the left side of the "|". If the match succeeds,
return success.
If the first call didn't return success, call recursively on the right side of
the "|" (starting from the same position in the input stream as for the call
on the left side of the "|"). If the match succeeds, return success,
otherwise return failure.
This is effectively the same as backtracking.
>See ya,
>PS: I am somehow tired today to study and comment another examples, sorry :-)
Me too, I still have to read quite a few pages (of _really_ boring statistics)
before I can go to bed ;-)
Kind regards,
--
Ole Friis <[EMAIL PROTECTED]>
"Ignorance is bliss"
(Cypher, The Matrix)