Verified Commit e9dcabb2 authored by Vladimír Štill's avatar Vladimír Štill
Browse files

CFG: Fix an overzealous assertion in production counting

parent 9d4203ee
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -723,15 +723,12 @@ class WordGenerator:
        self.counts.append({n: 0 for n in self.cfg.nonterminals})

        for src, prod in self.cfg.productions():
            count = self._materialize_prod(prod, length)
            count = self._materialize_prod_count(prod, length)
            self.counts[length][src] += count

    def _materialize_prod(self, prod: CFG.Production, length: int, prefix=""):
        """Assumes smaller length are already computed"""

        assert len(self.prod_counts) >= length, \
            "smaller production lengths must be already computed"

        if isinstance(prod, Eps):
            return Eps() in self.cfg.rules.get(self.cfg.init, [])

@@ -743,6 +740,9 @@ class WordGenerator:
        if CFG.all_terminal(prod):
            return len(prod) == length

        assert len(self.prod_counts) >= length, \
            "smaller production lengths must be already computed"

        if len(self.prod_counts) == length:
            self.prod_counts.append(dict())