ParserFollowedByOps

implicit class ParserFollowedByOps[In, A](parser: Parser[In, A])

Adds followedBy and followedByStream to Parser (they aren't defined in the Parser trait due to the In type needing to be invariant here)

class Object
trait Matchable
class Any

Value members

Concrete methods

Intermediate object for creating a sequenced parser in which the result of this parser will be used to initialize a second parser as soon as it is available.

Intermediate object for creating a sequenced parser in which the result of this parser will be used to initialize a second parser as soon as it is available.

In other words, the source (series of In values) will be fed into this Parser until this parser's handler returns a result of type Out. At that point, the second parser (as specified by using the apply or flatMap methods on the FollowedBy returned by this method) will be instantiated. Any relevant "stack events" (see Stackable) will be replayed so the second parser has the right context, and from that point on, all In values will be sent to the second parser. When that second parser returns a result, that result becomes the output of the combined parser created by this.followedBy(out => makeSecondParser(out))

Examples:

  val p1: Parser[A] = /* ... */
  def getP2(p1Result: A): Parser[B] = /* ... */
  val combined: Parser[B] = p1.followedBy(getP2)

  // alternative `flatMap` syntax
  val combined: Parser[B] = for {
    p1Result <- p1.followedBy
    p2Result <- getP2(p1Result)
  } yield p2Result

See Parser's interruptedBy, which is useful when a transformer.parseFirstOption must be followedBy some other parser.

Alias for followedBy, for use when Cat's ApplyOps gets in the way with its own useless followedBy method.

Alias for followedBy, for use when Cat's ApplyOps gets in the way with its own useless followedBy method.

Intermediate object creating a transformer that depends on this parser. Particularly useful in cases where one or more specific "info" elements precede a stream of other elements which require that "info" to be parsed.

Intermediate object creating a transformer that depends on this parser. Particularly useful in cases where one or more specific "info" elements precede a stream of other elements which require that "info" to be parsed.

Examples:

  val p1: Parser[In, A] = /* ... */
  def getP2Stream(p1Result: A): Transformer[In, B] = /* ... */
  val combined: Transformer[In, B] = p1.andThenStream(getP2Stream)

  // alternative `flatMap` syntax
  val combined: Transformer[In, B] = for {
    p1Result <- p1.andThenStream
    p2Result <- getP2Stream(p1Result)
  } yield p2Result

See followedBy for a general explanation of how the combination works.

See also, interruptedBy, which is useful when a transformer.parseFirstOption must be followedBy some other transformer.