From 7cd87a9214c030bf3af7037d4787a5c4b990b1ad Mon Sep 17 00:00:00 2001 From: breandan Date: Fri, 21 Apr 2023 23:51:15 -0400 Subject: [PATCH] cache hashCode for frozen CFGs --- galoisenne | 2 +- .../mcgill/cstk/experiments/repair/OrganicSyntaxRepair.kt | 7 +++---- .../cstk/experiments/repair/PythonStatementRepair.kt | 3 +++ 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/galoisenne b/galoisenne index bcc1faf2..8815925a 160000 --- a/galoisenne +++ b/galoisenne @@ -1 +1 @@ -Subproject commit bcc1faf2a547daf35287acbf2a016bada5788527 +Subproject commit 8815925a05045e002da9b8d069c9b3bbc27a1ad2 diff --git a/src/main/kotlin/edu/mcgill/cstk/experiments/repair/OrganicSyntaxRepair.kt b/src/main/kotlin/edu/mcgill/cstk/experiments/repair/OrganicSyntaxRepair.kt index 2c7c0ea1..9f9a74b3 100644 --- a/src/main/kotlin/edu/mcgill/cstk/experiments/repair/OrganicSyntaxRepair.kt +++ b/src/main/kotlin/edu/mcgill/cstk/experiments/repair/OrganicSyntaxRepair.kt @@ -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")) } @@ -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") } diff --git a/src/main/kotlin/edu/mcgill/cstk/experiments/repair/PythonStatementRepair.kt b/src/main/kotlin/edu/mcgill/cstk/experiments/repair/PythonStatementRepair.kt index b9b0a9f1..ca3f6747 100644 --- a/src/main/kotlin/edu/mcgill/cstk/experiments/repair/PythonStatementRepair.kt +++ b/src/main/kotlin/edu/mcgill/cstk/experiments/repair/PythonStatementRepair.kt @@ -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)