atto is a compact, pure-functional, incremental text parsing library for Scala (if you're looking for binary parsing, please turn your attention to scodec). The atto API is non-invasive (nothing to extend!) and uses sensible and familiar abstractions. atto parsers are a fun and principled tool for everyday parsing.
scala> sepBy(int, spaceChar).parseOnly("1 20 300").option
res0: Option[List[Int]] = Some(List(1, 20, 300))
The current version (0.2.1) runs on Scala 2.10 and 2.11 with scalaz 7.0.
Add atto as a dependency in your build.sbt
file. The atto-core
library is probably all you need, but if you are using Spire and want parsers for unsigned integral types you can also add atto-spire
.
resolvers += "tpolecat" at "http://dl.bintray.com/tpolecat/maven"
libraryDependencies ++= Seq(
"org.tpolecat" %% "atto-core" % "0.2.1", // Core parsers and combinators
"org.tpolecat" %% "atto-spire" % "0.2.1" // Optional, parsers for unsigned integral types
)
New! Experimental integration with scalaz-stream is provided by atto-stream
, which can be added as above. This tiny library provides combinators to turn Parser[A]
into Process1[String, A]
with a few variations. There is a very basic example given here.
Behold:
- A wee REPL tutorial. (The only change from the 0.1 version is the new import for Spire combinators).
- A variety of tasty examples.
- Here's the Scaladoc but it's kind of grim at the moment.
- Read the source! Perhaps start with the parser definitions.
The core of atto originated in @ekmett's Scala port of Attoparsec. This library is an elaboration maintained by @tpolecat with contributions from @runarorama, @marcsaegesser, and @coltfred. Feedback (complaints especially) and suggestions are always welcome.
Attoparsec, a Haskell library, is licensed under BSD-3 as specified here; the derivative work atto is provided under the MIT licence here. Both licenses appear in project metadata.