Thinking about this further (yes, I know I should be concentrating on festivities, my wife has already told me) I am still a bit puzzled. Following the stages as you describe, there is no outer
x flag so comments are not stripped once the closing token is found. Then variable interpolation is done
before the pattern is compiled so nothing should yet be known about the semantics of the pattern. However, it seems that the compiler is aware somehow that variables don't interpolate inside
(?# ... ) constructs, as seen
here whereas it isn't with extended syntax comments.
It would appear that some form of pre-compilation parsing is happening so that it is aware of comment blocks before variable interpolation. I wonder if it would also be able to take note of (?x) constructs. The problem would be separating the x from the possible ism etc.
Cheers,
JohnGG