package pratter

  1. Overview
  2. Docs
Parse strings of tokens and mixfix operators

Install

Dune Dependency

Authors

Maintainers

Sources

pratter-5.0.1.tar.bz2
md5=7a75f978f8746f5745318422d562e361
sha256=1083dd78ef5413366fdd0bcfcdb19a59f92d145f677d89a502a5da109e965cac

Description

Pratter allows to transform strings of symbols and mixfix operators to full binary trees. Pratter is convenient for parsing languages made of terms with many mixfix operators with different associativities and precedences such as arithmetic or λ-calculi. In contrast to parser generators, parsing rules can be edited dynamically.

Published: 09 Apr 2025

README

Pratter

By Gabriel Hondet

Pratter allows to transform strings of symbols and mixfix operators to full binary trees. Pratter is convenient for parsing languages made of terms with many mixfix operators with different associativities and precedences such as arithmetic or λ-calculi. In contrast to parser generators, parsing rules can be edited dynamically.

You are free to copy, modify and distribute Pratter with attribution under the terms of the BSD 3 Clause license. See the license for more details.

Getting started

To compile and use pratter, you need

  • ocaml >= 4.14
  • dune >= 2.7

Then, at the root of the source tree,

$ make install

To ensure it's working write the following code in some file plus.ml

type t = A of t * t | S of string
let appl t u = A (t, u)
let token = Fun.id
let ops = function
  | S "+" as s -> Pratter.[ Infix Left, 0.3, s ]
  | _ -> []
let parse = Pratter.expression ~token ~appl ~ops
let () =
  let input = List.to_seq [ S "x"; S "+"; S "y"] in
  assert (Result.is_ok @@ Pratter.run parse input)

then execute the following lines which should return 0

$ echo "module Pratter = struct $(cat pratter.ml) end $(cat plus.ml)" > plus_.ml
$ ocamlc plus_.ml
$ ./a.out

The aforementioned code defines a parser for the language made of strings interspersed with infix + operators

What next?

  • There's a change log.
  • There's a license.
  • This file is another use case example that is slightly more involved than the one in this readme.

You can raise issues either using the issue tracker or sending an email to <koizel#pratter@aleeas.com>.

Dependencies (2)

  1. dune >= "2.7"
  2. ocaml >= "4.10.0"

Dev Dependencies (4)

  1. odoc with-doc
  2. qcheck-alcotest with-test & >= "0.12"
  3. qcheck with-test & >= "0.12"
  4. alcotest with-test & >= "1.5.0" & < "2"

Used by

None

Conflicts

None

OCaml

Innovation. Community. Security.