package pratter

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

Install

Dune Dependency

Authors

Maintainers

Sources

pratter-3.0.0.tar.gz
md5=f8ad3611d5702c0dd1ca869c2349663e
sha512=2dca78a5e2d1239c7aaa893c08eb612dad50ade092776ca02fd083209fca805e22520bff78309ef8435a4b900be2a272415efff3a81e1bb1f0a3dec8bcb3e1a4

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: 06 Nov 2023

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.08

  • dune >= 2.7

  • camlp-streams

Then, at the root of the source tree,

$ dune build
$ dune install

You can try the library in the toplevel: the following code defines a parser for the language made of strings interspersed with infix + operators:

# #require "pratter";;
# type t = A of t * t | S of string;;
type t = A of t * t | S of string
# let appl t u = A (t, u);;
val appl : t -> t -> t = <fun>
# let is_op = function S "+" -> Some Pratter.(Infix Left, 0.3) | _ -> None;;
val is_op : t -> (Pratter.operator * float) option = <fun>
# Pratter.expression ~appl ~is_op (Stream.of_list [ S "x"; S "+"; S "y"]);;
- : (t, t Pratter.error) result = Ok (A (A (S "+", S "x"), S "y"))

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 (3)

  1. camlp-streams >= "5.0" & < "6"
  2. dune >= "2.7"
  3. ocaml >= "4.08"

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 (1)

  1. lambdapi >= "2.4.1"

Conflicts

None

OCaml

Innovation. Community. Security.