tags:

views:

53

answers:

2

According to http://www.rebol.com/docs/core23/rebolcore-15.html

You can use change/part to parse and replace but that doesn't work well with this where I just try to replace the block

<mytag > ... </mytag>

by "MyString"

content:  {<mytag id="a" 111111111111111>
</mytag>
aaaaaaaaaaaaaaa
aaaaaaaaaaaaaaa
<mytag id="b" 22222222222222222>
</mytag>

<mytag id="c" 3333333333333>
</mytag>
aaaaaaaaaaaaaaa
aaaaaaaaaaaaaaa
<mytag id="d" 444444444444444>
</mytag>
}


mytag: [  to {<mytag} start: (
)
  thru {<mytag}
  to {id="} thru {id="} copy ID to {"} thru {"}
  to {</mytag>} 

  thru {</mytag>} 
  ending:

  (change/part start "mystring" ending)
  mark:
  (  write clipboard:// mark
  input)  
]

rule: [any mytag to end]

parse content rule
+2  A: 

I point you to have a look at http://en.wikibooks.org/wiki/REBOL_Programming/Language_Features/Parse#Modifying_the_input_series

Ladislav
Thank you very interesting will reread it. Still I can't see why and how I solve my parse problem whereas the goal is really simple ?
Rebol Tutorial
+1  A: 

Ladislav's suggestion is to solve it without changing the input stream, which can have performance issues and is harder to debug. Just build up your output separately. e.g.

result: copy ""

mytag: [
  [
    copy text to {<mytag} (if text [append result text])
    thru {<mytag}
    to {id="} thru {id="} copy ID to {"} thru {"}
    thru {</mytag>} 
    (append result reform ["__" ID "__"])
  ]
  | 
  skip
]

rule: [any mytag to end]

parse content rule

result
Gregg Irwin
OK thanks that solves the immediate problem but I still don't understand the weird result of my code.And this solutions seems not "composable" with other rules if I needed to ?
Rebol Tutorial
If you add some probes to see where 'start, 'ending, and 'mark are, it may become clear. Since you are changing part of the string with a sub-string of a different length, you need to adjust the position in the input accordingly. e.g. (new-mark: change/part start "mystring" ending) :new-mark
Gregg Irwin