Package-level declarations

Types

Link copied to clipboard

An implementation of StateCallback that composes two other state callbacks. Consider that we were only dealing with regular functions, this would give:

Link copied to clipboard
class EitherBranch<T>(val expectations: List<Expectation<T, *>>)

A branch for the ExpectedEither expectation.

Link copied to clipboard
abstract class Expectation<T, in R>(val stateCallback: StateCallback<T, R, *>? = null)

General class for an expectation.

Link copied to clipboard

An expectation that takes the result of some branches.

Link copied to clipboard
class ExpectedEmitConstant<T, R>(value: R, stateCallback: StateCallback<T, R, *>?) : Expectation<T, R> , HandlesTokenDrought

An expectation that always matches and always emits the provided value.

Link copied to clipboard

An expectation that only matches if the current position is the end of the input.

Link copied to clipboard

A "look-ahead" branch. Similar to lookaheads in regular expressions, ExpectedLookahead will verify expectations, but not advanced the "cursor" to the next token. You can think of it as check against "what will come next", while staying where we are.

Link copied to clipboard
class ExpectedNode<T, R>(node: ParserNodeDeclaration<R>, stateCallback: StateCallback<T, R, *>? = null) : Expectation<T, R>

An expectation that expects another node to be present at this point.

Link copied to clipboard

An optional branch. This expectation is always met (always returns a success), even when we have run out of tokens.

Link copied to clipboard
class ExpectedRepeated<T, R>(minIterations: Int?, maxIterations: Int?, repeatableExpectations: List<Expectation<RepeatedItemReceiver<R>, *>>, stateCallback: StateCallback<T, List<R>, *>?) : Expectation<T, List<R>> , HandlesTokenDrought

A repeated branch that runs 0+ iterations of some expectations and collects the results into a list. Said list can then be stored in the model results.

Link copied to clipboard
class ExpectedToken<T>(tokenType: TokenType, withValue: String? = null, stateCallback: StateCallback<T, String, *>? = null) : Expectation<T, String>

An expectation that expects a token to be present at this point.

Link copied to clipboard

When an expectation is also of type HandlesTokenDrought, it means that the expectation should be called even when running out of tokens.

Link copied to clipboard
data class NodeParameterKey<in T, in R>(val outputType: KType, val name: String)

A key used when storing state within Niwen parsers.

Link copied to clipboard
data class RawKey(val outputType: KType, val name: String)

An escape hatch for NodeParameterKey's harsh typing restrictions.

Link copied to clipboard

Receiver interface for the content of a repeated { } block.

Link copied to clipboard
fun interface StateCallback<T, in R, U>

A callback for manipulating and invoking side effects with state information.

Link copied to clipboard
class StoreStateCallback<T, R>(storeValueIn: NodeParameterKey<T, R>) : StateCallback<T, R, R>

An implementation of StateCallback that stores values in the key specified in storeValueIn.

Link copied to clipboard
class TransformStateCallback<T, R, U>(transformer: (R) -> U) : StateCallback<T, R, U>

An implementation of StateCallback that transforms incoming state using the provided transformer.

Functions

Link copied to clipboard

Create a NodeParameterKey for the provided property.

Link copied to clipboard
fun <T, R> StateCallback<T, R, *>?.createStoreMap(value: R): Map<NodeParameterKey<T, *>, Any?>

Create a store map and evaluate this state callback. The map is returned.

Link copied to clipboard
inline fun <T, R> key(name: String): NodeParameterKey<T, R>

Create a NodeParameterKey from the provided name and types.

Link copied to clipboard
fun <T, R> StateCallback<T, R, *>?.withStoreMap(value: R, currIndex: Int, handler: (Map<NodeParameterKey<T, *>, Any?>) -> ExpectationResult<T>): ExpectationResult<T>

Create a store map (using createStoreMap) and call the provided handler, returning an ExpectationResult.