pacombversion Documentation on ocaml.org

Parsing library based on combinators and ppx extension to write languages

Pacomb is a parsing library that compiles grammars to combinators prior to parsing together with a PPX extension to write parsers inside OCaml files.

The advantages of Pacomb are

  • Grammars as first class values defined in your OCaml files. This is an example from the distribution:

( The three levels of priorities *) type p = Atom | Prod | Sum let%parser rec

          (
This includes each priority level in the next one )
 expr p = Atom < Prod < Sum
        (
all other rule are selected by their priority level )
        ; (p=Atom) (x::FLOAT)                        => x
        ; (p=Atom) '(' (e::expr Sum) ')'             => e
        ; (p=Prod) (x::expr Prod) '
' (y::expr Atom) => x*.y

        ; (p=Prod) (x::expr Prod) '/' (y::expr Atom) => x/.y
        ; (p=Sum ) (x::expr Sum ) '+' (y::expr Prod) => x+.y
        ; (p=Sum ) (x::expr Sum ) '-' (y::expr Prod) => x-.y
  • Good performances:

    • on non ambiguous grammars, 2 to 3 time slower compared to ocamlyacc

    • on ambiguous grammars O(N^3 ln(N)) can be achieved.

  • Parsing from left to right (despite the use of combinators) allowing not to keep the whole input in memory and allowing to parse streams.

  • Dependant sequence allowing for self extensible grammars (like new infix with a given priority in a given example).

  • Managing of blanks that for instance allows for nested language using different kind of comments or blanks.

  • Support for cache and merge for ambiguous grammars (to get O(N^3 ln(N)))

  • Enough support for utf8 to write parser for a language using utf8.

  • Comes with documentation and various examples illustrating most possibilities.

All this makes Pacomb a promising solution to write languages in OCaml.

Tags parsing
AuthorChristophe Raffalli <christophe@raffalli.eu>
LicenseMIT
Published
Homepagehttps://github.com/craff/CamlSurf
Issue Trackerhttps://github.com/craff/CamlSurf/issues
Documentationhttps://raffalli.eu/pacomb
MaintainerChristophe Raffalli <christophe@raffalli.eu>
Dependencies
Source [http] https://github.com/craff/pacomb/archive/refs/tags/1.4.4.tar.gz
md5=17df1ee094890404ec4110f097ac1ab6
sha512=2046537f5dabbe5598c094c4b4e645cd2a4eeb4b3d7fe8fde39659df3398675831f11d2ae3e86069e8a8c350c0725e0299c1571eed2a938f2a3d0c1cc5330804
Edithttps://github.com/ocaml/opam-repository/tree/master/packages/pacomb/pacomb.1.4.4/opam