package cairn

  1. Overview
  2. Docs

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.

  • Parser is the parser_decorated obtained from the modules generated by menhir invocation.
  • 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

Signature

module Parser = Parser
val 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.

val parse : string -> Stdlib.Lexing.lexbuf -> Parser.value_parsed option * ParserLog.configuration list * (string * string * string) list

parse 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).
val parse_interactive : string -> Stdlib.Lexing.lexbuf -> Parser.value_parsed option

parse_interactive text lexbuf parses an input pointed by lexbuf, whose content is text. Displays a terminal user interface allowing to navigate the log of the parser. Then returns the parsed value (if no error was encountered, None otherwise).

val parse_log : string -> Stdlib.Lexing.lexbuf -> string -> string -> Parser.value_parsed option

parse_log text lexbuf log_file error_file parses an input pointed by lexbuf, whose content is text. Writes a log of the parser execution in the file of name log_file and an error log in the file of name error_file. Returns the parsed value (if no error was encountered, None otherwise)

val parse_interactive_or_log : string -> Stdlib.Lexing.lexbuf -> bool -> string option -> string option -> Parser.value_parsed option

parse_log text lexbuf interactive log_file error_file parses an input pointed by lexbuf, whose content is text. Displays a terminal user interface allowing to navigate the log of the parser if interactive is true. Writes a log of the parser execution in the file of name log_file if it is not None and an error log in the file of name error_file if it is not None. Returns the parsed value (if no error was encountered, None otherwise)

OCaml

Innovation. Community. Security.