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

[REBOL] finding balanced occurences of two words... help needed Re:

From: rebol:techscribe at: 15-Sep-2000 2:18

Hi princepawn, and not in bed yet ...
> s-size: [thru "setsize" (set-cmds: set-cmds + 1)] > rs-size: [thru "resetsize" (reset-cmds: reset-cmds + 1)] > rules: [any [rs-size | s-size] ] > > parse read file rules
your rules contains the first rs-size and then s-size. The rs-size rule says [thru "resetsize"]. thru is a navigational command that tells the parse to ignore everything up to "resetsize". Since this is your first rule, parse will have skipped all occurrences of "setsize" because it can satisfy this rule by navigating passed the "setsize" until it arrives at "resetsize". Since it can fulfill the rs-size rule, and in doing so has passed "thru" all occurrences of "setsize", the s-size rule is never matched. Instead of using navigational commands, try the following combination (or something similar, I haven't tried it, because I really have to rest my brain for a few hours): s-size: ["setsize" (set-cmds: set-cmds + 1)] rs-size: ["resetsize" (reset-cmds: reset-cmds + 1)] rules [any [rs-size | s-size | skip] ] What happens now is that parse tries to match rs-size on the first character sequence it finds in file. If there is no match, it tries to match s-size instead. If neither of them match, it'll perform skip, which takes it to the next character and it will now try to match the string resetsize again against the charcter sequence beginning with the second character in the file, and so on, until it has exhausted the file, occassionally matching one or the other rule, or skipping a character, if neither of the rules match the chacter sequence beginning at the current character position. Hope this (or something similar to this) helps, ;- Elan [ : - ) ] author of REBOL: THE OFFICIAL GUIDE REBOL Press: The Official Source for REBOL Books visit me at