Module Cobol_parser

Exported modules

module Options : sig ... end

Options to tune the parser engine

module Outputs : sig ... end

Output types for the engine

module Diagnostics : sig ... end
module Tokens : sig ... end
module Expect : sig ... end
module Printer : sig ... end
module Keywords : sig ... end
module Grammar_interpr : sig ... end

Exported functions

Basic (one-shot) parsing

type 'm simple_parsing = options:Cobol_parser__.Parser_options.parser_options -> Cobol_preproc.preprocessor -> (Cobol_ptree.compilation_group option, 'm) Cobol_parser__.Parser_outputs.output Cobol_common__Diagnostics_accumulator.MAKE(Cobol_parser__.Parser_diagnostics.ALL).TYPES.with_diags

Simple parsing functions traverse the inputs once to produce a result.

Simple parsing function that does not return any artifact.

Simple parsing function does return some artifacts.

Rewindable parsing

type 'm rewindable_parsing = options:Cobol_parser__.Parser_options.parser_options -> Cobol_preproc.preprocessor -> ((Cobol_ptree.compilation_group option, 'm) Cobol_parser__.Parser_outputs.output as 'x * 'x rewinder) Cobol_common__Diagnostics_accumulator.MAKE(Cobol_parser__.Parser_diagnostics.ALL).TYPES.with_diags

Rewindable parsing functions extend the behaviors of simple parsing functions, with the ability to rewind the parser (and pre-processor) before a given lexing position. To this end, their results include a rewinder that may then be given to rewind_and_parse.

and 'x rewinder

Rewinder for parsing functions that produce results of type 'x

and preprocessor_rewind = last_pp:Cobol_preproc.preprocessor as 'r -> ?new_position:Stdlib.Lexing.position -> 'r -> 'r

Functions for rewinding the pre-processor. Such a function should return a preprocessor in the exact same state as the one given in (unlabelled) argument, with the only exception that the input text is now read from new_position.

last_pp is the state of the pre-processor at the end of the previous call to rewindable_parse_simple, rewindable_parse_with_artifacts, or rewind_and_parse operation: it may be used to translate positions that follow the last piece of input seen by the unlabelled preprocessor argument.

If new_position is not given, the text should be read from the very beginning of the input.

Rewindable parsing function that does not return any artifact.

val rewindable_parse_with_artifacts : Cobol_common.Behaviors.eidetic rewindable_parsing

Rewindable parsing function that does return some artifacts.

type position =
  1. | Lexing of Stdlib.Lexing.position
    (*

    raw lexing position

    *)
  2. | Indexed of {
    1. line : int;
      (*

      line number (starting from 0)

      *)
    2. char : int;
      (*

      character number in line (starting from 0)

      *)
    }

Specification of positions to rewind to.

val rewind_and_parse : 'x rewinder -> preprocessor_rewind -> position:position -> ((Cobol_ptree.compilation_group option, 'm) Cobol_parser__.Parser_outputs.output as 'x * 'x rewinder) Cobol_common__Diagnostics_accumulator.MAKE(Cobol_parser__.Parser_diagnostics.ALL).TYPES.with_diags

rewind_and_parse rewinder preprocessor_rewind ~position uses rewinder to restart parsing before the given position. Note that the new_position argument that is given to preprocessor_rewind may not correspond to position, as the parser typically needs to rewind earlier than position.

Rewinding for inspection

type inspectable_parser_state =
  1. | Sink

Type of parser states that can be inspected using the interpreter that is generated by menhir (cf INSPECT).

val rewind_for_inspection : 'x rewinder -> preprocessor_rewind -> position:position -> inspect:(inspectable_parser_state -> 'a) -> 'a

Note: given parser state should not escapre inspect.

Accessing artifacts

val artifacts : (_, Cobol_common.Behaviors.eidetic) Cobol_parser__.Parser_outputs.output -> Cobol_parser__.Parser_outputs.artifacts

Modules and functions exported for testing purposes

Signatures of modules below may change unexpectedly.

module INTERNAL : sig ... end