Skip to content

Commit

Permalink
simplify js
Browse files Browse the repository at this point in the history
  • Loading branch information
breandan committed Jul 15, 2024
1 parent d5c3002 commit f247409
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -419,8 +419,7 @@ fun CFG.fastRepairSeq(tokens: List<String>, spacing: Int = 2, holes: Int = 6): S
}.flatMap { if (it.isEmpty()) sequenceOf(it) else minimizeFix(tokens, it.tokenizeByWhitespace()) { this in language } }

fun CFG.barHillelRepair(tokens: List<String>): Sequence<String> =
generateSequence(1) { it + 1 }
.flatMap { radius ->
generateSequence(1) { it + 1 }.flatMap { radius ->
try { intersectLevFSA(makeLevFSA(tokens, radius)).ifEmpty { null } }
catch (e: Exception) { null }?.toPTree()?.sampleStrWithoutReplacement() ?: sequenceOf()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ fun Σᐩ.parseCFG(
lines().filter { "->" in it }.map { line ->
if (validate && !line.isValidProd()) throw Exception("Invalid production: $line")
line.splitProd().let { it[0] to it[1].tokenizeByWhitespace() }
}.toSet().let { if (normalize) it.normalForm else it }
}.toSet().let { if (normalize) it.normalForm else it.freeze() }

fun Σᐩ.stripEscapeChars(c: Char = '`'): Σᐩ =
if (first() == c && last() == c) drop(1).dropLast(1) else this
Expand Down

0 comments on commit f247409

Please sign in to comment.