Skip to content

Commit

Permalink
cache hashCode for frozen CFGs
Browse files Browse the repository at this point in the history
  • Loading branch information
breandan committed Apr 22, 2023
1 parent e8f9950 commit 7cd87a9
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ const val NO_REPAIR = "NO_REPAIR_PROPOSAL!"
// "Premature optimization is the root of all evil." -Dijkstra

val tidyparse = Model("tidyparse")
val cfg =
val cfg: CFG =
"""S -> w | ( ) | [ ] | { } | ( S ) | [ S ] | { S } | S S"""
.parseCFG().apply { blocked.addAll(setOf("w")) }

Expand Down Expand Up @@ -120,14 +120,13 @@ fun String.coarsenAsPython(): String =
}

fun String.uncoarsenAsPython(prompt: String): String {
// println("Before uncoarsening: $this")
val words = prompt.tokenizeAsPython()
val words = prompt.tokenizeByWhitespace()
.filter { it !in pythonKeywords && it.any { it.isLetterOrDigit() }}.toMutableList()
val uncoarsed = tokenizeByWhitespace().joinToString(" ") { token ->
when {
token.isBracket() -> token
token.none { it.isLetterOrDigit() } -> token
token == "w" -> words.removeAt(0)
token == "w" -> words.removeFirst()
token in pythonKeywords -> token
else -> throw Exception("Unknown token: $token")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ fun main() {
syntheticErrorCorrection()
organicErrorCorrection()
// compareParserValidity()
// pythonStatementCFG.blocked.add("w")
// println(pythonStatementCFG.blocked)
// println((pythonStatementCFG as CFGWrapper).cfg.blocked)
}

@OptIn(ExperimentalTime::class)
Expand Down

0 comments on commit 7cd87a9

Please sign in to comment.