atto is a compact, pure-functional, incremental text parsing library for Scala. The 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> import atto._, Atto._ import atto._ import Atto._ scala> int.sepBy(spaceChar).parseOnly("1 20 300").option res0: Option[List[Int]] = Some(List(1, 20, 300))
The current version is 0.6.5 for Scala 2.11/12/13 and Scala-JS (2.11+) with cats 1.5.0. Add it to your
libraryDependencies += "org.tpolecat" %% "atto-core" % "0.6.5" libraryDependencies += "org.tpolecat" %% "atto-refined" % "0.6.5"
Documentation and Support
atto differs from stdlib parser combinators in a number of ways:
- You don’t have to extend a trait or implement any methods.
- There is no tokenizer; the input type is always
- Abstractions are better defined, which leads to simpler, more general code.
Parseris a cats
Monadfor example, which gives us a lot of helpful operations for free.
- Parsers are incremental which means you can evaluate whether a prefix of your input is “ok so far.” This can be helpful when working with streams or interactive UIs.
It’s not a big deal to construct and use atto parsers; use them in any situation where you might otherwise reach for regular expressions or raw string manipulation.
Although atto is 50 times faster now than version 0.1, it’s still not the fastest parsing lib on the block. If you’re doing massive data processing you might look at a library like Fastparse, or even a hand-built parser like those used in the fastest JSON libs. But for “everyday” parsing where you have to turn user input into something useful, atto is a friendly little library to use.
The core of atto originated in Edward Kmett’s Scala port of Attoparsec. This library is an elaboration maintained by @tpolecat with contributions from some very helpful folks. Feedback and suggestions are always welcome.