Wiki

Clone wiki

Parsec for Scala / Home

Parsec for Scala

Welcome to the Parsec for Scala library for Scala 2.11.8 and upwards. This is based off of the excellent Parsec library for Haskell which can be found here. I've developed the core functionality of this library, and added on my own extensions.

There are a few differences with the original parsec, including the removal of the Monad Transformer. In it's place we have stackable parser extensions, which allow us to add additional components to parser state and therefore combine different additional parser behaviours. This is covered in full in the tutorials. The other differences with the original parsec can also be found in the Wiki.

Core Concepts

Documentation

  • parsec.ParsecE - Core functionality of parsers
  • parsec.Prim - Primitive operations
  • parsec.Char - Common character parsers
  • parsec.Combinator - Common parser combinators
  • parsec.Token - Tokeniser
  • parsec.Expr - Simple Expression parser
  • parsec.Perm - Permutation parsers
  • parsec.Indent - Indentation sensitive parsing extension

Tutorial

  • Types - Unravelling the Types; An in-depth discussion of the Parsec type synonyms and how they affect your usage of Parsec
  • Tiny Basic - Implementing a subset of the BASIC programming language, as modified by Dr. Nicholas Wu from Bristol University.

Examples

#!scala
import parsec.Char.string
val helloworld: Parser[String] = string("hello world")
println(runParser[Stream[String, Char], Unit, String](helloworld, (), "", "hello world!"))

Updated