(Hmm, Petr's message has yet to arrive here. SELMA?)

Hello [EMAIL PROTECTED]!

On 29-Dic-99, you wrote:

 i> Hi Petr,

 i>> [EMAIL PROTECTED] wrote:

 i>>> Hello [EMAIL PROTECTED]!

 i>> On 27-Dic-99, you wrote:

 i>>> [thru "s" "om" skip " " "t" thru "t" " " "to" " " "p"
 i>> skip
 i>>> skip "se"]

 i>> What about:

 i>>     [thru "som" skip " t" thru " to p" 2 skip "se"]

 i>> Well, it doesn't solve my situation actually. The search
 i>> string user enters can be something like "s?me", and you have
 i>> to scan for the "s" occurance, followed by the rest of the
 i>> rule - skip "me" " " etc.... The buil-rule function seems to
 i>> work, seems to translate ? and * into right (almost, need to
 i>> think about t*t case :-) sequences. The problem is really
 i>> skip to "right" occurance of "s", to match the rule. I am now
 i>> thinking about using some "ordinary" iteration, which should
 i>> use 'find, to find "s", and then will try to apply the rule.
 i>> I know the solution with rule | skip was also suggested here,
 i>> but I think it will slow things a little bit ....

Ok, so let's try with the complete solution. :-) (I just wanted to
make a little suggestion last time... ;-) ).

You have to scan the entire string to find the first piece of text
that matches the rule; we want to return the position where the
piece of text was found. We can use an iteration inside parse
instead of outside it.
We are assuming that the first piece of the rule is a string; I
think this is ok with you because you make the same assumption.

exit-parse: [to end]

find-match: func [
    "Find the first match of a rule" [catch]
    text [string!]
    rule [block!] "The rule to match"
    /local initial-string position
] [
    initial-string: first rule ; should be a string
    if not string? :initial-string [
        throw make error! compose [
            script invalid-arg (mold initial-string)
        ]
    ]
    either parse/all text [
        to initial-string position:
        some [
            rule exit-parse |
            skip to initial-string position:
        ]
    ] [
        position
    ] [
        none
    ]
]

>> find-match "Some text, some string to parse, some other text" [
[    "som" skip " str" thru "g to p" 2 skip "se"
[    ]
== "some string to parse, some other text"
>> find-match "Some text, some string to parse, some other text" [
[    "som" skip " other t" thru "t"                                 
[    ]
== "some other text"
>> find-match "This will not work." [2 skip "is"]
** Script Error: Invalid argument: 2.
** Where: find-match "This will not work." [2 skip "is"]

Hope this helps,
    Gabriele.
-- 
o--------------------) .-^-. (----------------------------------o
| Gabriele Santilli / /_/_\_\ \ Amiga Group Italia --- L'Aquila |
| GIESSE on IRC     \ \-\_/-/ /  http://www.amyresource.it/AGI/ |
o--------------------) `-v-' (----------------------------------o

Reply via email to