Search code examples
parsingrebolred-lang

Rebo/Red parse: Is it possible to copy between two marks embedding nested div


Subsequent to Rebol/Red parse: how to copy between 2 marks let's now suppose I achieve to mark a string with some marks with a complex parse rule having nested div (whatever that rule), is there a general way to copy between mark1 and mark2, at least is there a specific way for this kind of nested div example:

    {
        <div>
        a ; <- mark1
            <div>
                b
            </div>
            <div>
            c
            </div>
        d ; <- mark2
        </div> 

        <div>
        e
            <div>
                f
            </div>
            <div>
            g
            </div>
        h
        </div>  
    }


    rule: [
        mark1:
        ...
        mark2:
        copy mark1 to mark2
    ]

Solution

  • This is no problem with the already shown solutions, but if you want to make it a little bit more complicated you could go back to an already defined / marked point in your src as in this example.

    src: {1234567890abcdefghijklmnopqrstuvxyz}
    >> parse src [ skip mark: to "a" mark2:  :mark   to "3" mark1: to end]  
    == true
    >> mark1
    == "34567890abcdefghijklmnopqrstuvxyz"
    

    pay attention to :mark It set back the pointer to an prior defined point.

    So the answer to your former question would look like that

    rule: [
        to "b" mark1: thru "e" mark2: 
        :mark1 copy text to mark2
    ]
    

    Here replace "b" and "e" according your your wished points, maybe "a" and "d".