Token transformation managers with a (mostly) abstract TokenTransformManager base class and AsyncTokenTransformManager and SyncTokenTransformManager implementation subclasses. Individual transformations register for the token types they are interested in and are called on each matching token.
Async token transformations are supported by the TokenAccumulator class, that manages as-early-as-possible and in-order return of tokens including buffering.
See https://www.mediawiki.org/wiki/Parsoid/Token_stream_transformations for more documentation.