Fix double printing
This commit is contained in:
parent
bfb509f41f
commit
1e087c8339
3 changed files with 12 additions and 6 deletions
|
@ -1,11 +1,8 @@
|
|||
import com.sun.org.apache.bcel.internal.util.Args
|
||||
import com.xenomachina.argparser.ArgParser
|
||||
import com.xenomachina.argparser.mainBody
|
||||
import interpreter.FileLoader
|
||||
import io.GhentPrologArgParser
|
||||
import io.Logger
|
||||
import prolog.Program
|
||||
import prolog.ast.logic.Clause
|
||||
import repl.Repl
|
||||
|
||||
fun main(args: Array<String>) = mainBody {
|
||||
|
|
|
@ -2,6 +2,7 @@ package interpreter
|
|||
|
||||
import io.Logger
|
||||
import prolog.ast.arithmetic.Expression
|
||||
import prolog.ast.arithmetic.Integer
|
||||
import prolog.ast.logic.Clause
|
||||
import prolog.ast.logic.Fact
|
||||
import prolog.ast.logic.LogicOperand
|
||||
|
@ -56,6 +57,8 @@ open class Preprocessor {
|
|||
Structure(Atom("fail"), emptyList()) -> Fail
|
||||
Atom("!") -> Cut()
|
||||
Structure(Atom("!"), emptyList()) -> Cut()
|
||||
Atom("inf") -> Integer(Int.MAX_VALUE)
|
||||
Atom("nl") -> Nl
|
||||
is Structure -> {
|
||||
// Preprocess the arguments first to recognize builtins
|
||||
val args = term.arguments.map { preprocess(it) }
|
||||
|
@ -115,6 +118,10 @@ open class Preprocessor {
|
|||
Between(args[0] as Expression, args[1] as Expression, args[2] as Expression)
|
||||
}
|
||||
|
||||
// Other
|
||||
term.functor == "write/1" -> Write(args[0])
|
||||
term.functor == "read/1" -> Read(args[0])
|
||||
|
||||
else -> term
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,19 +24,21 @@ class Repl {
|
|||
}
|
||||
|
||||
fun query(): Answers {
|
||||
val queryString = io.prompt("?-", { "" })
|
||||
val queryString = io.prompt("?-", { "| " })
|
||||
val simpleQuery = parser.parse(queryString)
|
||||
val query = preprocessor.preprocess(simpleQuery)
|
||||
Logger.debug("Satisfying query: $query")
|
||||
return query.satisfy(emptyMap())
|
||||
}
|
||||
|
||||
fun printAnswers(answers: Answers) {
|
||||
val knownCommands = setOf(";", "a", ".", "h")
|
||||
|
||||
if (answers.none()) {
|
||||
val iterator = answers.iterator()
|
||||
|
||||
if (!iterator.hasNext()) {
|
||||
io.say("false.")
|
||||
} else {
|
||||
val iterator = answers.iterator()
|
||||
var previous = iterator.next()
|
||||
io.say(prettyPrint(previous))
|
||||
|
||||
|
|
Reference in a new issue