Handler

trait Handler[-In, +Out]

An internally-mutable representation of a Parser, which reacts to inputs from a data stream and eventually produces a result.

class Object
trait Matchable
class Any
trait Stateless[In, Out]
class ParserDelay[A]
object ParserDrain.type
class ParserFind[In]
class ParserFirst[In]
class ParserFirstOpt[In]
class ParserPure[Out]
class ParserTap[In]
class Handler[In, Out]
class Handler[In, Out]
class Handler[In, Out]
class Handler[In, A, Out]
class Handler[In, Out]
class Handler[In, Out, Out2]
class Handler[In, Out]
class Handler[In, Out]
class Handler[In, Out]
class TopLevelParserHandler[In, Out]

Value members

Abstract methods

def finish(): Out

Signal the end of the data stream to this handler, forcing it to generate a result. Handlers may throw exceptions in response to this, such as a handler which wants the first event from an empty stream.

Signal the end of the data stream to this handler, forcing it to generate a result. Handlers may throw exceptions in response to this, such as a handler which wants the first event from an empty stream.

Further calls to step or finish after the first call to finish will result in undefined behavior. The general assumption is that a handler should be discarded after its finish method is called.

Returns:

the final result of this parser

def step(in: In): Either[Out, Handler[In, Out]]

Advance the state of this handler by accepting a single input of type In. If doing so would cause this parser to complete, return a Left containing the output. Otherwise, return a Right containing the next parser state.

Advance the state of this handler by accepting a single input of type In. If doing so would cause this parser to complete, return a Left containing the output. Otherwise, return a Right containing the next parser state.

Handlers are assumed to be internally-mutable, so it is acceptable to simply update some internal state and then return Right(this), although in some cases it will be desirable to return a separate handler entirely.

Value parameters:
in

A single input event from a data stream

Returns:

If the input would finish the parser, return a Left containing the result. Otherwise, return a Right containing a Handler which represents the next parsing state. The handler in a Right may be this handler, or a completely separate one.

Concrete methods

Wraps this handler as a "top level" handler, which will inject a SpacTraceElement (representing the current input or the "EOF" signal) to any exception is thrown by this handler when calling its step or finish methods.

Wraps this handler as a "top level" handler, which will inject a SpacTraceElement (representing the current input or the "EOF" signal) to any exception is thrown by this handler when calling its step or finish methods.

Used internally by Parser's parse methods.

def stepMany[C[_], In2 <: In](inputs: C[In2])(implicit C: Unconsable[C]): Either[(Out, C[In2]), Handler[In, Out]]

Convenience function to call step on a sequence of inputs all at once. If the step returns a result, this method will return a Left containing that result and the remainder of the inputs that were not consumed. If the inputs run out before the handler returns a result from a step, this method will return a Right containing the latest state of the handler. This method will not call the handler's finish().

Convenience function to call step on a sequence of inputs all at once. If the step returns a result, this method will return a Left containing that result and the remainder of the inputs that were not consumed. If the inputs run out before the handler returns a result from a step, this method will return a Right containing the latest state of the handler. This method will not call the handler's finish().

In general, you won't call this method directly. Instead, use one of the Parser trait's parse methods.

Type parameters:
C

An Unconsable collection, i.e. List or cats.data.Chain

In2

Subtype of In, or In (to satisfy contravariance)

Value parameters:
C

Evidence that the inputs has a head/tail split operation

inputs

A sequence of inputs

Returns:

Either the handler's result paired with the remaining inputs, or the new handler state