GithubHelp home page GithubHelp logo

isabella232 / scala-parser-combinators Goto Github PK

View Code? Open in Web Editor NEW

This project forked from scala/scala-parser-combinators

0.0 0.0 0.0 1011 KB

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

License: Apache License 2.0

Scala 100.00%

scala-parser-combinators's Introduction

scala-parser-combinators

Scala Standard Parser Combinator Library

This library 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 helping please contact @Philippus or @SethTisue.

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

Alternatives

A number of other parsing libraries for Scala are available; see https://github.com/lauris/awesome-scala#parsing

scala-parser-combinators's People

Contributors

adriaanm avatar dchenbecker avatar dcsobral avatar dragos avatar eed3si9n avatar egulias avatar filipochnik avatar gkossakowski avatar gourlaysama avatar heathermiller avatar ilya-klyuchnikov avatar julienrf avatar kzys avatar liskin avatar lrytz avatar martingd avatar milessabin avatar nthportal avatar odersky avatar paulp avatar philippus avatar raboof avatar retronym avatar scala-steward avatar sethtisue avatar soc avatar som-snytt avatar sudohalt avatar toddobryan-amazon avatar xuwei-k avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.