Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

License

NotificationsYou must be signed in to change notification settings

scala/scala-parser-combinators

Repository files navigation

build

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 library

This library's main strengths are:

  • Stability. It's been around and in wide use for more than a decade.
  • The codebase is modest in size and its internals are fairly simple.
  • It's plain vanilla Scala. No macros, code generation, or other magic is involved.
  • Multiple versions of Scala (2.12, 2.13, 3) are supported on all back ends (JVM, JS, Native).

Its main weaknesses are:

  • Performance. If you are ingesting large amounts of data, you may want something faster.
  • Minimal feature set.
  • Inflexible, unstructured error reporting.

A number of other parsing libraries for Scala are available --see list on Scaladex.

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" % <version>

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

Scala.js and Scala Native

Scala-parser-combinators is also available for Scala.js and Scala Native:

libraryDependencies += "org.scala-lang.modules" %%% "scala-parser-combinators" % <version>

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 seeGetting Started.

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


[8]ページ先頭

©2009-2025 Movatter.jp