On Sat, 13 Mar 2004, Giuseppe Chillemi wrote:

> Hi,
>
>              I am a newbie to Rebol. I need a little help on parsing:
>
> I have these 2 possible inputs:
>
>
>
> 1)  "KW1 555 <br> KW1 333 KW2 444 <br>"
>
> 2)  "KW1 555 KW2 666 <br> KW2 444 <br>"
>
>
>
> I need to extract the value of KW1 and KW2 , or KW1 itself.
                                                     ^ value?


> If I parse using (1):
>

hmmm


any[
    [to "KW1" copy myresult to <br>]
    |
    [to "KW1" to "KW2" copy myresult2 to <br>]
]

    ^^^^^^^^

    this second rule can never be reached since the first rule
    will allways accept any string the second rule could.




this solution may not work for you directly since it is keyed
to your example which is apt to be a simplification of your actual problem
but it may help



;;; a recursive parse rule to copy the value from an unknown number of
;;; consecutive "KW value" pairs in a string
;;; possibaly separated with <br>

rule: [
    "KW" ["1 " | "2 "]       ; what the parser needs to reconize
    copy result integer!     ; may not be integer in real case
    (append store result)    ; store/use result immediatly
    opt <br>                 ; there might be a trailing <br>
    opt rule                 ; there might be another KW to reconize
]



>> store: copy [] parse s1 rule store
== ["555" "333" "444"]
>> store: copy [] parse s2 rule store
== ["555" "666" "444"]


where s1 & s2 are your input strings


hope that helps


> (1) is parsed correctly by the first block of the rule but (2) is not (and
> the reason is clear)
>
> If I exchange the blocks of the rule, changing block1 to block2 and vice
> versa the result is still wrong because
>
>
>
> any[[to "KW1" to "KW2" copy myresult2 to <br>]
      |
      [to "KW1" copy myresult to <br>]
]

>
>
> Will parse string (2) correctly but string (1)
>
>
>
> "KW1 555 <br> KW1 333 KW2 444 <br>"
>
>
>
> Is parsed from the value of the first KW1 to KW2
>  (which is not a piece of the first part !) and finally to <br>
>
>
>
> Thank you in advance for you answers !
>
>
>
> Giuseppe Chillemi
> --
> To unsubscribe from this list, just send an email to
> [EMAIL PROTECTED] with unsubscribe as the subject.
>
-- 
To unsubscribe from this list, just send an email to
[EMAIL PROTECTED] with unsubscribe as the subject.

Reply via email to