JsonParserTypedFirst

class JsonParserTypedFirst[A](expected: String, f: JsonEvent => Option[A]) extends Parser[JsonEvent, A]
Companion
object
trait Parser[JsonEvent, A]
class Object
trait Matchable
class Any

Document{}

def toPipe[F[_]](pos: CallerPos): (F, JsonEvent) => A

Convert this parser to a FS2 "Pipe". The resulting pipe will forward inputs from the upstream into this parser, emitting a single value to the downstream when this parser finishes. Since a Parser may abort early (e.g. with Parser.first), the pipe may not pull the entire input stream.

Convert this parser to a FS2 "Pipe". The resulting pipe will forward inputs from the upstream into this parser, emitting a single value to the downstream when this parser finishes. Since a Parser may abort early (e.g. with Parser.first), the pipe may not pull the entire input stream.

Inherited from
Parser
def map[Out2](f: A => Out2): Parser[JsonEvent, Out2]

Create a copy of this Parser whose result is transformed by the given function f.

Create a copy of this Parser whose result is transformed by the given function f.

Type Params
Out2

The new parser's result type

Value Params
f

Result transformation function

Inherited from
Parser
def interruptedBy[I2 <: JsonEvent](interrupter: Parser[I2, Any]): Parser[I2, A]

Create a copy of this parser that will treat a result from the interrupter as an early EOF. This is especially useful for creating followedBy chains involving optional elements.

Create a copy of this parser that will treat a result from the interrupter as an early EOF. This is especially useful for creating followedBy chains involving optional elements.

Normally, a parser for an optional item in some context will not finish until that context ends, or until the item is encountered. So if the item is not present, followedBy logic won't work since the followUp parser/transformer will not see any events.

To make sure the leading parser can "fail fast", you can "interrupt" it, typically by creating a parser that immediately returns a result upon entering a particular context, i.e. the context in which the "following" parser will start. Parser#beforeContext provides a convenience for doing so.

Note that if the interrupter throws an exception, that exception will not be caught. If your interrupter might throw, pass interrupter.wrapSafe instead to swallow the exception.

Type Params
I2

Subtype of In, or just In (to satisfy contravariance of Parser's In type)

Value Params
interrupter

A parser which will be run in parallel with this parser, and whose result will be treated as an early EOF for this parser, forcing an early call to finish().

Returns

A parser which will perform an early finish() call when the interrupter produces a result.

Inherited from
Parser
def rethrow[T](ev: A <:< Either[Throwable, T]): Parser[JsonEvent, T]

Like unwrapSafe, but rethrows exceptions from Left or returns results from Right. This operation is the opposite of attempt.

Like unwrapSafe, but rethrows exceptions from Left or returns results from Right. This operation is the opposite of attempt.

Inherited from
Parser
def attempt: Parser[JsonEvent, Either[Throwable, A]]

Like wrapSafe, but represents exceptions as Left and successful results as Right

Like wrapSafe, but represents exceptions as Left and successful results as Right

Inherited from
Parser
def asTransformer: Transformer[JsonEvent, A]

Represent this parser as a Transformer which emits this parser's result

Represent this parser as a Transformer which emits this parser's result

Inherited from
Parser
@throws(scala.throws.$lessinit$greater$default$1[io.dylemma.spac.SpacException[_ >: scala.Nothing <: scala.Any]])
def parse[S](source: S)(S: Parsable[Id, S, JsonEvent], pos: CallerPos): A

Interpret the given source as a data stream of type In, using this parser to produce a result of type Out. Exceptions thrown by the underlying parser logic will bubble up and be thrown by this method.

Interpret the given source as a data stream of type In, using this parser to produce a result of type Out. Exceptions thrown by the underlying parser logic will bubble up and be thrown by this method.

Type Params
S

The source type. Will typically be a File or a List[In].

Value Params
S

Typeclass instance that provides the logic for feeding values from source into this parser

pos

Captures the caller filename and line number, used to fill in the 'spac trace' if the parser throws an exception

source

The source of a data stream

Inherited from
Parser
def withName(name: String): Parser[JsonEvent, A]

Creates a copy of this parser, but with a different toString

Creates a copy of this parser, but with a different toString

Value Params
name

The new "name" (i.e. toString) for this parser

Returns

A copy of this parser whose toString returns the given name

Inherited from
Parser
def unwrapSafe[T](ev: A <:< Try[T]): Parser[JsonEvent, T]

Creates a copy of this parser which unwraps the resulting Try, throwing an exception if the result was a Failure. This operation is the opposite of wrapSafe.

Creates a copy of this parser which unwraps the resulting Try, throwing an exception if the result was a Failure. This operation is the opposite of wrapSafe.

Inherited from
Parser
def wrapSafe: Parser[JsonEvent, Try[A]]

Create a copy of this Parser whose handler will catch NonFatal exceptions thrown by the underlying logic. Caught exceptions will be yielded as a Failure output. Normal results will be wrapped in Success.

Create a copy of this Parser whose handler will catch NonFatal exceptions thrown by the underlying logic. Caught exceptions will be yielded as a Failure output. Normal results will be wrapped in Success.

Returns

A copy of this parser that will return a Failure instead of throwing exceptions

Inherited from
Parser
def expectInputs[I2 <: JsonEvent](expectations: List[(String, I2 => Boolean)]): Parser[I2, A]

Impose expectations on the sequence of inputs to be received by handlers created by this parser. As this parser's handler receives an input, the input will be tested against the head of the expectations list. If the test returns false, the expectation is failed and the handler will throw an exception. If the test returns true, the expectation is satisfied, and the handler will advance to the next expectation. If there are no more expectations left in the list (i.e. N inputs have satisfied the corresponding N expectations), then all expectations have been met and inputs will be treated as normal by the handler. If the handler receives an EOF before all expectations are met, it will throw an exception.

Impose expectations on the sequence of inputs to be received by handlers created by this parser. As this parser's handler receives an input, the input will be tested against the head of the expectations list. If the test returns false, the expectation is failed and the handler will throw an exception. If the test returns true, the expectation is satisfied, and the handler will advance to the next expectation. If there are no more expectations left in the list (i.e. N inputs have satisfied the corresponding N expectations), then all expectations have been met and inputs will be treated as normal by the handler. If the handler receives an EOF before all expectations are met, it will throw an exception.

Value Params
expectations

A sequence of label -> test expectations imposed on inputs to this parser

Returns

A copy of this parser with expectations imposed on its inputs

Inherited from
Parser
def orElse[In2 <: JsonEvent, Out2 >: A](fallback: Parser[In2, Out2]): Parser[In2, Out2]

Combine this parser with the fallback such that failures from the underlying parsers will be ignored as long as at least one succeeds. The result will be the result of whichever underlying parser succeeds first. If all of the underlying parsers fail, a SpacException.FallbackChainFailure will be thrown by the returned parser's handler.

Combine this parser with the fallback such that failures from the underlying parsers will be ignored as long as at least one succeeds. The result will be the result of whichever underlying parser succeeds first. If all of the underlying parsers fail, a SpacException.FallbackChainFailure will be thrown by the returned parser's handler.

Type Params
In2

Subtype of In, or just In (to satisfy Parser's contravariance on the In type)

Out2

Supertype of Out, or just Out (to satisfy Parser's covariance on the Out type)

Value Params
fallback

another parser of the same(ish) type as this one

Returns

A new parser that will succeed if either this parser or the fallback succeed

Inherited from
Parser
def beforeContext[I2 <: JsonEvent, StackElem](matcher: ContextMatcher[StackElem, Any])(stackable: StackLike[I2, StackElem], pos: CallerPos): Parser[I2, A]

Specialization of interruptedBy for stack-like input types, such that an interruption will occur upon entering a stack context that can be matched by the given matcher.

Specialization of interruptedBy for stack-like input types, such that an interruption will occur upon entering a stack context that can be matched by the given matcher.

Example:

val preludeContext = * \ "prelude"
val dataContext = * \ "data"
for {
 prelude <- Splitter(preludeContext).firstOption[Prelude].beforeContext(dataContext).followedByStream
 data <- Splitter(dataContext).as[Data]
} yield data
Type Params
I2

Subtype of In, or just In (to satisfy contravariance of Parser's In type)

StackElem

Specialization of the In type for when it represents a stack push or pop

Value Params
matcher

A matching function that operates on a context stack

stackable

Interprets the inputs as stack push/pop events to accumulate a context stack

Returns

A parser which will perform an early finish() when a matching context is encountered

Inherited from
Parser
def upcast[Out2](ev: A <:< Out2): Parser[JsonEvent, Out2]

Returns this parser, with the output type widened to Out2, which is some supertype of Out. Uses asInstanceOf rather than creating a new parser.

Returns this parser, with the output type widened to Out2, which is some supertype of Out. Uses asInstanceOf rather than creating a new parser.

Inherited from
Parser

Value members

Concrete methods

def newHandler: Handler[JsonEvent, A]