Code Monkey home page Code Monkey logo

scala-parser-combinators's Introduction

scala-parser-combinators

Scala Standard Parser Combinator Library

This library is now community-maintained. If you are interested in helping please contact @Philippus or @SethTisue.

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.

Scala.js and Scala Native

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

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

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.

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

scala-parser-combinators's People

Contributors

adriaanm avatar blair avatar ckampfe avatar dchenbecker avatar dcsobral avatar dragos avatar eed3si9n avatar egulias avatar filipochnik avatar gkossakowski avatar gourlaysama avatar heathermiller avatar jroper avatar julienrf avatar kzys avatar liskin avatar lrytz avatar milessabin 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

Watchers

 avatar  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.