Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] Re: Help on parsing

From: tomc:darkwing:uoregon at: 13-Mar-2004 12:39

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>] ]