Coder Social home page Coder Social logo

pebsconsulting / scala-parser-combinators Goto Github PK

View Code? Open in Web Editor NEW

This project forked from scala/scala-parser-combinators

0.0 2.0 0.0 489 KB

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

License: BSD 3-Clause "New" or "Revised" License

Shell 1.82% Scala 98.18%

scala-parser-combinators's Introduction

scala-parser-combinators Gitter

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

(Assuming you're using a scalaVersion for which a scala-parser-combinators is published. The first 2.11 milestone for which this is true is 2.11.0-M4.)

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

Example

import scala.util.parsing.combinator._

case class WordFreq(word: String, count: Int) {
    override def toString = "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("FAILURE: " + msg)
            case Error(msg,_) => println("ERROR: " + msg)
        }
    }
}

For a detailed unpacking of this example see Getting Started.

ScalaJS support

Scala-parser-combinators directly supports scala-js 0.6+, starting with v1.0.5:

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

Contributing

scala-parser-combinators's People

Contributors

gourlaysama avatar adriaanm avatar paulp avatar odersky avatar gkossakowski avatar lrytz avatar dchenbecker avatar liskin avatar retronym avatar raboof avatar soc avatar kzys avatar heathermiller avatar dragos avatar sethtisue avatar egulias avatar toddobryan-amazon avatar som-snytt avatar milessabin avatar dcsobral avatar blair avatar jroper avatar janekdb avatar propensive avatar ladinu avatar nimishgupta avatar stephenjudkins avatar tiarkrompf avatar zandbee avatar hrj avatar

Watchers

James Cloos 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.