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

[REBOL] Re(2): 'parse trick and 'unset

From: arolls::bigpond::net::au at: 17-Dec-2000 3:34

Change 'id, so that the full code is: line1: "Ju<li>e<><><<1234>" line2: "Jules<1234>ffg<5678>" digits: charset "0123456789" id: ["<" 3 4 digits ">"] rule: [a: some [id | [skip b:]] (print copy/part a b)] parse line1 rule parse line2 rule
> > Try this out: > > line1: "Ju<li>e<><><<1234>" > > id: [thru "<" 3 4 digits ">"] > > rule: [a: some [id | [skip b:]] (print copy/part a b)] > > parse line1 rule > > Nice trick, I would never have thought of it. It will really be useful for > 'extract rule checking (see my last post). I was surprised by the > results of > the following test though: > > >> parse line1 rule > Ju<li>e<><>< > == true > >> line2: "Jules<1234>ffg<5678>" > == "Jules<1234>ffg<5678>" > >> parse line2 rule > ** Script Error: Invalid /part count: <1234>. > ** Where: print copy/part a b > > Weird. After some stuffing around I discovered this was because > 'a and 'b were > still defined from the last operation, so the values need to be > cleared. This > is apparently not as easy as it would seem:
That's not the reason. The reason is because parsing line2 didn't ever set 'b. 'b was still set to point to line1, with the index at "<1234>". Why? Because in 'line2 we instantly found 2 id's and got to the end in two steps. That's because id began with [thru ">" ...], which means "jump through all input until after the first ">". This happens twice and we're finished already. Remove the 'thru, and 'id is defined more precisely. My mistake.
> Finally Anton, your trick always returns true, even if it didn't > find the id > !: > > line1: "Ju<li>e<><><<no-id-here>" > parse line1 rule > Ju<li>e<><><<no-id-here> > == true > > So I'll have to redefine 'rule: > > parse line1 rule: [a: (success: false) some [id (success: true)| > [skip b:]] > (print copy/part a b)] > if success [do something]
That's a good idea. Anton.