liveBook · Manning

Parsing library

As explained in Functional Programming in Scala, Second Edition

A parsing library is a software library that provides abstractions and operations for recognizing and processing structured input.

A parsing library provides composable parsers for recognizing and processing structured string input. Its design balances expressive grammars, speed, and precise error reporting: malformed input should identify both where parsing failed and why. section 9.1

Algebraic design starts with parser operations and their laws before choosing representations. Simple repeated-letter and gibberish examples expose the essential combinators before practical formats such as JSON or HTML. section 9.1

A small parser interface grows through reusable operations:

  • Recognize a character with char and a complete string with string. section 9.1
  • Run a parser against a String and return either a parse error or a result. section 9.1
  • Combine alternatives with or, and repeat a parser with listOfN. section 9.1

Combining alternatives and repetition

The parser (string("ab") | string("cad")).listOfN(3) accepts "ababcad" as List("ab", "ab", "cad"), and also accepts the same alternatives in other orders. section 9.1

trait Parsers[ParseError, Parser[+_]]:      #1
 
  extension [A](p: Parser[A]) def run(input: String): Either[ParseError, A]
 
  def char(c: Char): Parser[Char]           #2

Browse the compact parser-library interface: Parser, run, and char show how primitive recognition and execution fit together. section 9.1

How Functional Programming in Scala, Second Edition covers it

How deep it goes
Develops an algebra and combinators through examples, then applies them to a JSON parser without detailing implementation internals.
Examples
Uses character, string, alternative, and fixed-length repetition parsers over examples such as "a", "abra", and "cad".
What you can do after
Build parsers from primitive recognizers and combinators, then apply the design to structured formats such as JSON.
How it connects
Connects parser combinators with algebraic design, functional library design, parse errors, and JSON parsing.

This explainer was generated by Manning's knowledge graph from the text of Functional Programming in Scala, Second Edition. The section links point to the parts of the book it draws on.