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.position contains parsers for extracting position information.
    • 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 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
  • Atoms
  • Fixity
  • GOps
  • InfixL
  • InfixN
  • InfixR
  • Ops
  • Postfix
  • Prec
  • Prefix
  • SOps
  • chain
  • infix
  • mixed
  • precedence
o

parsley.expr

precedence

object precedence

This object is used to construct precedence parsers from either a Prec or many Ops[A, A].

Contained within this object are three different shapes of apply functions: they allows for the construction of a precedence parser from either: a collection of levels of operators and atoms, in either weak-to-strong or strong-to-weak orderings; or a heterogeneous precedence table Prec.

Source
precedence.scala
Since

2.2.0

Linear Supertypes
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. precedence
  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. def apply[A](table: Prec[A]): Parsley[A]

    This combinator builds an expression parser given a heterogeneous precedence table.

    This combinator builds an expression parser given a heterogeneous precedence table.

    An expression parser will be formed by collapsing the given precedence table layer-by-layer. Since this table is heterogeneous, each level of the table produces a difference type, which is then consumed by the next level above.

    A

    the type of the expression parsers generated by this combinator.

    table

    the description of the heterogeneous table, where each level can vary in output and input types.

    returns

    an expression parser for the described precedence table.

    Example:
    1. This is overkill for this particular example, as each layer has the same type: it would be better to use one of the other forms of precedence for simplicity. This is best used in conjunction with SOps or GOps; or a mix of SOps, GOps, and Ops.

      scala> import parsley.Parsley, parsley.character.{char, digit}
      scala> import parsley.expr.{Atoms, Ops, InfixL, precedence}
      scala> val expr = precedence(Atoms(digit.map(_.asDigit)) :+
                                   Ops[Int](InfixL)(char('*') #> (_ * _)) :+
                                   Ops[Int](InfixL)(char('+') #> (_ + _), char('-') #> (_ - _)))
      scala> expr.parse("1+8*7+4")
      val res0 = Success(61)
    Since

    4.0.0

    See also

    Prec and its subtypes for a description of how the types work.

  5. def apply[A](lvlWeakest: Ops[A, A], lvls: Ops[A, A]*)(atom0: Parsley[A], atoms: Parsley[A]*): Parsley[A]

    This combinator builds an expression parser given a collection of homogeneous atoms and operators.

    This combinator builds an expression parser given a collection of homogeneous atoms and operators.

    An expression parser will be formed by parsing atom0 and the remaining atoms at the base of the table. Then lvlWeakest will be the level containing the weakest operators at the outermost layer of the table. The remaining lvls will be from tightest-to-weakest binding. All levels must consume and produce the same type.

    A

    the type of the expression parsers generated by this combinator.

    lvlWeakest

    the weakest binding operators.

    lvls

    the remaining levels of operators, ordered weakest-to-tightest.

    atom0

    the first atom at the base of the table.

    atoms

    the remaining atoms at the base of the table.

    returns

    an expression parser for the described precedence table.

    Example:
    1. scala> import parsley.Parsley, parsley.character.{char, digit}
      scala> import parsley.expr.{Ops, InfixL, precedence}
      scala> val expr = precedence[Int](Ops(InfixL)(char('+') #> (_ + _), char('-') #> (_ - _))),
                                        Ops(InfixL)(char('*') #> (_ * _))
                                       (digit.map(_.asDigit)))
      scala> expr.parse("1+8*7+4")
      val res0 = Success(61)

      Note that the type ascription on precedence is needed for this example, to avoid specifying the argument types of the operators in the table: this wouldn't be required with the tightest-to-weakest variant, as the inference is better on the atoms.

    Since

    4.0.0

  6. def apply[A](atom0: Parsley[A], atoms: Parsley[A]*)(lvlTightest: Ops[A, A], lvls: Ops[A, A]*): Parsley[A]

    This combinator builds an expression parser given a collection of homogeneous atoms and operators.

    This combinator builds an expression parser given a collection of homogeneous atoms and operators.

    An expression parser will be formed by parsing atom0 and the remaining atoms at the base of the table. Then lvlTightest will be the level containing the tightest operators. The remaining lvls will be from tightest-to-weakest binding. All levels must consume and produce the same type.

    A

    the type of the expression parsers generated by this combinator.

    atom0

    the first atom at the base of the table.

    atoms

    the remaining atoms at the base of the table.

    lvlTightest

    the tightest binding operators.

    lvls

    the remaining levels of operators, ordered tightest-to-weakest.

    returns

    an expression parser for the described precedence table.

    Example:
    1. scala> import parsley.Parsley, parsley.character.{char, digit}
      scala> import parsley.expr.{Ops, InfixL, precedence}
      scala> val expr = precedence(digit.map(_.asDigit))
                                  (Ops(InfixL)(char('*') #> (_ * _)),
                                   Ops(InfixL)(char('+') #> (_ + _), char('-') #> (_ - _)))
      scala> expr.parse("1+8*7+4")
      val res0 = Success(61)
    Since

    3.0.0

  7. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  8. def clone(): AnyRef
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.CloneNotSupportedException]) @native()
  9. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  10. def equals(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef → Any
  11. def finalize(): Unit
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.Throwable])
  12. final def getClass(): Class[_ <: AnyRef]
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  13. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  14. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  15. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  16. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  17. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  18. final def synchronized[T0](arg0: => T0): T0
    Definition Classes
    AnyRef
  19. def toString(): String
    Definition Classes
    AnyRef → Any
  20. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  21. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  22. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException]) @native()

Inherited from AnyRef

Inherited from Any

Ungrouped