Crate chumsky[][src]

Expand description

A friendly parser combinator crate that makes writing LL(1) parsers with error recovery easy.

Example

Here follows a Brainfuck parser. See examples/ for the full interpreter.

use chumsky::prelude::*;

#[derive(Clone)]
enum Instr {
    Invalid,
    Left, Right,
    Incr, Decr,
    Read, Write,
    Loop(Vec<Self>)
}

fn parser() -> impl Parser<char, Vec<Instr>, Error = Simple<char>> {
    use Instr::*;
    recursive(|bf| bf.delimited_by('[', ']').map(|xs| xs.map_or(Invalid, Loop))
        .or(just('<').to(Left))
        .or(just('>').to(Right))
        .or(just('+').to(Incr))
        .or(just('-').to(Decr))
        .or(just(',').to(Read))
        .or(just('.').to(Write))
        .repeated())
}

Features

  • Generic combinator parsing
  • Error recovery
  • Recursive parsers
  • Text-specific parsers & utilities
  • Custom error types

Modules

Combinators that allow combining and extending existing parsers.

Error types, traits and utilities.

Commonly used functions, traits and types.

Parser primitives that accept specific token patterns.

Recursive parsers (parser that include themselves within their patterns).

Token streams and behaviours.

Text-specific parsers and utilities.

Traits

A trait implemented by parsers.