in reply to Text parsing. Processing scopes and subscopes.

Something about the statement of the task seems very odd to me. One way (I think the "literal" way) to interpret your description would yield a sequence like this:
0. text {scope 4 {scope 2 {scope 1} scope 2} scope 4 {scope 3} scope +4} text 1. text {scope 4 {scope 2 -change1- scope 2} scope 4 {scope 3} scope +4} text 2. text {scope 4 - - - -c h a n g e 2- - - - scope 4 {scope 3} scope +4} text 3. text {scope 4 - - - -c h a n g e 2- - - - scope 4 -change3- scope +4} text 4. text - - - - - - - - - - - - -c h a n g e 4- - - - - - - - - - - - + - text
So the question would be: why even bother with the initial nested levels, since later changes will obliterate them? If that's what is supposed to happen, it would make more sense to identify the outer-most bracketing, and apply only that single substitution. Perhaps you intended to describe something different?

(Update: I suppose that if there were interactions from one step to the next - e.g. if a substitution at step 1 either creates or eliminates a condition that affects what happens in a later stage - then it becomes a more complicated business, posing greater challenges for maintenance.)