chomp/pratt

This module is very similar to the elm-pratt-parser package in the Elm ecosystem, and much of its docs apply to this module.

Types

pub opaque type Config(a, e, tok, ctx)
pub opaque type Operator(a, e, tok, ctx)
pub type Precedence {
  Left(Int)
  Right(Int)
}

Constructors

  • Left(Int)
  • Right(Int)

Functions

pub fn expression(
  one_of first: List(fn(Config(a, b, c, d)) -> Parser(a, b, c, d)),
  or_error or_error: b,
  and_then then: List(Operator(a, b, c, d)),
) -> Parser(a, b, c, d)
pub fn infix(
  precedence: Precedence,
  operator: Parser(a, b, c, d),
  apply: fn(e, e) -> e,
) -> Operator(e, b, c, d)
pub fn infix_custom(
  precedence: Precedence,
  operator: fn(Config(a, b, c, d)) -> Parser(e, b, c, d),
  apply: fn(a, a, e) -> a,
) -> Operator(a, b, c, d)
pub fn operator_custom(
  build: fn(Config(a, b, c, d)) ->
    #(Int, fn(a) -> Parser(a, b, c, d)),
) -> Operator(a, b, c, d)
pub fn postfix(
  precedence: Int,
  operator: Parser(a, b, c, d),
  apply: fn(e) -> e,
) -> Operator(e, b, c, d)
pub fn postfix_custom(
  precedence: Int,
  operator: fn(Config(a, b, c, d)) -> Parser(e, b, c, d),
  apply: fn(a, e) -> a,
) -> Operator(a, b, c, d)
pub fn prefix(
  precedence: Int,
  operator: Parser(a, b, c, d),
  apply: fn(e) -> e,
) -> fn(Config(e, b, c, d)) -> Parser(e, b, c, d)
pub fn prefix_custom(
  precedence: Int,
  operator: fn(Config(a, b, c, d)) -> Parser(e, b, c, d),
  apply: fn(a, e) -> a,
) -> fn(Config(a, b, c, d)) -> Parser(a, b, c, d)
pub fn sub_expression(
  config: Config(a, b, c, d),
  precedence: Int,
) -> Parser(a, b, c, d)
Search Document