package nice_parser

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

Module Nice_parserSource

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
Sourcemodule type RAW_PARSER = sig ... end

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

Sourcemodule type NICE_PARSER = sig ... end

The nicified interface to your parser.

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