TuPrologCmd

class TuPrologCmd(additionalLibraries: Library) : AbstractTuPrologCommand

Root clikt command of the 2P-Kt REPL: java -jar 2p-repl.jar.

Run with no subcommand, it starts an interactive Prolog read-eval-print loop: it builds a it.unibo.tuprolog.solve.Solver (see getSolver), repeatedly prompts the user for a dot-terminated query with ?- (see AbstractTuPrologCommand.readQuery), parses it with it.unibo.tuprolog.core.Struct.Companion.parse, solves it, and prints the resulting solutions -- until the standard input stream is closed, at which point it prints a farewell message and exits.

Supported options (see the corresponding property for details): -T/--theory (repeatable, one or more theory files to load into the static KB), -t/--timeout (per-query solving timeout, in milliseconds), and --oop (also load :oop-lib's it.unibo.tuprolog.solve.libs.oop.OOPLib). The solve subcommand (TuPrologSolveQuery) reuses the same solver to evaluate a single query non-interactively instead.

The solver is always built with :io-lib's it.unibo.tuprolog.solve.libs.io.IOLib loaded (for write/1, nl/0, file inclusion, and the like -- see IOLib's own KDoc for the full predicate list), on top of it.unibo.tuprolog.solve.classic.ClassicSolverFactory's ISO-standard resolution engine (via it.unibo.tuprolog.solve.Solver.Companion.prolog).

Parameters

additionalLibraries

extra Library instances to load into the solver alongside IOLib (and OOPLib when --oop is given), e.g. for an embedder that wants to expose custom predicates through this same CLI.

Constructors

Link copied to clipboard
constructor(vararg additionalLibraries: Library)

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
Link copied to clipboard
open override val autoCompleteEnvvar: String?
Link copied to clipboard
Link copied to clipboard
val currentContext: Context
Link copied to clipboard
open override val helpTags: Map<String, String>
Link copied to clipboard
open override val hiddenFromHelp: Boolean
Link copied to clipboard
open override val invokeWithoutSubcommand: Boolean
Link copied to clipboard
Link copied to clipboard
open override val printHelpOnEmptyArgs: Boolean
Link copied to clipboard

Functions

Link copied to clipboard
open fun aliases(): Map<String, List<String>>
Link copied to clipboard
open fun allHelpParams(): List<HelpFormatter.ParameterHelp>
Link copied to clipboard
open fun commandHelp(context: Context): String
Link copied to clipboard
open fun commandHelpEpilog(context: Context): String
Link copied to clipboard
fun configureContext(block: Context.Builder.() -> Unit)
Link copied to clipboard
fun echo()
fun echo(message: Any?, trailingNewline: Boolean, err: Boolean)
Link copied to clipboard
fun echoFormattedHelp(error: CliktError?)
Link copied to clipboard
fun getFormattedHelp(error: CliktError?): String?
Link copied to clipboard

Builds a fresh Solver according to this command's options: it loads and merges every theory file given via -T/--theory (skipping any that isReadableFile deems unreadable, and reporting a it.unibo.tuprolog.core.parsing.ParseException for any that fails to parse) into the static knowledge base, always loads :io-lib's it.unibo.tuprolog.solve.libs.io.IOLib plus this command's additionalLibraries, additionally loads :oop-lib's it.unibo.tuprolog.solve.libs.oop.OOPLib when --oop was given, enables the it.unibo.tuprolog.solve.flags.TrackVariables flag, and routes solve warnings to the terminal (with their logic stack trace). As a side effect, it echoes the 2P-Kt version and the alias of each loaded library to standard output.

Link copied to clipboard

The -t/--timeout option's value (milliseconds, defaulting to DEFAULT_TIMEOUT), converted to the TimeDuration expected by it.unibo.tuprolog.solve.Solver.solve. Exposed so TuPrologSolveQuery can reuse the same timeout its parent command was configured with.

Link copied to clipboard
open override fun help(context: Context): String
Link copied to clipboard
open override fun helpEpilog(context: Context): String
Link copied to clipboard
fun issueMessage(message: String)
Link copied to clipboard
fun registerArgument(argument: Argument)
Link copied to clipboard
fun registeredArguments(): List<Argument>
Link copied to clipboard
fun registeredOptions(): List<Option>
Link copied to clipboard
fun registeredParameterGroups(): List<ParameterGroup>
Link copied to clipboard
fun registeredSubcommands(): List<CoreCliktCommand>
Link copied to clipboard
open override fun registerOption(option: GroupableOption)
fun registerOption(option: Option)
Link copied to clipboard
fun registerOptionGroup(group: ParameterGroup)
Link copied to clipboard
fun resetContext(parent: Context?): Context
Link copied to clipboard
open override fun run()

Builds a solver (see getSolver) and, if no subcommand was invoked on the command line, starts the interactive read-eval-print loop with it. When a subcommand (e.g. solve) was invoked instead, clikt dispatches to that subcommand's own run after this method returns, reusing the solver built here through getSolver/getTimeout.

Link copied to clipboard
open override fun toString(): String