Packages

o

parsley.cats

combinator

object combinator

This module contains pre-made combinators that are very useful for a variety of purposes, specialised to cats.

In particular, it contains functionality found normally in parsley.combinator, but returning the cats NonEmptyList instead of a regular Scala List.

Source
combinator.scala
Since

1.2.0

Linear Supertypes
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. combinator
  2. AnyRef
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. Protected

Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##: Int
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  4. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  5. def clone(): AnyRef
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.CloneNotSupportedException]) @native()
  6. def endBy1[A](p: Parsley[A], sep: => Parsley[_]): Parsley[NonEmptyList[A]]

    This combinator parses one or more occurrences of p, separated and ended by sep.

    This combinator parses one or more occurrences of p, separated and ended by sep.

    Parses p followed by sep one or more times. The results of the p's, x1 through xn, are returned as NonEmptyList.of(x1, .., xn). If p or sep fails having consumed input, the whole parser fails.

    p

    the parser whose results are collected into a list.

    sep

    the delimiter that must be parsed between every p.

    returns

    a parser that parses p delimited by sep, returning the non-empty list of p's results.

    Example:
    1. scala> ...
      scala> val args = endBy1(int, string(";\n"))
      scala> args.parse("7;\n3;\n2")
      val res0 = Failure(..)
      scala> args.parse("")
      val res1 = Failure(..)
      scala> args.parse("1;\n")
      val res2 = Success(NonEmptyList.of(1))
      scala> args.parse("1;\n2;\n")
      val res3 = Success(NonEmptyList.of(1, 2))
    Since

    1.2.0

  7. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  8. def equals(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef → Any
  9. def finalize(): Unit
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.Throwable])
  10. final def getClass(): Class[_ <: AnyRef]
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  11. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  12. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  13. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  14. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  15. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  16. def sepBy1[A](p: Parsley[A], sep: => Parsley[_]): Parsley[NonEmptyList[A]]

    This combinator parses one or more occurrences of p, separated by sep.

    This combinator parses one or more occurrences of p, separated by sep.

    First parses a p. Then parses sep followed by p until there are no more seps. The results of the p's, x1 through xn, are returned as NonEmptyList.of(x1, .., xn). If p or sep fails having consumed input, the whole parser fails. Requires at least one p to have been parsed.

    p

    the parser whose results are collected into a list.

    sep

    the delimiter that must be parsed between every p.

    returns

    a parser that parses p delimited by sep, returning the non-empty list of p's results.

    Example:
    1. scala> ...
      scala> val args = sepBy1(int, string(", "))
      scala> args.parse("7, 3, 2")
      val res0 = Success(NonEmptyList.of(7, 3, 2))
      scala> args.parse("")
      val res1 = Failure(..)
      scala> args.parse("1")
      val res2 = Success(NonEmptyList.of(1))
      scala> args.parse("1, 2, ")
      val res3 = Failure(..) // no trailing comma allowed
    Since

    1.2.0

  17. def sepEndBy1[A](p: Parsley[A], sep: => Parsley[_]): Parsley[NonEmptyList[A]]

    This combinator parses one or more occurrences of p, separated and optionally ended by sep.

    This combinator parses one or more occurrences of p, separated and optionally ended by sep.

    First parses a p. Then parses sep followed by p until there are no more: if a final sep exists, this is parsed. The results of the p's, x1 through xn, are returned as NonEmptyList.of(x1, .., xn). If p or sep fails having consumed input, the whole parser fails. Requires at least one p to have been parsed.

    p

    the parser whose results are collected into a list.

    sep

    the delimiter that must be parsed between every p.

    returns

    a parser that parses p delimited by sep, returning the non-empty list of p's results.

    Example:
    1. scala> ...
      scala> val args = sepEndBy1(int, string(";\n"))
      scala> args.parse("7;\n3;\n2")
      val res0 = Success(NonEmptyList.of(7, 3, 2))
      scala> args.parse("")
      val res1 = Failure(..)
      scala> args.parse("1")
      val res2 = Success(NonEmptyList.of(1))
      scala> args.parse("1;\n2;\n")
      val res3 = Success(NonEmptyList.of(1, 2))
    Since

    1.2.0

  18. def some[A](p: Parsley[A]): Parsley[NonEmptyList[A]]

    This combinator repeatedly parses a given parser one or more times, collecting the results into a list.

    This combinator repeatedly parses a given parser one or more times, collecting the results into a list.

    Parses a given parser, p, repeatedly until it fails. If p failed having consumed input, this combinator fails. Otherwise when p fails without consuming input, this combinator will return all of the results, x1 through xn (with n >= 1), in a non-empty list: NonEmptyList.of(x1, .., xn). If p was not successful at least one time, this combinator fails.

    p

    the parser to execute multiple times.

    returns

    a parser that parses p until it fails, returning the non-empty list of all the successful results.

    Example:
    1. scala> import parsley.character.string
      scala> import parsley.cats.combinator.some
      scala> val p = some(string("ab"))
      scala> p.parse("")
      val res0 = Failure(..)
      scala> p.parse("ab")
      val res1 = Success(NonEmptyList.of("ab"))
      scala> p.parse("abababab")
      val res2 = Success(NonEmptyList.of("ab", "ab", "ab", "ab"))
      scala> p.parse("aba")
      val res3 = Failure(..)
    Since

    1.2.0

  19. def someTill[A](p: Parsley[A], end: Parsley[_]): Parsley[NonEmptyList[A]]

    This combinator repeatedly parses a given parser one or more times, until the end parser succeeds, collecting the results into a list.

    This combinator repeatedly parses a given parser one or more times, until the end parser succeeds, collecting the results into a list.

    First ensures that trying to parse end fails, then tries to parse p. If it succeed then it will repeatedly: try to parse end, if it fails without consuming input, then parses p, which must succeed. When end does succeed, this combinator will return all of the results generated by p, x1 through xn (with n >= 1), in a non-empty list: NonEmptyList.of(x1, .., xn). The parser p must succeed at least once before end succeeds.

    p

    the parser to execute multiple times.

    end

    the parser that stops the parsing of p.

    returns

    a parser that parses p until end succeeds, returning the non-empty list of all the successful results.

    Example:
    1. This can be useful for scanning comments:

      scala> import parsley.character.{string, item, endOfLine}
      scala> import parsley.cats.combinator.someTill
      scala> val comment = string("//") *> someTill(item, endOfLine)
      scala> p.parse("//hello world")
      val res0 = Failure(..)
      scala> p.parse("//hello world\n")
      val res1 = Success(NonEmptyList.of('h', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd'))
      scala> p.parse("//\n")
      val res2 = Failure(..)
      scala> p.parse("//a\n")
      val res3 = Success(NonEmptyList.of('a'))
    Since

    1.3.0

  20. final def synchronized[T0](arg0: => T0): T0
    Definition Classes
    AnyRef
  21. def toString(): String
    Definition Classes
    AnyRef → Any
  22. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  23. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  24. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException]) @native()

Deprecated Value Members

  1. def someUntil[A](p: Parsley[A], end: Parsley[_]): Parsley[NonEmptyList[A]]

    This combinator repeatedly parses a given parser one or more times, until the end parser succeeds, collecting the results into a list.

    This combinator repeatedly parses a given parser one or more times, until the end parser succeeds, collecting the results into a list.

    First ensures that trying to parse end fails, then tries to parse p. If it succeed then it will repeatedly: try to parse end, if it fails without consuming input, then parses p, which must succeed. When end does succeed, this combinator will return all of the results generated by p, x1 through xn (with n >= 1), in a non-empty list: NonEmptyList.of(x1, .., xn). The parser p must succeed at least once before end succeeds.

    p

    the parser to execute multiple times.

    end

    the parser that stops the parsing of p.

    returns

    a parser that parses p until end succeeds, returning the non-empty list of all the successful results.

    Annotations
    @deprecated
    Deprecated

    (Since version 1.3.0) This combinator will be removed in 2.0.0, use someTill instead

    Example:
    1. This can be useful for scanning comments:

      scala> import parsley.character.{string, item, endOfLine}
      scala> import parsley.cats.combinator.someUntil
      scala> val comment = string("//") *> someUntil(item, endOfLine)
      scala> p.parse("//hello world")
      val res0 = Failure(..)
      scala> p.parse("//hello world\n")
      val res1 = Success(NonEmptyList.of('h', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd'))
      scala> p.parse("//\n")
      val res2 = Failure(..)
      scala> p.parse("//a\n")
      val res3 = Success(NonEmptyList.of('a'))
    Since

    1.2.0

Inherited from AnyRef

Inherited from Any

Ungrouped