package cairn

  1. Overview
  2. Docs

Module Parsing.MakeSource

Main functor of this module. It generates a module that can parse a text with the parser provided as an argument, and generates a log of the partial derivations produced along the run of the parser, a log of errors encountered (several errors supported if generated with PopFirst strategy), and can display a tui explorer of the sequence of partial derivations produced by the parser.

  • T is a module containing the type of value returned by the main parsing function of Parser.
  • Parser is the parser generated by menhir that need to be logged. Assumes the parsing function to be used is name main (if it is not the case, you have to rename the function inside Parser).
  • Lexer is a module containing a lexing function which is expected to be named token. Compatible with a lexer generated with ocamllex whose main function is named token. If not, providing the needed function and renaming it token in an ad-hoc module is enough.
  • ParserMessages is the module of type parser_messages obtained by menhir with option --compile-errors and filled in by the user.
  • Grammar is the module of type MenhirSdk.Cmly_api.GRAMMAR that has been read from a cmly file produced by menhir with option --cmly.

Parameters

module T : sig ... end
module Lexer : sig ... end

Signature

Sourceval state_to_lr0_list : int -> string list

Function that associates to a lr1 state number a list of string representing the lr0 items it contains.

Sourceval parse_to_derivation : ?strategy:error_strategy -> string -> Lexing.lexbuf -> T.value_parsed option * ParserLog.configuration list * (string * string * string) list

parse_to_derivation text lexbuf parses an input pointed by lexbuf whose content is text. text and lexbuf might be obtained with MenhirLib.LexerUtil. It returns (value,log,errors), where:

  • value is either Some value if the parser produced a semantical value or None.
  • log is a configuration list that represents the execution of the parser (to be used with functions from ParserLog alongside state_to_lr0_list).
  • errors is a list of error messages encountered along the execution, in order to which they appeared. If this list is not empty, value should probably not be trusted. The first string is the position of the error, the second the two tokens between which the error occured, and the last an explanation (from the ParserMessages provided).

The optional argument ?strategy controls which error_strategy is used if an error is encountered. Defaults to Stop.

Sourceval parse : ?strategy:error_strategy -> ?interactive:bool -> ?log_file:string -> ?error_file:string -> string -> Lexing.lexbuf -> T.value_parsed option

parse text lexbuf parses an input pointed by lexbuf, whose content is text, computes the log of its derivation, and depending of its optional arguments, can display a terminal user interface allowing to navigate the log of the parser, and save the log and error log into external files. Then returns the parsed value (if no error was encountered, None otherwise).

  • ?strategy controls which error_strategy is used if an error is encountered. Defaults to Stop.
  • ?interactive controls whether the terminal user interface is displayed or not. Defaults to true.
  • if ?log_file is provided, the log of the derivation will be saved in a file of that name.
  • if ?error_file is provided, the error log will be saved in a file of that name.
Sourceval parse_string : ?strategy:error_strategy -> ?interactive:bool -> ?log_file:string -> ?error_file:string -> string -> T.value_parsed option

parse_string string parses the string string, and has the same functionalities as parse. It simply wraps the creation of the buffer.

Sourceval parse_file : ?strategy:error_strategy -> ?interactive:bool -> ?log_file:string -> ?error_file:string -> string -> T.value_parsed option

parse_file file parses the content of the file file, and has the same functionalities as parse. It simply wraps the creation of the buffer.