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

[REBOL] Re: My function seems to have no effect

From: joel:neely:fedex at: 16-Apr-2002 10:58

Hi, Richard, I'll try to explain and fix... COFFRE Richard FTO wrote:
> ... the double quotes are optional ... > > Can you give more explanation about the boilerplate. > I believe that gap is not a refinement of parse but I don't > really understand the link between the boilerplate and the > parse command : how can Rebol use the whitespace definition > into parse ... ??? >
Briefly, the parse rules specify a "grammar" which must be satisfied by the series being parsed. (In the comments below, I'll stick to parsing a string.) A BITSET! value can be used by PARSE in the sense of "one of these characters", so the definition whitespace: charset { ^-^/} means that the value of WHITESPACE will match anywhere that a space, tab, or newline occurs. Within the parsing dialect, the keyword ANY means zero or more occurrences of what follows, so the definition gap: [any whitespace] means that GAP will match anywhere that an optional run made up of spaces, tabs, and newlines (in any order/combination) occurs. If the quotation marks are optional, then the grammar gets a bit more complicated, especially if we're going to worry about whether the quotation marks must balance. Of course, we can cheat and assume that whatever is creating the input data will deal with that issue. In other words, I'll assume that presence/absence of properly-balanced quotation marks isn't a significant issue for the present purpose.
> Some sample data: > > bletch: { > Call ("Get0Code:initData") > call ("TestFunc:blahblah") > call("Quux:flarp") call("Quux:spoo") > call ( "Layout:spaceObsessively" ) CALL ( "The:end" ) > } >
bletch: { Call ("Get0Code:initData") call ("TestFunc:blahblah") call("Quux:flarp") call("Quux:spoo") CALL (MoreStuff:unQuoted) call ( MoreStuff:quotesMustMatch ) call("Cheat:caseOne) call(Cheat:caseTwo") call ( "Layout:spaceObsessively" ) CALL ( "The:end" ) } whitespace: charset { ^-^/} gap: [any whitespace] parse/all bletch [ any [ {call} gap {(} copy fn to {)} {)} ( print trim/with fn {" } ) | skip ] ] This provides the following output: Get0Code:initData TestFunc:blahblah Quux:flarp Quux:spoo MoreStuff:unQuoted MoreStuff:quotesMustMatch Cheat:caseOne Cheat:caseTwo Layout:spaceObsessively The:end and returns TRUE because it consumed the entire string. The way that parse rule works is as follows: - a string is assumed to be made up of zero or more parts (that's the role of ANY ) - each part is either a function call or a single character whose value we don't care about (that's the role of | ) - a function call must contain the following parts: - the literal word "call" - an optional run of whitespace - an open parenthesis - any characters (no constraints on what may appear here) up to but not including a close parenthesis -- all of which will be saved in the word FN - a close parenthesis - if we do match a function call with the above syntax, remove all spaces and quotation marks from the string in FN and print what's left (that's the role of the parentheses enclosing the PRINT... phrase) Note that this version will allow unbalanced quotation marks around the name of the function being called. Hope this helps! -jn-