from .formats import BaseFormat from .tokens import * class ExtractingFormat(BaseFormat): """Yields only the args to entities of the given style.""" text_based = False def __init__(self, style): self.style = style def text(self, text): return () def start(self, t, arg=None): return () def end(self, t, arg=None): return () def entity(self, t, arg=None): if t == self.style: yield arg def __call__(self): # We don't have any mutable state, so we can be a singleton. return self