ClausesParser

interface ClausesParser

Parses Prolog source into clauses or a Theory.

This layer converts the concrete syntax produced by parser-impl into tuProlog clauses. Each clause gets a fresh variable scope. Recognized op/3 goals update the session operator table only after their containing clause has been parsed, so they affect subsequent clauses but never the directive that declares them. Low-level syntax failures and invalid operator declarations are exposed as it.unibo.tuprolog.core.parsing.ParseException, whose clauseIndex identifies the zero-based failing clause:

val parser = ClausesParser.withStandardOperators()
val theory =
parser.parseTheory(
"""
:- op(900, xfy, '::').
parent(alice, bob).
ancestor(X, Y) :- parent(X, Y).
1 :: 2 :: nil.
""".trimIndent(),
)

Here :: is only usable as an infix operator starting from the clause that follows the op/3 directive. To parse a single term or clause instead of a whole theory, use it.unibo.tuprolog.core.parsing.TermParser.

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard

Initial operator set used when no explicit set is supplied.

Functions

Link copied to clipboard
open fun parseClauses(input: String): List<Clause>

open fun parseClauses(input: String, operators: OperatorSet): List<Clause>

Parses all clauses from input eagerly using operators.

Link copied to clipboard

abstract fun parseClausesLazily(input: String, operators: OperatorSet): Sequence<Clause>

Returns a single-consumer sequence that parses clauses from input using operators.

Link copied to clipboard
open fun parseTheory(input: String): Theory

open fun parseTheory(input: String, operators: OperatorSet): Theory

Parses input using operators and the default unificator.

open fun parseTheory(input: String, unificator: Unificator): Theory
open fun parseTheory(input: String, operators: OperatorSet, unificator: Unificator): Theory

Parses input eagerly into an indexed theory using operators and unificator.