Skip to content

Commit d4f1592

Browse files
committed
refactoring
1 parent 0b85da3 commit d4f1592

File tree

1 file changed

+2
-4
lines changed
  • src/commonMain/kotlin/ai/hypergraph/kaliningraph/parsing

1 file changed

+2
-4
lines changed

src/commonMain/kotlin/ai/hypergraph/kaliningraph/parsing/CFG.kt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,10 @@ private class FrozenCFG(val cfg: CFG): CFG by cfg {
3838

3939
val CFG.language: CFL by cache { CFL(this) }
4040
val CFG.delimiters: Array<Σᐩ> by cache { (terminals.sortedBy { -it.length } + arrayOf(HOLE_MARKER, " ")).toTypedArray() }
41-
val CFG.nonterminals: Set<Σᐩ> by cache { map { it.LHS }.toSet() }
41+
val CFG.nonterminals: Set<Σᐩ> by cache { setOf(START_SYMBOL) + map { it.LHS }.toSet() }
4242
val CFG.symbols: Set<Σᐩ> by cache { nonterminals + flatMap { it.RHS } }
4343
val CFG.terminals: Set<Σᐩ> by cache { symbols - nonterminals }
44-
val CFG.terminalUnitProductions: Set<Production>
45-
by cache { filter { it.RHS.size == 1 && it.RHS[0] !in nonterminals } }
44+
val CFG.terminalUnitProductions: Set<Production> by cache { filter { it.RHS.size == 1 && it.RHS[0] !in nonterminals } }
4645
val CFG.unitProductions: Set<Pair<Σᐩ, Σᐩ>> by cache { filter { it.RHS.size == 1 }.map { it.LHS to it.RHS[0] }.toSet() }
4746
val CFG.nonterminalProductions: Set<Production> by cache { filter { it !in terminalUnitProductions } }
4847
val CFG.unitNonterminals: Set<Σᐩ> by cache { terminalUnitProductions.map { it.LHS }.toSet() }
@@ -240,7 +239,6 @@ class JoinMap(val CFG: CFG) {
240239
}
241240

242241
// Maps indices to nonterminals and nonterminals to indices
243-
// TODO: Would be nice if START had a zero index (requires rebuilding caches)
244242
class Bindex<T>(
245243
val set: Set<T>,
246244
val indexedNTs: List<T> = set.toList(),

0 commit comments

Comments
 (0)