molecule.parsing

Parser

abstract class Parser[A, +B] extends AnyRef

Incremental parser

A

the type of the input messages accepted by a parser B the type of the result

Self Type
Parser[A, B]
Source
Parser.scala
Linear Supertypes
AnyRef, Any
Known Subclasses
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. Hide All
  2. Show all
  1. Parser
  2. AnyRef
  3. Any
Visibility
  1. Public
  2. All

Instance Constructors

  1. new Parser()

Type Members

  1. type Res = ParseResult[B, A]

    Attributes
    protected

Abstract Value Members

  1. abstract def apply(seg: Seg[A]): ParseResult[B, A]

    Apply this parser to the next segment.

    Apply this parser to the next segment.

    seg

    the segment to parse for the next message

    returns

    a parse result

  2. abstract def name: String

    The name of this parser (used for debugging)

    The name of this parser (used for debugging)

    returns

    name of this parser

  3. abstract def result(signal: Signal): Option[Either[Fail, Done[B, A]]]

    Request result because there is no more data

Concrete Value Members

  1. final def !=(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  2. final def !=(arg0: Any): Boolean

    Definition Classes
    Any
  3. final def ##(): Int

    Definition Classes
    AnyRef → Any
  4. def *(implicit parsers: Parsers[A]): Parser[A, Seg[B]]

    Returns a parser that repeatedly parses what this parser parses

    Returns a parser that repeatedly parses what this parser parses

    returns

    rep(this)

  5. def +(implicit parsers: Parsers[A]): Parser[A, Seg[B]]

    Returns a parser that repeatedly (at least once) parses what this parser parses.

    Returns a parser that repeatedly (at least once) parses what this parser parses.

    returns

    rep1(this)

  6. def <~[U](p: ⇒ Parser[A, U]): Parser[A, B]

    A parser combinator for sequential composition which keeps only the left result

    A parser combinator for sequential composition which keeps only the left result

    p <~ q' succeeds if p' succeeds and q' succeeds on the input left over by p'.

    Note: <~ has lower operator precedence than ~ or ~>.

    returns

    a Parser' that -- on success -- returns the result of p'.

  7. final def ==(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  8. final def ==(arg0: Any): Boolean

    Definition Classes
    Any
  9. def ?(implicit parsers: Parsers[A]): Parser[A, Option[B]]

    Returns a parser that optionally parses what this parser parses.

    Returns a parser that optionally parses what this parser parses.

    returns

    opt(this)

  10. def ^^[U](f: (B) ⇒ U): Parser[A, U]

    A parser combinator for function application

    A parser combinator for function application

    p ^^ f' succeeds if p' succeeds; it returns f' applied to the result of p'.

    f

    a function that will be applied to this parser's result (see map' in ParseResult').

    returns

    a parser that has the same behaviour as the current parser, but whose result is transformed by f'.

  11. def ^^^[U](r: U): Parser[A, U]

    A parser combinator for substituting a result with another

    A parser combinator for substituting a result with another

    p ^^^ r' succeeds if p' succeeds; it returns r'

    r

    the substitution result

    returns

    a parser that has the same behaviour as the current parser, but whose result is replaced by r'.

  12. final def asInstanceOf[T0]: T0

    Definition Classes
    Any
  13. def clone(): AnyRef

    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws()
  14. def collect[C](f: PartialFunction[B, C]): Parser[A, C]

  15. def contraMap[Z](g: (Z) ⇒ A, consume: (Z, A) ⇒ Z): Parser[Z, B]

    transforms this of type Parser[A,B] into a parser of type Parser[Z,B].

    transforms this of type Parser[A,B] into a parser of type Parser[Z,B].

    g

    function that maps a message of type Z into a message of type A. Given an input stream ichan: IChan[Z] and a parser: Parser[A,B], the stream transformation ichan.parse(parser.contraMap(g,h)) is equivalent to ichan.map(g).parse(parser). The reason for contraMap is to be able to apply g until a first parsed result on a input:Input[Z]; input.read(parser.contraMap(g,h)) will leave, after reading the first parsed result, the stream untouched and of type Z, so one map want to apply another parser of type Parser[Z,C] afterwards.

    consume

    function to generate a partially consumed message type Z in case the inverse function of g does not exists. A parser may partially consume a message of an input stream. So if this leaves a partially consumed message of type A on the stream, an equally consumed message of type Z will generated with function consume. In the function consume(z:A,a:A):Z, z is the message to be partially consumed, a is the partially consume value of g(z); the return value must be the partially consume z such that g( consume(z,a) ) == a and when g(z) == a than consume(z,a) == z If consume is not correctly specified, the contraMapped parser may give unexpected results in case of partially consumed messages.

    returns

    a contraMapped parser

  16. def contraMapReversible[Z](g: (Z) ⇒ A, h: (A) ⇒ Z): Parser[Z, B]

    transforms this of type Parser[A,B] into a parser of type Parser[Z,B].

    transforms this of type Parser[A,B] into a parser of type Parser[Z,B].

    g

    function that maps a message of type Z into a message of type A. Given an input stream ichan: IChan[Z] and a parser: Parser[A,B], the stream transformation ichan.parse(parser.contraMap(g,h)) is equivalent to ichan.map(g).parse(parser). The reason for contraMap is to be able to apply g until a first parsed result on a input:Input[Z]; input.read(parser.contraMap(g,h)) will leave, after reading the first parsed result, the stream untouched and of type Z, so one map want to apply another parser of type Parser[Z,C] afterwards.

    h

    inverse function of g. A parser may partially consume a message of an input stream. So if this leaves a partially consumed message of type A on the stream, that message will be reverse mapped to Z with function h. If h(g(a)) is not equal to a, the contraMapped parser may give unexpected results in case of partially consumed messages. In case the function h is not defined, one must use contraMap[Z](g: Z => A, consume:(Z,A) => Z): Parser[Z, B].

    returns

    a contraMapped parser

  17. final def eq(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  18. def equals(arg0: Any): Boolean

    Definition Classes
    AnyRef → Any
  19. final def filter(p: (B) ⇒ Boolean): Parser[A, B]

    Filter results of this parser.

    Filter results of this parser.

    p

    predicate that returns true for results accepted by this parser

    returns

    a filtered parser

  20. def finalize(): Unit

    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws()
  21. def flatMap[C](f: (B) ⇒ Parser[A, C]): Parser[A, C]

    Sequence with a second parsers only after this one produced a result.

    Sequence with a second parsers only after this one produced a result.

    returns

    the resulting parser

  22. final def getClass(): java.lang.Class[_]

    Definition Classes
    AnyRef → Any
  23. def hashCode(): Int

    Definition Classes
    AnyRef → Any
  24. final def isInstanceOf[T0]: Boolean

    Definition Classes
    Any
  25. final def map[C](f: (B) ⇒ C): Parser[A, C]

    Map the result of this parser to another result C

  26. final def ne(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  27. final def notify(): Unit

    Definition Classes
    AnyRef
  28. final def notifyAll(): Unit

    Definition Classes
    AnyRef
  29. final def result(seg: Seg[A], signal: Signal): Option[Either[Fail, Done[B, A]]]

    Apply this parser to the last segment.

    Apply this parser to the last segment.

    seg

    the segment to parse for a new message

    signal

    the signal accompanying the last segment

    returns

    Nothing if there is no new message left. Some Fail or Done depending on if the last parse failed or succeeded.

  30. final def synchronized[T0](arg0: ⇒ T0): T0

    Definition Classes
    AnyRef
  31. def toString(): String

    Definition Classes
    AnyRef → Any
  32. final def wait(): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws()
  33. final def wait(arg0: Long, arg1: Int): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws()
  34. final def wait(arg0: Long): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws()
  35. def |[U >: B](alternative: ⇒ Parser[A, U]): Parser[A, U]

    A parser combinator for alternative composition

    A parser combinator for alternative composition

    p | q' succeeds if p' succeeds or q' succeeds Note that q' is only tried if p's failure is non-fatal (i.e., back-tracking is allowed).

    returns

    a Parser' that returns the result of the first parser to succeed (out of p' and q') The resulting parser succeeds if (and only if)

    • p' succeeds, or
    • if p' fails allowing back-tracking and q' succeeds.
  36. def ~[U](p: ⇒ Parser[A, U]): Parser[A, ~[B, U]]

    A parser combinator for sequential composition

    A parser combinator for sequential composition

    p ~ q' succeeds if p' succeeds and q' succeeds on the input left over by p'.

    returns

    a Parser' that -- on success -- returns a ~' (like a Pair, but easier to pattern match on) that contains the result of p' and that of q'. The resulting parser fails if either p' or q' fails.

  37. def ~>[U](p: ⇒ Parser[A, U]): Parser[A, U]

    A parser combinator for sequential composition which keeps only the right result

    A parser combinator for sequential composition which keeps only the right result

    p ~> q' succeeds if p' succeeds and q' succeeds on the input left over by p'.

    returns

    a Parser' that -- on success -- returns the result of q'.

Inherited from AnyRef

Inherited from Any