The Parser::handleDoubleUnderscore() method should be factored out into a CoreBehaviorSwitches class like CoreParserFunctions, etc, so that it can be reused by Parsoid, since almost everything it does can be done with only access to the ParserOutput (and TrackingCategories).
(As a corollary, reworking the stuff which is *not* "just ParserOutput" to track state in ParserOutput instead of Parser private variables would also help increase compatibility with Parsoid in situations where there might be a recursive parse with the legacy parser: the legacy parser and Parsoid would be effectively sharing the same parse state in the form of the ParserOutput object.)