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

[REBOL] Re: Parse versus Regular Expressions

From: g:santilli:tiscalinet:it at: 5-Apr-2003 21:48

Hi Joel, On Saturday, April 5, 2003, 4:44:11 PM, you wrote: JN> I'm not clear on which part you're referring to as "useless copying". When you say (some expression) and then refer to the matched substring with $1, it means that the interpreter has created a new variable and copied a part of the input string in it. With the approach I (and Ladislav) used you do not need to allocate any extra space or copy parts of the input string. (I.e. you are sure that the are no copies, independently on the "sophisticatedness" of the implementation.) JN> How would you solve the variation I posed in my reply to Ladislav? JN> (allow the run of equal-length a, b, c segments to occur anywhere JN> inside the target string?) Using an approach similar to the one you used for the RE, i.e. (using copies this time, for the sake of simplicity): any [ here: copy As some #"a" copy Bs some #"b" copy Cs some #"c" (if all [ greater-or-equal? length? As length? Bs lesser-or-equal? length? Bs length? Cs ] [print ["Found match at position" index? here]]) | skip ] It is admittedly quite slow, but I doubt that the RE would be faster.
>> parse/all "my dog has aaabbbccc fleas" rule
Found match at position 12 == true
>> parse/all "aaadddeeeabc" rule
Found match at position 10 == true
>> parse/all "abcccccccc" rule
Found match at position 1 == true
>> parse/all "aabbaaaaabbcccc" rule
Found match at position 5 == true (The last result is arguably wrong, however I think it is on par with the one you get with your RE.) Regards, Gabriele. -- Gabriele Santilli <[g--santilli--tiscalinet--it]> -- REBOL Programmer Amigan -- AGI L'Aquila -- REB: http://web.tiscali.it/rebol/index.r