Packages

  • package root

    This is the documentation for Parsley.

    This is the documentation for Parsley.

    Package structure

    The parsley package contains the Parsley class, as well as the Result, Success, and Failure types. In addition to these, it also contains the following packages and "modules" (a module is defined as being an object which mocks a package):

    • parsley.Parsley contains the bulk of the core "function-style" combinators.
    • parsley.combinator contains many helpful combinators that simplify some common parser patterns.
    • parsley.character contains the combinators needed to read characters and strings, as well as combinators to match specific sub-sets of characters.
    • parsley.debug contains debugging combinators, helpful for identifying faults in parsers.
    • parsley.extension contains syntactic sugar combinators exposed as implicit classes.
    • parsley.io contains extension methods to run parsers with input sourced from IO sources.
    • parsley.expr contains the following sub modules:
      • parsley.expr.chain contains combinators used in expression parsing
      • parsley.expr.precedence is a builder for expression parsers built on a precedence table.
      • parsley.expr.infix contains combinators used in expression parsing, but with more permissive types than their equivalents in chain.
      • parsley.expr.mixed contains combinators that can be used for expression parsing, but where different fixities may be mixed on the same level: this is rare in practice.
    • parsley.implicits contains several implicits to add syntactic sugar to the combinators. These are sub-categorised into the following sub modules:
      • parsley.implicits.character contains implicits to allow you to use character and string literals as parsers.
      • parsley.implicits.combinator contains implicits related to combinators, such as the ability to make any parser into a Parsley[Unit] automatically.
      • parsley.implicits.lift enables postfix application of the lift combinator onto a function (or value).
      • parsley.implicits.zipped enables boths a reversed form of lift where the function appears on the right and is applied on a tuple (useful when type inference has failed) as well as a .zipped method for building tuples out of several combinators.
    • parsley.errors contains modules to deal with error messages, their refinement and generation.
    • parsley.lift contains functions which lift functions that work on regular types to those which now combine the results of parsers returning those same types. these are ubiquitous.
    • parsley.ap contains functions which allow for the application of a parser returning a function to several parsers returning each of the argument types.
    • parsley.registers contains combinators that interact with the context-sensitive functionality in the form of registers.
    • parsley.token contains the Lexer class that provides a host of helpful lexing combinators when provided with the description of a language.
    • parsley.genericbridges contains some basic implementations of the Parser Bridge pattern (see Design Patterns for Parser Combinators in Scala, or the parsley wiki): these can be used before more specialised generic bridge traits can be constructed.
    Definition Classes
    root
  • package parsley
    Definition Classes
    root
  • package errors

    This package contains various functionality relating to the generation and formatting of error messages.

    This package contains various functionality relating to the generation and formatting of error messages.

    In particular, it includes a collection of combinators for improving error messages within the parser, including labelling and providing additional information. It also contains combinators that can be used to valid data produced by a parser, to ensure it conforms to expected invariances, producing good quality error messages if this is not the case. Finally, this package contains ways of changing the formatting of error messages: this can either be changing how the default String-based errors are formatted, or by injectiing Parsley's errors into a custom error object.

    Definition Classes
    parsley
  • package expr

    This package contains various functionality relating to the parsing of expressions..

    This package contains various functionality relating to the parsing of expressions..

    This includes the "chain" combinators, which tackle the left-recursion problem and allow for the parsing and combining of operators with values. It also includes functionality for constructing larger precedence tables, which may even vary the type of each layer in the table, allowing for strongly-typed expression parsing.

    Definition Classes
    parsley
  • package implicits

    This package contains various functionality that involve Scala's implicits mechanism.

    This package contains various functionality that involve Scala's implicits mechanism.

    This includes conversions from scala literals into parsers, as well as enabling new syntax on regular Scala values (such as Parsley's lift or zipped syntax). Automatic conversion to Parsley[Unit] is also supported within this package.

    Definition Classes
    parsley
  • package internal
    Definition Classes
    parsley
  • package token

    This package provides a wealth of functionality for performing common lexing tasks.

    This package provides a wealth of functionality for performing common lexing tasks.

    It is organised as follows:

    • the main parsing functionality is accessed via Lexer, which provides implementations for the combinators found in the sub-packages given a LexicalDesc.
    • the descriptions sub-package is how a lexical structure can be described, providing the configuration that alters the behaviour of the parsers produced by the Lexer.
    • the other sub-packages contain the high-level interfaces that the Lexer exposes, which can be used to pass whitespace-aware and non-whitespace-aware combinators around in a uniform way.
    • the predicate module contains functionality to help define boolean predicates on characters or unicode codepoints.
    Definition Classes
    parsley
  • Failure
  • Parsley
  • Result
  • Success
  • ap
  • character
  • combinator
  • debug
  • extension
  • genericbridges
  • io
  • lift
  • registers
o

parsley

combinator

object combinator

This module contains a huge number of pre-made combinators that are very useful for a variety of purposes.

In particular, it contains combinators for: performing a parser iteratively, collecting all the results; querying whether or not any input is left; optionally performing parsers; parsing delimited constructions; handling multiple possible alternatives or parsers to sequence; handling more complex conditional execution; and more.

Since

2.2.0

Linear Supertypes
AnyRef, Any
Ordering
  1. Grouped
  2. Alphabetic
  3. 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 attemptChoice[A](ps: Parsley[A]*): Parsley[A]

    This combinator tries to parse each of the parsers ps in order, until one of them succeeds.

    This combinator tries to parse each of the parsers ps in order, until one of them succeeds.

    Finds the first parser in ps which succeeds, returning its result. If none of the parsers succeed, then this combinator fails. This combinator will always try and parse each of the combinators until one succeeds, regardless of how they fail. The last argument will not be wrapped in attempt, as this is not necessary.

    ps

    the parsers to try, in order.

    returns

    a parser that tries to parse one of ps.

    Example:
    1. scala> import parsley.combinator.attemptChoice
      scala> import parsley.character.string
      scala> val p = attemptChoice(string("abc"), string("ab"), string("bc"), string("d"))
      scala> p.parse("abc")
      val res0 = Success("abc")
      scala> p.parse("ab")
      val res1 = Success("ab")
      scala> p.parse("bc")
      val res2 = Success("bc")
      scala> p.parse("x")
      val res3 = Failure(..)
    Note

    this combinator is not particularly efficient, because it may unnecessarily backtrack for each alternative.

    See also

    <|>

    attempt

  6. def between[A](open: Parsley[_], close: => Parsley[_], p: => Parsley[A]): Parsley[A]

    This combinator parses open, followed by p, and then close.

    This combinator parses open, followed by p, and then close.

    First parse open, ignore its result, then parse, p, producing x. Finally, parse close, ignoring its result. If open, p, and close all succeeded, then return x. If any of them failed, this combinator fails.

    open

    the first parser to parse.

    close

    the last parser to parse.

    p

    the parser to parse between the other two.

    returns

    a parser that reads open, then p, then close and returns the result of p.

    Example:
    1. def braces[A](p: Parsley[A]) = between(char('{'), char('}'), p)
  7. def choice[A](ps: Parsley[A]*): Parsley[A]

    This combinator tries to parse each of the parsers ps in order, until one of them succeeds.

    This combinator tries to parse each of the parsers ps in order, until one of them succeeds.

    Finds the first parser in ps which succeeds, returning its result. If none of the parsers succeed, then this combinator fails. If a parser fails having consumed input, this combinator fails immediately.

    ps

    the parsers to try, in order.

    returns

    a parser that tries to parse one of ps.

    Example:
    1. scala> import parsley.combinator.choice
      scala> import parsley.character.string
      scala> val p = choice(string("abc"), string("ab"), string("bc"), string("d"))
      scala> p.parse("abc")
      val res0 = Success("abc")
      scala> p.parse("ab")
      val res1 = Failure(..)
      scala> p.parse("bc")
      val res2 = Success("bc")
      scala> p.parse("x")
      val res3 = Failure(..)
    See also

    <|>

  8. def clone(): AnyRef
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.CloneNotSupportedException]) @native()
  9. def decide[A](p: Parsley[Option[A]], q: => Parsley[A]): Parsley[A]

    This combinator parses q depending only if p returns a None.

    This combinator parses q depending only if p returns a None.

    First parses p. If p returned Some(x), then x is returned. Otherwise, if p returned None then q is parsed, producing y, and y is returned. If p or q fails, the combinator fails.

    p

    the first parser, which returns an Option to eliminate.

    q

    a parser to execute when p returns None, to provide a value of type A.

    returns

    a parser that either just parses p or both p and q in order to return an A.

    Example:
    1. decide(option(p), q) = p <|> q
  10. def decide[A](p: Parsley[Option[A]]): Parsley[A]

    This combinator can eliminate an Option from the result of the parser p.

    This combinator can eliminate an Option from the result of the parser p.

    First parse p, if it succeeds returning Some(x), then return x. However, if p fails, or returned None, then this combinator fails.

    p

    the parser to parse and extract the result from.

    returns

    a parser that tries to extract the result from p.

    Example:
    1. decide(option(p)) = p
  11. def endBy[A](p: Parsley[A], sep: => Parsley[_]): Parsley[List[A]]

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

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

    Behaves just like endBy1, except does not require an initial p and sep, returning the empty list instead.

    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 list of p's results.

    Example:
    1. scala> ...
      scala> val args = endBy(int, string(";\n"))
      scala> args.parse("7;\n3;\n2")
      val res0 = Failure(..)
      scala> args.parse("")
      val res1 = Success(Nil)
      scala> args.parse("1;\n")
      val res2 = Success(List(1))
      scala> args.parse("1;\n2;\n")
      val res3 = Success(List(1, 2))
  12. def endBy1[A](p: Parsley[A], sep: => Parsley[_]): Parsley[List[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 List(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 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(List(1))
      scala> args.parse("1;\n2;\n")
      val res3 = Success(List(1, 2))
  13. val eof: Parsley[Unit]

    This parser only succeeds at the end of the input.

    This parser only succeeds at the end of the input.

    Equivalent to notFollowedBy(item).

    Example:
    1. scala> import parsley.combinator.eof
      scala> eof.parse("a")
      val res0 = Failure(..)
      scala> eof.parse("")
      val res1 = Success(())
  14. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  15. def equals(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef → Any
  16. def exactly[A](n: Int, p: Parsley[A]): Parsley[List[A]]

    This combinator parses exactly n occurrences of p, returning these n results in a list.

    This combinator parses exactly n occurrences of p, returning these n results in a list.

    Parses p repeatedly up to n times. If p fails before n is reached, then this combinator fails. It is not required for p to fail after the nth parse. The results produced by p, x1 through xn, are returned as List(x1, .., xn).

    n

    the number of times to repeat p.

    p

    the parser to repeat.

    returns

    a parser that parses p exactly n times, returning a list of the results.

    Example:
    1. scala> import parsley.character.item
      scala> import parsley.combinator.exactly
      scala> val p = exactly(3, item)
      scala> p.parse("ab")
      val res0 = Failure(..)
      scala> p.parse("abc")
      val res1 = Success(List('a', 'b', 'c'))
      scala> p.parse("abcd")
      val res2 = Success(List('a', 'b', 'c'))
    Since

    4.0.0

  17. def finalize(): Unit
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.Throwable])
  18. final def getClass(): Class[_ <: AnyRef]
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  19. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  20. def ifP[A](condP: Parsley[Boolean], thenP: => Parsley[A], elseP: => Parsley[A]): Parsley[A]

    This combinator parses one of thenP or elseP depending on the result of parsing condP.

    This combinator parses one of thenP or elseP depending on the result of parsing condP.

    This is a lifted if-statement. First, parse condP: if it is successful and returns true, then parse thenP; else, if it returned false, parse elseP; or, if condP failed then fail. If either of thenP or elseP fail, then this combinator also fails.

    Most useful in conjunction with Registers, as this allows for decisions to be made based on state.

    condP

    the parser that yields the condition value.

    thenP

    the parser to execute if the condition is true.

    elseP

    the parser to execute if the condition is false.

    returns

    a parser that conditionally parses thenP or elseP after condP.

    Example:
    1. ifP(pure(true), p, _) == p
      ifP(pure(false), _, p) == p
    Since

    4.0.0

  21. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  22. def many[A](p: Parsley[A]): Parsley[List[A]]

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

    This combinator repeatedly parses a given parser zero 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 >= 0), in a list: List(x1, .., xn). If p was never successful, the empty list is returned.

    p

    the parser to execute multiple times.

    returns

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

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

    2.2.0

  23. def manyN[A](n: Int, p: Parsley[A]): Parsley[List[A]]

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

    This combinator repeatedly parses a given parser n 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 xm (with m >= n), in a list: List(x1, .., xm). If p was not successful at least n times, this combinator fails.

    n

    the minimum number of ps required.

    p

    the parser to execute multiple times.

    returns

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

    Example:
    1. scala> import parsley.character.string
      scala> import parsley.combinator.manyN
      scala> val p = manyN(2, string("ab"))
      scala> p.parse("")
      val res0 = Failure(..)
      scala> p.parse("ab")
      val res1 = Failure(..)
      scala> p.parse("abababab")
      val res2 = Success(List("ab", "ab", "ab", "ab"))
      scala> p.parse("aba")
      val res3 = Failure(..)
    Note

    many(p) == many(0, p) and some(p) == many(1, p).

  24. def manyUntil[A](p: Parsley[A], end: Parsley[_]): Parsley[List[A]]

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

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

    First tries to parse end, if it fails without consuming input, then parses p, which must succeed. This repeats until end succeeds. When end does succeed, this combinator will return all of the results generated by p, x1 through xn (with n >= 0), in a list: List(x1, .., xn). If end could be parsed immediately, the empty list is returned.

    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 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.combinator.many
      scala> val comment = string("//") *> manyUntil(item, endOfLine)
      scala> p.parse("//hello world")
      val res0 = Failure(..)
      scala> p.parse("//hello world\n")
      val res1 = Success(List('h', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd'))
      scala> p.parse("//\n")
      val res2 = Success(Nil)
  25. val more: Parsley[Unit]

    This parser only succeeds if there is still more input.

    This parser only succeeds if there is still more input.

    Equivalent to lookAhead(item).void.

    Example:
    1. scala> import parsley.combinator.more
      scala> more.parse("")
      val res0 = Failure(..)
      scala> more.parse("a")
      val res1 = Success(())
  26. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  27. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  28. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  29. def option[A](p: Parsley[A]): Parsley[Option[A]]

    This combinator tries to parse p, wrapping its result in a Some if it succeeds, or returns None if it fails.

    This combinator tries to parse p, wrapping its result in a Some if it succeeds, or returns None if it fails.

    Tries to parse p. If p succeeded, producing x, then Some(x) is returned. Otherwise, if p failed without consuming input, then None is returned instead.

    p

    the parser to try to parse.

    returns

    a parser that tries to parse p, but can still succeed with None if that was not possible.

    Example:
    1. scala> import parsley.combinator.option
      scala> import parsley.character.string
      scala> val p = option(string("abc"))
      scala> p.parse("")
      val res0 = Success(None)
      scala> p.parse("abc")
      val res1 = Success(Some("abc"))
      scala> p.parse("ab")
      val res2 = Failure(..)
  30. def optional(p: Parsley[_]): Parsley[Unit]

    This combinator will parse p if possible, otherwise will do nothing.

    This combinator will parse p if possible, otherwise will do nothing.

    Tries to parse p. If p succeeds, or fails without consuming input then this combinator is successful. Otherwise, if p failed having consumed input, this combinator fails.

    p

    the parser to try to parse.

    returns

    a parser that tries to parse p.

    Example:
    1. scala> import parsley.combinator.optional
      scala> import parsley.character.string
      scala> val p = optional(string("abc"))
      scala> p.parse("")
      val res0 = Success(())
      scala> p.parse("abc")
      val res1 = Success(())
      scala> p.parse("ab")
      val res2 = Failure(..)
    Note

    equivalent to optionalAs(p, ()).

  31. def optionalAs[A](p: Parsley[_], x: A): Parsley[A]

    This combinator will parse p if possible, otherwise will do nothing.

    This combinator will parse p if possible, otherwise will do nothing.

    Tries to parse p. If p succeeds, or fails without consuming input then this combinator is successful and returns x. Otherwise, if p failed having consumed input, this combinator fails.

    p

    the parser to try to parse.

    x

    the value to return regardless of how p performs.

    returns

    a parser that tries to parse p, returning x regardless of success or failure.

    Example:
    1. scala> import parsley.combinator.optionalAs
      scala> import parsley.character.string
      scala> val p = optionalAs(string("abc"), 7)
      scala> p.parse("")
      val res0 = Success(7)
      scala> p.parse("abc")
      val res1 = Success(7)
      scala> p.parse("ab")
      val res2 = Failure(..)
  32. def sepBy[A](p: Parsley[A], sep: => Parsley[_]): Parsley[List[A]]

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

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

    Behaves just like sepBy1, except does not require an initial p, returning the empty list instead.

    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 list of p's results.

    Example:
    1. scala> ...
      scala> val args = sepBy(int, string(", "))
      scala> args.parse("7, 3, 2")
      val res0 = Success(List(7, 3, 2))
      scala> args.parse("")
      val res1 = Success(Nil)
      scala> args.parse("1")
      val res2 = Success(List(1))
      scala> args.parse("1, 2, ")
      val res3 = Failure(..) // no trailing comma allowed
  33. def sepBy1[A](p: Parsley[A], sep: => Parsley[_]): Parsley[List[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 List(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 list of p's results.

    Example:
    1. scala> ...
      scala> val args = sepBy1(int, string(", "))
      scala> args.parse("7, 3, 2")
      val res0 = Success(List(7, 3, 2))
      scala> args.parse("")
      val res1 = Failure(..)
      scala> args.parse("1")
      val res2 = Success(List(1))
      scala> args.parse("1, 2, ")
      val res3 = Failure(..) // no trailing comma allowed
  34. def sepEndBy[A](p: Parsley[A], sep: => Parsley[_]): Parsley[List[A]]

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

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

    Behaves just like sepEndBy1, except does not require an initial p, returning the empty list instead.

    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 list of p's results.

    Example:
    1. scala> ...
      scala> val args = sepEndBy(int, string(";\n"))
      scala> args.parse("7;\n3;\n2")
      val res0 = Success(List(7, 3, 2))
      scala> args.parse("")
      val res1 = Success(Nil)
      scala> args.parse("1")
      val res2 = Success(List(1))
      scala> args.parse("1;\n2;\n")
      val res3 = Success(List(1, 2))
  35. def sepEndBy1[A](p: Parsley[A], sep: => Parsley[_]): Parsley[List[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 List(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 list of p's results.

    Example:
    1. scala> ...
      scala> val args = sepEndBy1(int, string(";\n"))
      scala> args.parse("7;\n3;\n2")
      val res0 = Success(List(7, 3, 2))
      scala> args.parse("")
      val res1 = Failure(..)
      scala> args.parse("1")
      val res2 = Success(List(1))
      scala> args.parse("1;\n2;\n")
      val res3 = Success(List(1, 2))
  36. def sequence[A](ps: Parsley[A]*): Parsley[List[A]]

    This combinator will parse each of ps in order, collecting the results.

    This combinator will parse each of ps in order, collecting the results.

    Given the parsers ps, consisting of p1 through pn, parses each in order. If they all succeed, producing the results x1 through xn, then List(x1, .., xn) is returned. If any of the parsers fail, then the whole combinator fails.

    ps

    parsers to be sequenced.

    returns

    a parser that parses each of ps, returning the results in a list

    Example:
    1. scala> import parsley.combinator.sequence
      scala> import parsley.character.{char, item}
      scala> val p = sequence(char('a'), item, char('c'))
      scala> p.parse("abc")
      val res0 = Success(List('a', 'b', 'c'))
      scala> p.parse("ab")
      val res1 = Failure(..)
    Since

    4.0.0

    Note

    be aware that all of the arguments to this combinator are in strict positions.

    See also

    <::>

  37. def skip(p: Parsley[_], ps: Parsley[_]*): Parsley[Unit]

    This combinator will parse each of ps in order, discarding the results.

    This combinator will parse each of ps in order, discarding the results.

    Given the parsers ps, consisting of p1 through pn, parses each in order. If they all succeed, this combinator succeeds. If any of the parsers fail, then the whole combinator fails.

    p

    first parser to be sequenced

    ps

    parsers to be sequenced.

    returns

    a parser that parses each of ps, returning ().

    Example:
    1. scala> import parsley.combinator.skip
      scala> import parsley.character.{char, item}
      scala> val p = skip(char('a'), item, char('c'))
      scala> p.parse("abc")
      val res0 = Success(())
      scala> p.parse("ab")
      val res1 = Failure(..)
    Note

    be aware that all of the arguments to this combinator are in strict positions.

    See also

    *>

  38. def skipMany(p: Parsley[_]): Parsley[Unit]

    This combinator repeatedly parses a given parser zero or more times, ignoring the results.

    This combinator repeatedly parses a given parser zero or more times, ignoring the results.

    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 succeed.

    p

    the parser to execute multiple times.

    returns

    a parser that parses p until it fails, returning unit.

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

    2.2.0

  39. def skipManyN(n: Int, p: Parsley[_]): Parsley[Unit]

    This combinator repeatedly parses a given parser n or more times, ignoring the results.

    This combinator repeatedly parses a given parser n or more times, ignoring the results.

    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 succeed. The parser p must succeed at least n times.

    p

    the parser to execute multiple times.

    returns

    a parser that parses p until it fails, returning unit.

    Example:
    1. scala> import parsley.character.string
      scala> import parsley.combinator.skipManyN
      scala> val p = skipManyN(2, string("ab"))
      scala> p.parse("")
      val res0 = Failure(..)
      scala> p.parse("ab")
      val res1 = Failure(..)
      scala> p.parse("abababab")
      val res2 = Success(())
      scala> p.parse("aba")
      val res3 = Failure(..)
  40. def skipSome(p: Parsley[_]): Parsley[Unit]

    This combinator repeatedly parses a given parser one or more times, ignoring the results.

    This combinator repeatedly parses a given parser one or more times, ignoring the results.

    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 succeed. The parser p must succeed at least once.

    p

    the parser to execute multiple times.

    returns

    a parser that parses p until it fails, returning unit.

    Example:
    1. scala> import parsley.character.string
      scala> import parsley.combinator.skipSome
      scala> val p = skipSome(string("ab"))
      scala> p.parse("")
      val res0 = Failure(..)
      scala> p.parse("ab")
      val res1 = Success(())
      scala> p.parse("abababab")
      val res2 = Success(())
      scala> p.parse("aba")
      val res3 = Failure(..)
  41. def some[A](p: Parsley[A]): Parsley[List[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 list: List(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 list of all the successful results.

    Example:
    1. scala> import parsley.character.string
      scala> import parsley.combinator.some
      scala> val p = some(string("ab"))
      scala> p.parse("")
      val res0 = Failure(..)
      scala> p.parse("ab")
      val res1 = Success(List("ab"))
      scala> p.parse("abababab")
      val res2 = Success(List("ab", "ab", "ab", "ab"))
      scala> p.parse("aba")
      val res3 = Failure(..)
  42. def someUntil[A](p: Parsley[A], end: Parsley[_]): Parsley[List[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 list: List(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 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.combinator.many
      scala> val comment = string("//") *> someUntil(item, endOfLine)
      scala> p.parse("//hello world")
      val res0 = Failure(..)
      scala> p.parse("//hello world\n")
      val res1 = Success(List('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(List('a'))
  43. final def synchronized[T0](arg0: => T0): T0
    Definition Classes
    AnyRef
  44. def toString(): String
    Definition Classes
    AnyRef → Any
  45. def traverse[A, B](f: (A) => Parsley[B], xs: A*): Parsley[List[B]]

    This combinator will parse each of the parsers generated by applying f to xs, in order, collecting the results.

    This combinator will parse each of the parsers generated by applying f to xs, in order, collecting the results.

    Given the values xs, consisting of x1 through xn, first creates the parses f(x1) through f(xn) and then called sequence on them.

    f

    the function used to generate parsers for each values

    xs

    the values to turn into parsers and sequence.

    returns

    a parser that sequences the parsers generated from applying f to each of xs.

    Example:
    1. // this is an OK implementation for `string`, which is common in Haskell.
      def string(str: String) = {
          traverse(char, str:  _*).map(_.mkString)
      }
    Since

    4.0.0

    Note

    be aware that all of the arguments to this combinator are in strict positions.

    See also

    sequence

  46. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  47. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  48. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException]) @native()
  49. def when(condP: Parsley[Boolean], thenP: => Parsley[Unit]): Parsley[Unit]

    This combinator conditionally parses thenP depending on the result of parsing condP.

    This combinator conditionally parses thenP depending on the result of parsing condP.

    This is a lifted if-statement. First, parse condP: if it is successful and returns true, then parse thenP; else, if it returned false do nothing; or, if condP failed then fail. If thenP fails, then this combinator also fails.

    Most useful in conjunction with Registers, as this allows for decisions to be made based on state.

    condP

    the parser that yields the condition value.

    thenP

    the parser to execute if the condition is true.

    returns

    a parser that conditionally parses thenP or elseP after condP.

    Example:
    1. when(pure(true), p) == p
      when(pure(false), _) == unit
  50. def whileP(p: Parsley[Boolean]): Parsley[Unit]

    This combinator repeatedly parses p so long as it returns true.

    This combinator repeatedly parses p so long as it returns true.

    This is a lifted while-loop. First, parse p: if it is successful and returns true, then repeat; else if it returned false stop; or, if it failed then this combinator fails.

    Most useful in conjunction with Registers, as this allows for decisions to be made based on state. In particular, this can be used to define the forP combinator.

    p

    the parser to repeatedly parse.

    returns

    a parser that continues to parse p until it returns false.

    Example:
    1. def forP[A](init: Parsley[A], cond: =>Parsley[A => Boolean], step: =>Parsley[A => A])(body: =>Parsley[_]): Parsley[Unit] = {
          val reg = Reg.make[A]
          lazy val _cond = reg.gets(cond)
          lazy val _step = reg.modify(step)
          reg.put(init) *> when(_cond, whileP(body *> _step *> _cond))
      }

Inherited from AnyRef

Inherited from Any

Iterative Combinators

These combinators all execute a given parser an unbounded number of times, until either it fails, or another parser succeeds, depending on the combinator. Depending on the combinator, all of the results produced by the repeated execution of the parser may be returned in a List. These are almost essential for any practical parsing task.

Input Query Combinators

These combinators do not consume input, but they allow for querying of the input stream - specifically checking whether or not there is more input that can be consumed or not. In particular, most parsers should be making use of eof to ensure that the parser consumes all the input available at the end of the parse.

Optional Parsing Combinators

These combinators allow for the possible parsing of some parser. If the parser succeeds, that is ok so long as it did not consume input. Be aware that the result of the success may be replaced with these combinators, with the exception of option, which still preserves the result.

Separated Values Combinators

These combinators are concerned with delimited parsing, where one parser is repeated but delimited by another one. In each of these cases p is the parser of interest and sep is the delimeter. These combinators mainly differ in either the number of ps they require, or exactly where the delimeters are allowed (only between, always trailing, or either). In all cases, they return the list of results generated by the repeated parses of p.

Multiple Branching/Sequencing Combinators

These combinators allow for testing or sequencing a large number of parsers in one go. Be careful, however, these are variadic combinators and are necessarily (for compatibility with Scala 2) not lazy. In such a case where laziness is desired without resorting to the other lazier combinators, there is a neat trick: unroll the first iteration of the combinator, and use the corresponding regular combinator to do that (i.e. <::> or *>): since these will have a lazy right-hand side, the remaining variadic arguments will be kept lazily suspended until later. Alternatively, it is possible to use the prefix ~ combinator to make any individual arguments lazy as required, for example skip(p, ~q, r).

Conditional Combinators

These combinators allow for the conditional extraction of a result, or the execution of a parser based on another. They are morally related to branch and select but are less fundamental.

Miscellaneous

Ungrouped