keypoint keypoint - 2 months ago 6
Scala Question

what do `^^^` and `~>` mean in sbt

I'm read the sbt documentation on Commands, and wondering what do

^^^
and
~>
mean?

I tried to google but nothing found, these chars are escaped by google I guess...Thanks a lot

// Demonstration of a custom parser.
// The command changes the foreground or background terminal color
// according to the input.
lazy val change = Space ~> (reset | setColor)
lazy val reset = token("reset" ^^^ "\033[0m")
lazy val color = token( Space ~> ("blue" ^^^ "4" | "green" ^^^ "2") )
lazy val select = token( "fg" ^^^ "3" | "bg" ^^^ "4" )
lazy val setColor = (select ~ color) map { case (g, c) => "\033[" + g + c + "m" }

def changeColor = Command("color")(_ => change) { (state, ansicode) =>
print(ansicode)
state
}


The full code is as example
project/CommandExample.scala
at http://www.scala-sbt.org/0.13/docs/Commands.html

Jan Jan
Answer

Those are methods on the RichParser class.

See http://www.scala-sbt.org/0.13/api/#sbt.complete.RichParser

Hint. If you look for symbolic methods click the '#' on the upper left corner of the api doc page.

  • ^^^[B](value: B): Parser[B]: Apply the original Parser, but provide value as the result if it succeeds.
  • ~>[B](b: Parser[B]): Parser[B]: Produces a Parser that applies the original Parser and then applies next (in order), discarding the result of the original parser.
Comments