Preprocessing

This commit is contained in:
Tibo De Peuter 2025-04-27 22:02:50 +02:00
parent 82a8fccf87
commit 174855d7a3
Signed by: tdpeuter
GPG key ID: 38297DE43F75FFE2
5 changed files with 284 additions and 7 deletions

View file

@ -1,5 +1,6 @@
package repl
import interpreter.Preprocessor
import io.Logger
import io.Terminal
import parser.ReplParser
@ -9,6 +10,7 @@ import prolog.Answers
class Repl {
private val io = Terminal()
private val parser = ReplParser()
private val preprocessor = Preprocessor()
fun start() {
io.say("Prolog REPL. Type '^D' to quit.\n")
@ -23,7 +25,8 @@ class Repl {
fun query(): Answers {
val queryString = io.prompt("?-", { "" })
val query = parser.parse(queryString)
val simpleQuery = parser.parse(queryString)
val query = preprocessor.preprocess(simpleQuery)
return query.satisfy(emptyMap())
}
@ -46,7 +49,10 @@ class Repl {
}
when (command) {
";" -> previous = iterator.next()
";" -> {
previous = iterator.next()
io.say(prettyPrint(previous))
}
"a" -> return
"." -> return
"h" -> {
@ -55,8 +61,6 @@ class Repl {
}
}
}
io.say(prettyPrint(previous))
}
io.say("\n")