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

[REBOL] Re: Strange parsing behavior

From: robert:muench:robertmuench at: 3-Aug-2002 8:39

> -----Original Message----- > From: [rebol-bounce--rebol--com] [mailto:[rebol-bounce--rebol--com]] > On Behalf Of Brett Handley > Sent: Saturday, August 03, 2002 2:04 AM > To: [rebol-list--rebol--com] > Subject: [REBOL] Re: Strange parsing behavior > I run your code and I get an error straight away: > > ** Script Error: string1 has no value > ** Where: rejoin > ** Near: mold name: get name > > So you probably had string1 set before you ran your test code.
Hi, hmm... I used the link-client to test it, or there was a problem with line breaks?
> > rule1: [start: copy string1 [to " - " (?? string1) | to newline]
copy string2 to end]
> To start, lets just look at the first COPY in your Rule1. The > variable is string1, the pattern is > [to " - " (?? string1) | to newline]
So far we agree ;-)
> Rule1 looks bad to me because you are asking parse to COPY > the input stream matched by the pattern into string1, but > then from inside the pattern (and therefore before the > pattern completes) you try to print string1.
Well, this dependes how you expect parse to work. The rule [to " - " (?? string1) | to newline] is a choice and Rebol parse uses a one-shot evaluation while parsing, this means, it executes a rule as long as possible starting with the first rule from several choices. As soon as the rule, in this case to " - " could be parsed successfully, the rule block ends. I expect parse to be in sync with the progress of the parsing. So, after parse did to " - " I expect the copy operation as terminated because internally it look like this: Copy string to " - " which can be executed successfully. So the print should succeed. The question is what is the trigger for the copy: You say it's the end of the rule block (lat trigger) and I would expect as soon as copying makes sense (early trigger). From a debugging point of view an early trigger is much more useful, further it would allow to create context-sensitive grammars, as you could chnage parsing rules on the fly. Robert