package nice_parser

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type

Eliminates Boilerplate code that can be shared among all parsers, providing a sane interface to {menhir, ocamlyacc}-generated parser.

Simply pass your auto-generated parser to the Make functor to nicify its interface:

(* parser.ml *)
include Nice_parser.Make(struct
  (* hook up your auto-generated parser here *)
  ...
end)

Among other benefits, this will make your parser produce beautiful error messages like this (see NICE_PARSER.pp_exceptions):

File "examples/illegal.katbb", line 1, characters 10-17:
1 | this!; is illegal!; isntit?
              ^^^^^^^
Error: [parser] unexpected token
module type RAW_PARSER = sig ... end

The raw interface to an auto-generated parser/lexer pair.

module type NICE_PARSER = sig ... end

The nicified interface to your parser.

module Make (P : RAW_PARSER) : NICE_PARSER with type token = P.token and type result = P.result

Pass your parser/lexer to this functor to obtain a nicer interface, without having to write boilerplate code.

OCaml

Innovation. Community. Security.