buildParserFor

fun <T> buildParserFor(source: SourceText, lexerOptions: LexerOptions = LexerOptions(), parserOptions: ParserOptions = ParserOptions(), continuation: (PrologParser, LexedSource) -> T): T

Creates the default lexer and parser for source, then invokes continuation with both.

This helper does not translate exceptions thrown by lexing, parsing, or continuation.

Return

the value returned by continuation

Throws


fun <T> buildParserFor(source: TextChunkSource, lexerOptions: LexerOptions = LexerOptions(), parserOptions: ParserOptions = ParserOptions(), continuation: (PrologParser, LexedSource) -> T): T

Creates the default lexer and parser for a synchronous chunk source.

Input remains lazy and is pulled only when continuation requests tokens.

Return

the value returned by continuation

Throws

if reading, lexing, or parsing requested input fails


fun <T> buildParserFor(input: String, id: String? = null, lexerOptions: LexerOptions = LexerOptions(), parserOptions: ParserOptions = ParserOptions(), continuation: (PrologParser, LexedSource) -> T): T

Creates the default lexer and parser for input, identified diagnostically by id.

val tree = buildParserFor("f(X).", id = "query") { parser, source ->
parser.parseClause(source)
}

Return

the value returned by continuation

Throws

fun <T> buildParserFor(input: Reader, chunkSize: Int = DEFAULT_READER_CHUNK_SIZE, autoClose: Boolean = true, lexerOptions: LexerOptions = LexerOptions(), parserOptions: ParserOptions = ParserOptions(), continuation: (PrologParser, LexedSource) -> T): T

Creates a lazy lexer and parser over input, then invokes continuation.

FileReader("program.pl").use { reader ->
buildParserFor(reader, autoClose = false) { parser, source ->
parser.parseTheory(source)
}
}

autoClose controls whether EOF closes input. Reading and lexing still occur only as tokens are requested by continuation.

Return

the value returned by continuation

Throws

if reading, lexing, or parsing requested input fails