Scala Parser Combinators alternatives and similar packages
Based on the "Parsing" category.
Alternatively, view Scala Parser Combinators alternatives based on common mentions on social networks and blogs.
-
Kaitai Struct
Kaitai Struct: declarative language to generate binary data parsers in C++ / C# / Go / Java / JavaScript / Lua / Nim / Perl / PHP / Python / Ruby
SaaSHub - Software Alternatives and Reviews
![SaaSHub Logo SaaSHub Logo](https://cdn-b.libhunt.com/assets/partners/saashub-small-09b040e303cf50000aca670e1c77a15c64fc5c073fbdca2665ec2b8b621efc1a.png)
Do you think we are missing an alternative of Scala Parser Combinators or a related project?
README
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
- Current API
- The [Getting Started](docs/Getting_Started.md) guide
- A more complicated example, Building a lexer and parser with Scala's Parser Combinators
- "Combinator Parsing", chapter 33 of Programming in Scala, Third Edition, shows how to apply this library to e.g. parsing of arithmetic expressions. The second half of the chapter examines how the library is implemented.
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](docs/Getting_Started.md).
Contributing
- See the Scala Developer Guidelines for general contributing guidelines
- Have a look at existing issues
- Ask questions and discuss in GitHub Discussions
- Feel free to open draft pull requests with partially completed changes, to get feedback.
Alternatives
A number of other parsing libraries for Scala are available; see https://index.scala-lang.org/awesome/parsing?sort=stars