Rebol Talk Forum  |  Getting Started  |  Newbie Help  |  Topic: Parsing blocks using wildcards
Pages: [1] Print
Author Topic: Parsing blocks using wildcards  (Read 220 times)
Grundle
Newbie
*
Offline Offline

Posts: 4


View Profile
Parsing blocks using wildcards
« on: August 27, 2004, 11:58:28 AM »

I am curious if there is a way to remove a particular pattern in a nested block structure?
The following block is the general idea
Code:
data: [blah [stuff, more stuff] " " [stuff [stuffing none] " " [stuf none none ]] continuing [stuff none]]

What I want to do is remove the entire block [stuff none none] but I want to do it based on the pattern.  I have a general idea that
I will be using something like

Code:
find/any data [* none none]
That is as close as I can get.  Can anyone point me in the right direction?  Thanks
Logged
CarlRead
Full Member
***
Offline Offline

Posts: 105


View Profile
Parsing blocks using wildcards
« Reply #1 on: August 27, 2004, 05:35:49 PM »

I don't think FIND looks into nested blocks, but yes, there is a way to do it - parsiing.  See the chapter on it in the REBOL/Core user's guide here...

Your kind of problem is perfectly suited for PARSE (the REBOL word designed for the job).  However, what you're wanting to do is compounded by the need to look through nested blocks.  Recursion is the normal way to do this. It's possible to do recursion with PARSE, (there's a section on it in the above mentioned chapter I think),  but you may find it simplier to use a standard method using a function, at least until you're comfortable with using PARSE.  (And you may find you don't need to use PARSE once you know how to do recursion.)

So, here's an example of using recursion to look through nested blocks.  hopefully it'll point you in the right direction...

Code:
rebol []

blk: [a [b] c [d e [f g] h] i]

recurse-example: func [blk [block!] indent [string!]][
   foreach value blk [
       either block? value [
           recurse-example value join indent "    "
       ][
           print join indent value
       ]
   ]
]

probe blk
recurse-example blk "    "

Run that at the REBOL Console to see what it does, then work out how the function does it and you should then understand resursion.  Do post again if you need more help.  (And appologies if I'm teaching a grandmother to suck eggs here and you already know for paring works:)
« Last Edit: August 27, 2004, 05:36:26 PM by CarlRead » Logged

- Carl Read
Pages: [1] Print 
Rebol Talk Forum  |  Getting Started  |  Newbie Help  |  Topic: Parsing blocks using wildcards
Jump to:  

  
Quick Search...

Advanced search
  
Welcome, Guest. Please login or register.
Did you miss your activation email?
August 29, 2008, 03:11:39 AM
Username: Password: Session Length:
  

News: 01-09-08

Alpha version of REBOL 3 has been released!


  
2232 Posts in 580 Topics by 1736 Members
Latest Member: goceertarramy

  Rebol Talk Forum | Powered by SMF 1.0.9.
© 2001-2005, Lewis Media. All Rights Reserved.

RT design by Defiant Pc