This was originally part of the Scala standard library, but is now community-maintained, under the guidance of the Scala team at Akka (formerly Lightbend). If you are interested in joining the maintainers team, please contact @Philippus or @SethTisue.
Choosing a parsing libraryThis library's main strengths are:
Its main weaknesses are:
A number of other parsing libraries for Scala are available -- see list on Scaladex.
To depend on scala-parser-combinators in sbt, add something like this to your build.sbt:
libraryDependencies += "org.scala-lang.modules" %% "scala-parser-combinators" % <version>
To support multiple Scala versions, see the example in scala/scala-module-dependency-sample.
Scala.js and Scala NativeScala-parser-combinators is also available for Scala.js and Scala Native:
libraryDependencies += "org.scala-lang.modules" %%% "scala-parser-combinators" % <version>
import scala.util.parsing.combinator._ case class WordFreq(word: String, count: Int) { override def toString = s"Word <$word> occurs with frequency $count" } class SimpleParser extends RegexParsers { def word: Parser[String] = """[a-z]+""".r ^^ { _.toString } def number: Parser[Int] = """(0|[1-9]\d*)""".r ^^ { _.toInt } def freq: Parser[WordFreq] = word ~ number ^^ { case wd ~ fr => WordFreq(wd,fr) } } object TestSimpleParser extends SimpleParser { def main(args: Array[String]) = { parse(freq, "johnny 121") match { case Success(matched,_) => println(matched) case Failure(msg,_) => println(s"FAILURE: $msg") case Error(msg,_) => println(s"ERROR: $msg") } } }
For a detailed unpacking of this example see Getting Started.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4