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, as well as the implicit classes which enable the "method-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.expr contains the following sub modules:
    • parsley.implicits contains several implicits to add syntactic sugar to the combinators, such as being able to use character and string literals directly as parsers, as well as enabling lifting of functions to work on parsers.
    • 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.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.unsafe contains unsafe (and not thread-safe) ways of speeding up the execution of a parser.

    In addition to the modules and packages outlined above, this version of Parsley (up to version 3.0), also includes the so-called old-style API, which is deprecated (see the Parsley wiki for a discussion of these differences). You should use the modules described above, and avoid the following:

    • parsley.BitGen
    • parsley.Char
    • parsley.CharSet
    • parsley.Combinator
    • parsley.ExpressionParser
    • parsley.Impl
    • parsley.Implicits
    • parsley.LanguageDef
    • parsley.NotRequired
    • parsley.Parser
    • parsley.Predicate
    • parsley.Reg
    • parsley.TokenParser
    Definition Classes
    root
  • package parsley
    Definition Classes
    root
  • package expr
    Definition Classes
    parsley
  • package internal
    Definition Classes
    parsley
  • package token
    Definition Classes
    parsley
  • BitGen
  • Char
  • CharSet
  • Combinator
  • ExpressionParser
  • Failure
  • Impl
  • Implicits
  • LanguageDef
  • NotRequired
  • Parser
  • Parsley
  • Predicate
  • Reg
  • Result
  • Success
  • TokenParser
  • character
  • combinator
  • debug
  • implicits
  • lift
  • registers
  • unsafe

object Parsley

This object contains the core "function-style" combinators as well as the implicit classes which provide the "method-style" combinators. All parsers will likely require something from within!

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

Type Members

  1. implicit final class LazyChooseParsley[P, +A] extends AnyRef
  2. implicit final class LazyMapParsley[A, +B] extends AnyRef
  3. implicit final class LazyParsley[P, +A] extends AnyRef

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 attempt[A](p: => Parsley[A]): Parsley[A]

    Given a parser p, attempts to parse p.

    Given a parser p, attempts to parse p. If the parser fails, then attempt ensures that no input was consumed. This allows for backtracking capabilities, disabling the implicit cut semantics offered by <|>.

    p

    The parser to run

    returns

    The result of p, or if p failed ensures the parser state was as it was on entry.

  6. def branch[A, B, C](b: => Parsley[Either[A, B]], p: => Parsley[(A) => C], q: => Parsley[(B) => C]): Parsley[C]

    This is one of the core operations of a selective functor.

    This is one of the core operations of a selective functor. It will conditionally execute one of p and q depending on the result from b. This can be used to implement conditional choice within a parser without relying on expensive monadic operations.

    b

    The first parser to parse

    p

    If b returns Left then this parser is executed with the result

    q

    If b returns Right then this parser is executed with the result

    returns

    Either the result from p or q depending on b.

  7. def clone(): AnyRef
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.CloneNotSupportedException]) @native()
  8. val col: Parsley[Int]

    This parser consumes no input and returns the current column number reached in the input stream

    This parser consumes no input and returns the current column number reached in the input stream

    returns

    The column number the parser is currently at

  9. val empty: Parsley[Nothing]

    The empty parser consumes no input and fails softly (that is to say, no error message)

  10. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  11. def equals(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef → Any
  12. def fail(msg: String): Parsley[Nothing]

    The fail(msg) parser consumes no input and fails with msg as the error message

  13. def finalize(): Unit
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.Throwable])
  14. final def getClass(): Class[_ <: AnyRef]
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  15. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  16. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  17. def join[A](p: => Parsley[Parsley[A]]): Parsley[A]

    This function is an alias for _.flatten.

    This function is an alias for _.flatten. Provides namesake to Haskell.

  18. val line: Parsley[Int]

    This parser consumes no input and returns the current line number reached in the input stream

    This parser consumes no input and returns the current line number reached in the input stream

    returns

    The line number the parser is currently at

  19. def lookAhead[A](p: => Parsley[A]): Parsley[A]

    Parses p without consuming any input.

    Parses p without consuming any input. If p fails and consumes input then so does lookAhead(p). Combine with attempt if this is undesirable.

    p

    The parser to look ahead at

    returns

    The result of the lookahead

  20. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  21. def notFollowedBy(p: Parsley[_]): Parsley[Unit]

    notFollowedBy(p) only succeeds when parser p fails.

    notFollowedBy(p) only succeeds when parser p fails. This parser does not consume any input. This parser can be used to implement the 'longest match' rule. For example, when recognising keywords, we want to make sure that a keyword is not followed by a legal identifier character, in which case the keyword is actually an identifier. We can program this behaviour as follows:

    attempt(kw *> notFollowedBy(alphaNum))
  22. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  23. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  24. val pos: Parsley[(Int, Int)]

    This parser consumes no input and returns the current position reached in the input stream

    This parser consumes no input and returns the current position reached in the input stream

    returns

    Tuple of line and column number that the parser has reached

  25. def pure[A](x: A): Parsley[A]

    This is the traditional applicative pure function (or monadic return) for parsers.

    This is the traditional applicative pure function (or monadic return) for parsers. It consumes no input and does not influence the state of the parser, but does return the value provided. Useful to inject pure values into the parsing process.

    x

    The value to be returned from the parser

    returns

    A parser which consumes nothing and returns x

  26. def select[A, B](p: => Parsley[Either[A, B]], q: => Parsley[(A) => B]): Parsley[B]

    This is one of the core operations of a selective functor.

    This is one of the core operations of a selective functor. It will conditionally execute one of q depending on whether or not p returns a Left. It can be used to implement branch and other selective operations, however it is more efficiently implemented with branch itself.

    p

    The first parser to parse

    q

    If p returns Left then this parser is executed with the result

    returns

    Either the result from p if it returned Left or the result of q applied to the Right from p

  27. def sequence[A](ps: Parsley[A]*): Parsley[List[A]]

    Evaluate each of the parsers in ps sequentially from left to right, collecting the results.

    Evaluate each of the parsers in ps sequentially from left to right, collecting the results.

    ps

    Parsers to be sequenced

    returns

    The list containing results, one from each parser, in order

  28. def skip(ps: Parsley[_]*): Parsley[Unit]

    Evaluate each of the parsers in ps sequentially from left to right, ignoring the results.

    Evaluate each of the parsers in ps sequentially from left to right, ignoring the results.

    ps

    Parsers to be performed

  29. final def synchronized[T0](arg0: => T0): T0
    Definition Classes
    AnyRef
  30. def toString(): String
    Definition Classes
    AnyRef → Any
  31. def traverse[A, B](f: (A) => Parsley[B], xs: A*): Parsley[List[B]]

    Like sequence but produces a list of parsers to sequence by applying the function f to each element in xs.

    Like sequence but produces a list of parsers to sequence by applying the function f to each element in xs.

    f

    The function to map on each element of xs to produce parsers

    xs

    Values to generate parsers from

    returns

    The list containing results formed by executing each parser generated from xs and f in sequence

  32. def unexpected(msg: String): Parsley[Nothing]

    The unexpected(msg) parser consumes no input and fails with msg as an unexpected error

  33. val unit: Parsley[Unit]

    Returns ().

    Returns (). Defined as pure(()) but aliased for sugar

  34. def void(p: Parsley[_]): Parsley[Unit]

    converts a parser's result to ()

  35. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  36. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  37. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException]) @native()

Deprecated Value Members

  1. def get[S](r: registers.Reg[S]): Parsley[S]

    Consumes no input and returns the value stored in one of the parser registers.

    Consumes no input and returns the value stored in one of the parser registers.

    S

    The type of the value in register r (this will result in a runtime type-check)

    r

    The index of the register to collect from

    returns

    The value stored in register r of type S

    Annotations
    @deprecated
    Deprecated

    (Since version v2.2.0) This method will be removed in Parsley 3.0, use parsley.registers.get instead

    Note

    There are only 4 registers at present.

  2. def gets[S, A](r: registers.Reg[S], pf: Parsley[(S) => A]): Parsley[A]

    Returns the value stored in one of the parser registers after applying a function obtained from given parser.

    Returns the value stored in one of the parser registers after applying a function obtained from given parser.

    S

    The type of the value in register r (this will result in a runtime type-check)

    A

    The desired result type

    r

    The index of the register to collect from

    pf

    The parser which provides the function to transform values

    returns

    The value stored in register r applied to f from pf

    Annotations
    @deprecated
    Deprecated

    (Since version v2.2.0) This method will be removed in Parsley 3.0, use parsley.registers.gets instead

    Note

    There are only 4 registers at present. The value is fetched before pf is executed

  3. def gets[S, A](r: registers.Reg[S], f: (S) => A): Parsley[A]

    Consumes no input and returns the value stored in one of the parser registers after applying a function.

    Consumes no input and returns the value stored in one of the parser registers after applying a function.

    S

    The type of the value in register r (this will result in a runtime type-check)

    A

    The desired result type

    r

    The index of the register to collect from

    f

    The function used to transform the value in the register

    returns

    The value stored in register r applied to f

    Annotations
    @deprecated
    Deprecated

    (Since version v2.2.0) This method will be removed in Parsley 3.0, use parsley.registers.gets instead

    Note

    There are only 4 registers at present.

  4. def label[A](p: Parsley[A], msg: String): Parsley[A]

    Alias for p ? msg.

    Alias for p ? msg.

    Annotations
    @deprecated
    Deprecated

    (Since version v2.6.0) This method will be removed in Parsley 3.0, use .label or ? instead

  5. def lift1[A, B](f: (A) => B, p: => Parsley[A]): Parsley[B]

    lift1(f, p) is an alias for p.map(f).

    lift1(f, p) is an alias for p.map(f). It is provided for symmetry with lift2 and lift3

    Annotations
    @deprecated
    Deprecated

    (Since version v2.2.0) This method will be removed in Parsley 3.0, use parsley.lift.lift1 instead

  6. def lift2[A, B, C](f: (A, B) => C, p: => Parsley[A], q: => Parsley[B]): Parsley[C]

    Traditionally, lift2 is defined as lift2(f, p, q) = p.map(f) <*> q.

    Traditionally, lift2 is defined as lift2(f, p, q) = p.map(f) <*> q. However, f is actually uncurried, so it's actually more exactly defined as; read p and then read q then provide their results to function f. This is designed to bring higher performance to any curried operations that are not themselves intrinsic.

    f

    The function to apply to the results of p and q

    p

    The first parser to parse

    q

    The second parser to parse

    returns

    f(x, y) where x is the result of p and y is the result of q.

    Annotations
    @deprecated
    Deprecated

    (Since version v2.2.0) This method will be removed in Parsley 3.0, use parsley.lift.lift2 instead

  7. def lift3[A, B, C, D](f: (A, B, C) => D, p: => Parsley[A], q: => Parsley[B], r: => Parsley[C]): Parsley[D]

    Traditionally, lift2 is defined as lift3(f, p, q, r) = p.map(f) <*> q <*> r.

    Traditionally, lift2 is defined as lift3(f, p, q, r) = p.map(f) <*> q <*> r. However, f is actually uncurried, so it's actually more exactly defined as; read p and then read q and then read 'r' then provide their results to function f. This is designed to bring higher performance to any curried operations that are not themselves intrinsic.

    f

    The function to apply to the results of p and q

    p

    The first parser to parse

    q

    The second parser to parse

    r

    The third parser to parse

    returns

    f(x, y, z) where x is the result of p, y is the result of q and z is the result of r.

    Annotations
    @deprecated
    Deprecated

    (Since version v2.2.0) This method will be removed in Parsley 3.0, use parsley.lift.lift3 instead

  8. def local[R, A](r: registers.Reg[R], f: (R) => R, p: => Parsley[A]): Parsley[A]

    For the duration of parser p the state stored in register r is instead modified with f.

    For the duration of parser p the state stored in register r is instead modified with f. The change is undone after p has finished.

    r

    The index of the register to modify

    f

    The function used to modify the value in register r

    p

    The parser to execute with the adjusted state

    returns

    The parser that performs p with the modified state

    Annotations
    @deprecated
    Deprecated

    (Since version v2.2.0) This method will be removed in Parsley 3.0, use parsley.registers.local instead

    Note

    There are only 4 registers at present.

  9. def local[R, A](r: registers.Reg[R], p: => Parsley[R], q: => Parsley[A]): Parsley[A]

    For the duration of parser q the state stored in register r is instead set to the return value of p.

    For the duration of parser q the state stored in register r is instead set to the return value of p. The change is undone after q has finished.

    r

    The index of the register to modify

    p

    The parser whose return value is placed in register r

    q

    The parser to execute with the adjusted state

    returns

    The parser that performs q with the modified state

    Annotations
    @deprecated
    Deprecated

    (Since version v2.2.0) This method will be removed in Parsley 3.0, use parsley.registers.local instead

    Note

    There are only 4 registers at present.

  10. def local[R, A](r: registers.Reg[R], x: R, p: => Parsley[A]): Parsley[A]

    For the duration of parser p the state stored in register r is instead set to x.

    For the duration of parser p the state stored in register r is instead set to x. The change is undone after p has finished.

    r

    The index of the register to modify

    x

    The value to place in the register r

    p

    The parser to execute with the adjusted state

    returns

    The parser that performs p with the modified state

    Annotations
    @deprecated
    Deprecated

    (Since version v2.2.0) This method will be removed in Parsley 3.0, use parsley.registers.local instead

    Note

    There are only 4 registers at present.

  11. def many[A](p: => Parsley[A]): Parsley[List[A]]

    many(p) executes the parser p zero or more times.

    many(p) executes the parser p zero or more times. Returns a list of the returned values of p.

    Annotations
    @deprecated
    Deprecated

    (Since version v2.2.0) This method will be removed in Parsley 3.0, use parsley.combinator.many instead

  12. def modify[S](r: registers.Reg[S], f: (S) => S): Parsley[Unit]

    Modifies the value contained in register r using function f.

    Modifies the value contained in register r using function f.

    S

    The type of value currently assumed to be in the register

    r

    The index of the register to modify

    f

    The function used to modify the register

    Annotations
    @deprecated
    Deprecated

    (Since version v2.2.0) This method will be removed in Parsley 3.0, use parsley.registers.modify instead

    Note

    There are only 4 registers at present.

  13. def put[S](r: registers.Reg[S], p: => Parsley[S]): Parsley[Unit]

    Places the result of running p into register r.

    Places the result of running p into register r.

    r

    The index of the register to place the value in

    p

    The parser to derive the value from

    Annotations
    @deprecated
    Deprecated

    (Since version v2.2.0) This method will be removed in Parsley 3.0, use parsley.registers.put instead

    Note

    There are only 4 registers at present.

  14. def put[S](r: registers.Reg[S], x: S): Parsley[Unit]

    Consumes no input and places the value x into register r.

    Consumes no input and places the value x into register r.

    r

    The index of the register to place the value in

    x

    The value to place in the register

    Annotations
    @deprecated
    Deprecated

    (Since version v2.2.0) This method will be removed in Parsley 3.0, use parsley.registers.put instead

    Note

    There are only 4 registers at present.

  15. def rollback[A, B](reg: registers.Reg[A], p: Parsley[B]): Parsley[B]

    rollback(reg, p) will perform p, but if it fails without consuming input, any changes to the register reg will be reverted.

    rollback(reg, p) will perform p, but if it fails without consuming input, any changes to the register reg will be reverted.

    reg

    The register to rollback on failure of p

    p

    The parser to perform

    returns

    The result of the parser p, if any

    Annotations
    @deprecated
    Deprecated

    (Since version v2.2.0) This method will be removed in Parsley 3.0, use parsley.registers.rollback instead

    Since

    2.0

  16. def skipMany[A](p: => Parsley[A]): Parsley[Unit]

    skipMany(p) executes the parser p zero or more times and ignores the results.

    skipMany(p) executes the parser p zero or more times and ignores the results. Returns ()

    Annotations
    @deprecated
    Deprecated

    (Since version v2.2.0) This method will be removed in Parsley 3.0, use parsley.combinator.skipMany instead

Inherited from AnyRef

Inherited from Any

Ungrouped