- Notifications
You must be signed in to change notification settings - Fork131
simple combinator-based parsing for Scala. formerly part of the Scala standard library, now a separate community-maintained module
License
scala/scala-parser-combinators
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
This library is now community-maintained. If you are interested in helping please contact @gourlaysama or mention iton 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.
- Current API
- TheGetting Started guide
- A more complicated example,Building a lexer and parser with Scala's Parser Combinators
- "Combinator Parsing", chapter 33 ofProgramming in Scala, Third Edition, shows how to use this library to parse arithmetic expressions and JSON. The second half of the chapter examines how the library is implemented.
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.7"
(Assuming you're using ascalaVersion
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 inhttps://github.com/scala/scala-module-dependency-sample.
importscala.util.parsing.combinator._caseclassWordFreq(word:String,count:Int) {overridedeftoString="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("FAILURE:"+ msg)caseError(msg,_)=> println("ERROR:"+ msg) } }}
For a detailed unpacking of this example seeGetting Started.
Scala-parser-combinators directly supports scala-js 0.6+, starting with v1.0.5:
libraryDependencies += "org.scala-lang.modules" %%% "scala-parser-combinators" % "1.0.7"
- See theScala Developer Guidelines for general contributing guidelines
- Have a look atexisting issues
- Ask questions and discusson Gitter
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
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.