Page
Library
Module
Module type
Parameter
Class
Class type
Source
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.
To compile and use pratter, you need
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"))
You can raise issues either using the issue tracker or sending an email to <koizel#pratter@aleeas.com>
.