Packages

  • package root
    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