Skip to content

simple combinator-based parsing for Scala. formerly part of the Scala standard library, now a separate community-maintained module

License

Notifications You must be signed in to change notification settings

scala/scala-parser-combinators

 
 

Repository files navigation

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.

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

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.1.2" 

To support multiple Scala versions, see the example in scala/scala-module-dependency-sample.

Example

importscala.util.parsing.combinator._caseclassWordFreq(word: String, count: Int) { overridedeftoString=s"Word <$word> occurs with frequency $count" } classSimpleParserextendsRegexParsers { defword:Parser[String] ="""[a-z]+""".r ^^ { _.toString } defnumber:Parser[Int] ="""(0|[1-9]\d*)""".r ^^ { _.toInt } deffreq:Parser[WordFreq] = word ~ number ^^ { case wd ~ fr =>WordFreq(wd,fr) } } objectTestSimpleParserextendsSimpleParser { defmain(args: Array[String]) = { parse(freq, "johnny 121") match { caseSuccess(matched,_) => println(matched) caseFailure(msg,_) => println(s"FAILURE: $msg") caseError(msg,_) => println(s"ERROR: $msg") } } }

For a detailed unpacking of this example see Getting Started.

ScalaJS support

Scala-parser-combinators directly supports Scala.js 0.6+:

libraryDependencies += "org.scala-lang.modules" %%% "scala-parser-combinators" % "1.1.2" 

Issues

Many old issues from the Scala JIRA issue tracker have been migrated here, but not all of them. Community assistance identifying and migrating still-relevant issues is welcome. See this page for details.

Contributing

About

simple combinator-based parsing for Scala. formerly part of the Scala standard library, now a separate community-maintained module

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages

close