Socket
Socket
Sign inDemoInstall

org.scala-lang.modules:scala-parser-combinators_2.13

Package Overview
Dependencies
Maintainers
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

org.scala-lang.modules:scala-parser-combinators_2.13

scala-parser-combinators


Version published
Maintainers
2
Source

scala-parser-combinators

This was originally part of the Scala standard library, but is now community-maintained, under the guidance of the Scala team at 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 in scala/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

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.

Contributing

FAQs

Package last updated on 18 Apr 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc