PrologParser

interface PrologParser

Parses a LexedSource into an immutable, lossless concrete syntax tree.

Structural syntax is handled by predictive recursive descent, while dynamic prefix, infix, and postfix expressions use precedence climbing in the style of Pratt's top-down operator-precedence parser. Prolog's seven operator specifiers and their x/y operand constraints follow ISO/IEC 13211-1.

Implementations are stateless and reusable. Inputs, operator tables, and sessions may be stateful and are not intended for concurrent access.

See also

Types

Link copied to clipboard
object Companion

Functions

Link copied to clipboard
fun PrologParser.openFileSession(file: Any, initialOperators: OperatorTable = OperatorTables.empty(), sourceId: String? = file.asDynamic().name as? String, maximumRetainedTokens: Int? = null): SuspendingPrologParseSession

Opens a UTF-8 suspending parse session over a browser File or Blob.

Link copied to clipboard
fun PrologParser.openReadableStreamSession(stream: Any, initialOperators: OperatorTable = OperatorTables.empty(), sourceId: String? = null, maximumRetainedTokens: Int? = null): SuspendingPrologParseSession

Opens a UTF-8 suspending parse session over a JavaScript ReadableStream<Uint8Array>.

Link copied to clipboard
abstract fun openSession(input: LexedSource, initialOperators: OperatorTable = OperatorTables.empty()): PrologParseSession

Opens a clause-by-clause session whose operator table may change between calls.

abstract fun openSession(input: SuspendingTextChunkSource, sourceId: String? = null, initialOperators: OperatorTable = OperatorTables.empty(), maximumRetainedTokens: Int? = null): SuspendingPrologParseSession

Opens a clause-by-clause session over asynchronously supplied text chunks.

Link copied to clipboard
abstract fun parseClause(input: LexedSource, operators: OperatorTable = OperatorTables.empty()): SyntaxTree<ClauseNode>

Parses exactly one clause, including its required terminating full stop.

Link copied to clipboard
abstract fun parseExpression(input: LexedSource, operators: OperatorTable = OperatorTables.empty()): SyntaxTree<ExpressionNode>

Parses one expression, optionally followed by a full stop, and requires EOF afterward.

Link copied to clipboard
abstract fun parseTerm(input: LexedSource, operators: OperatorTable = OperatorTables.empty()): SyntaxTree<TermNode>

Parses one non-operator term, optionally followed by a full stop, and requires EOF afterward.

Link copied to clipboard
abstract fun parseTheory(input: LexedSource, operators: OperatorTable = OperatorTables.empty()): SyntaxTree<TheoryNode>

Parses the complete input as zero or more clauses with a fixed operator table.