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

[REBOL] Re: Strange parsing behavior

From: brett:codeconscious at: 3-Aug-2002 18:11

> Well, this dependes how you expect parse to work.
I agree we have differing expectations. :^)
> As > soon as the rule, in this case to " - " could be parsed successfully, > the rule block ends.
I doubt that. It still has to process the paren! and to check if there is something after the paren!.
> 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).
Here are two interesting examples. In this first example the pattern given to COPY does not have a normal pattern to match on, but it does affect the parse position: parse [#a #b #c] [ #a pp: COPY block [ (pp: next next pp) :pp ] ] This example yields: == true
>> block
== [#b #c] In this second example the pattern given to COPY appears to match the stream initially but finishes by resetting the parse position to where it started at the beginning of COPY: parse [#a #b #c] [ #a pp: COPY block [#b #c :pp] #b #c ] This example yields: == true
>> block
== none I tend to think of Parse's COPY as equivalent to the REBOL's COPY/PART, and a parse pattern (rule) as a function that returns a series. Using this metaphor I can understand how the above two examples work (in fact I used the metaphor to dream up these odd examples in the first place). I wonder what you could expect from these two examples using the "early trigger" point of view.
> 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
Yes, debugging some rules can be challenging but I've never found it insurmountable. Parse as it works right now allows changing parsing rules on the fly. Here is another contrived example, this one shows a dynamic rule (perhaps the rules could be loaded from a file or database): stream-rules: [ 1 [#a #b #c] 2 [#d #e #f] 3 [#g #h #i] ] parse [1 #a #b #c 3 #g #h #i] [ (stream-rule: none) any [ copy section [ set num integer! (dynamic-rule: select stream-rules num) dynamic-rule ] (print mold section) ] ] Parse demonstrates a pretty flexible implementation! :^) Brett.