def teardown(self, g: grammar.Grammar): """We have introduced new nodes, so we need to recalculate min tokens. FIXME: Increasingly min tokens looks like it shouldn't be part of initial grammar creation. """ g._calc_min_tokens() g._calc_pot_tokens()
def teardown(self, g: grammar.Grammar): """Prune orphan symbols""" # Cannot remove start symbol! self.unit_symbols.discard(g.start) symbols = list(g.symbols.keys()) for name in symbols: if g.symbols[name] in self.unit_symbols: del g.symbols[name] g._calc_min_tokens() g._calc_pot_tokens()