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

[REBOL] Re: Parse refactoring puzzle

From: AJMartin:orcon at: 30-Jul-2003 19:17

Sunanda wrote:
> The function I wrote, and some test data is below. Can anyone suggest a
one-parse approach? [ Rebol [ Name: 'Remove_Place_Holders Title: "Remove Place Holders" File: %"Remove Place Holders.r" Author: "AJ Martin" Copyright: "Free!" Date: 30/July/2003 ] Remove_Place_Holders: function [String [string!]] [Mark Start Stop] [ Mark: {!!} parse/all String [ any [ Start: Mark thru Mark End: ( End: remove/part Start End ) :End | skip ] end ] String ] foreach [Test Goal] [ {Welcome John-Paul your address is The Vatican !!town!! Roma !!state!! Italia} {Welcome John-Paul your address is The Vatican Roma Italia} {no place holders in this string} {no place holders in this string} {!!begin!!text!!end!!} {text} {!!good!holder, even if a little weird!!and some text} {and some text} {leaves null place-holder !!!! in output, but another function might remove it. Either way is fine} {leaves null place-holder in output, but another function might remove it. Either way is fine} ] [ if Goal <> Actual: Remove_Place_Holders copy Test [ print [ "Problem!" newline "Test:" mold Test newline "Actual:" mold Actual newline "Goal:" mold Goal ] halt ] ] print "All OK!" halt ] And running it, produces: All OK!
>>
Note that 'Remove_Place_Holders modifies it's input string; the test code supplies a copy so that we can what the problems are. Sunanda wrote:
> Code before ours has made substitutions, but may have left some stray
place-holders:
> {Welcome John-Paul your address is The Vatican !!town!! Roma !!state!! > Italia} > > So I now want to remove the remaining place-holders:
The substitution code could easily remove placeholders that don't have a value. I hope that helps! Andrew J Martin ICQ: 26227169 http://www.rebol.it/Valley/ http://Valley.150m.com/