package nice_parser

  1. Overview
  2. Docs

Module Nice_parser.MakeSource

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

Parameters

module P : RAW_PARSER

Signature

Types

Inherited from RAW_PARSER.

Sourcetype token = P.token
Sourcetype result = P.result

Exceptions

Nice exceptions include the location at which an error occured. A nice ParseErrror also includes the token which caused the parser to choke, which can be useful for debugging.

Sourceexception LexError of {
  1. msg : string;
  2. loc : Location.t;
}
Sourceexception ParseError of {
  1. token : token;
  2. loc : Location.t;
}
Sourceval pp_exceptions : unit -> unit

Registers a pretty printer for LexError and ParseError. This results in colorful error messages including the source location when errrors occur. With OCaml >= 4.08, the pretty printer will also quote the problematic location in the soure code and underline the error location, like so:

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

Parsing

Sourceval parse_string : ?pos:Lexing.position -> string -> result
Sourceval parse_chan : ?pos:Lexing.position -> in_channel -> result
Sourceval parse_file : string -> result
OCaml

Innovation. Community. Security.