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
- Alphabetic
- By Inheritance
- precedence
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Value Members
-
final
def
!=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
##(): Int
- Definition Classes
- AnyRef → Any
-
final
def
==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
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.
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
precedencefor simplicity. This is best used in conjunction withSOpsorGOps; or a mix ofSOps,GOps, andOps.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
Precand its subtypes for a description of how the types work.
Example: -
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
atom0and the remainingatomsat the base of the table. ThenlvlWeakestwill be the level containing the weakest operators at the outermost layer of the table. The remaininglvlswill 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.
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
precedenceis 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
Example: -
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
atom0and the remainingatomsat the base of the table. ThenlvlTightestwill be the level containing the tightest operators. The remaininglvlswill 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.
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
Example: -
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
-
def
clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( ... ) @native()
-
final
def
eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
equals(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
def
finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( classOf[java.lang.Throwable] )
-
final
def
getClass(): Class[_]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
def
hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
-
final
def
ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
final
def
notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
final
def
notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
final
def
synchronized[T0](arg0: ⇒ T0): T0
- Definition Classes
- AnyRef
-
def
toString(): String
- Definition Classes
- AnyRef → Any
-
final
def
wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... ) @native()