# scala-parser-combinators **Repository Path**: knpg/scala-parser-combinators ## Basic Information - **Project Name**: scala-parser-combinators - **Description**: No description available - **Primary Language**: Unknown - **License**: BSD-3-Clause - **Default Branch**: 1.0.x - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2019-10-31 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README scala-parser-combinators [](https://travis-ci.org/scala/scala-parser-combinators) [](http://search.maven.org/#search%7Cga%7C1%7Cg%3Aorg.scala-lang.modules%20a%3Ascala-parser-combinators_2.11) [](http://search.maven.org/#search%7Cga%7C1%7Cg%3Aorg.scala-lang.modules%20a%3Ascala-parser-combinators_2.12) [![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/scala/scala-parser-combinators) ======================== ### Scala Standard Parser Combinator Library This library is now community-maintained. If you are interested in helping please contact @gourlaysama or mention it [on Gitter](https://gitter.im/scala/scala-parser-combinators). As of Scala 2.11, this library is a separate jar that can be omitted from Scala projects that do not use Parser Combinators. ## Documentation * [Current API](https://javadoc.io/page/org.scala-lang.modules/scala-parser-combinators_2.12/latest/scala/util/parsing/combinator/index.html) * The [Getting Started](docs/Getting_Started.md) guide * A more complicated example, [Building a lexer and parser with Scala's Parser Combinators](https://enear.github.io/2016/03/31/parser-combinators/) * "Combinator Parsing", chapter 33 of [_Programming in Scala, Third Edition_](http://www.artima.com/shop/programming_in_scala), shows how to use this library to parse arithmetic expressions and JSON. The second half of the chapter examines how the library is implemented. ## Adding an SBT dependency To depend on scala-parser-combinators in SBT, add something like this to your build.sbt: ``` libraryDependencies += "org.scala-lang.modules" %% "scala-parser-combinators" % "1.0.7" ``` (Assuming you're using a `scalaVersion` for which a scala-parser-combinators is published. The first 2.11 milestone for which this is true is 2.11.0-M4.) To support multiple Scala versions, see the example in https://github.com/scala/scala-module-dependency-sample. ## Example ```scala import scala.util.parsing.combinator._ case class WordFreq(word: String, count: Int) { override def toString = "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("FAILURE: " + msg) case Error(msg,_) => println("ERROR: " + msg) } } } ``` For a detailed unpacking of this example see [Getting Started](docs/Getting_Started.md). ## ScalaJS support Scala-parser-combinators directly supports scala-js 0.6+, starting with v1.0.5: ``` libraryDependencies += "org.scala-lang.modules" %%% "scala-parser-combinators" % "1.0.7" ``` ## Contributing * See the [Scala Developer Guidelines](https://github.com/scala/scala/blob/2.12.x/CONTRIBUTING.md) for general contributing guidelines * Have a look at [existing issues](https://github.com/scala/scala-parser-combinators/issues) * Ask questions and discuss [on Gitter](https://gitter.im/scala/scala-parser-combinators)