package catala

  1. Overview
  2. Docs

Wrapping module around parser and lexer that offers the parse_source_file API

module Pos = Utils.Pos
module Errors = Utils.Errors
module Cli = Utils.Cli

Internal functions

val state : 'semantic_value I.env -> int

Returns the state number from the Menhir environment

val minimum : 'a -> 'b -> 'c -> 'd

Three-way minimum

val levenshtein_distance : string -> string -> int

Computes the levenshtein distance between two strings, used to provide error messages suggestions

val syntax_hints_style : ANSITerminal.style list

Style with which to display syntax hints in the terminal output

val raise_parser_error : Pos.t -> Pos.t option -> string -> string -> 'a

Usage: raise_parser_error error_loc last_good_loc token msg

Raises an error message featuring the error_loc position where the parser has failed, the token on which the parser has failed, and the error message msg. If available, displays last_good_loc the location of the last token correctly parsed.

val fail : Sedlexing.lexbuf -> 'semantic_value I.env -> (string * Parser.token) list -> 'semantic_value0 I.env option -> 'a

Usage: fail lexbuf env token_list last_input_needed

Raises an error with meaningful hints about what the parsing error was. lexbuf is the lexing buffer state at the failure point, env is the Menhir environment and last_input_needed is the last checkpoint of a valid Menhir state before the parsing error. token_list is provided by things like Surface.Lexer.token_list_language_agnostic and is used to provide suggestions of the tokens acceptable at the failure point

val loop : (unit -> Parser.token * Stdlib.Lexing.position * Stdlib.Lexing.position) -> (string * Parser.token) list -> Sedlexing.lexbuf -> Ast.source_file_or_master I.env option -> Ast.source_file_or_master I.checkpoint -> Ast.source_file_or_master

Main parsing loop

val sedlex_with_menhir : (Sedlexing.lexbuf -> Parser.token) -> (string * Parser.token) list -> (Stdlib.Lexing.position -> Ast.source_file_or_master I.checkpoint) -> Sedlexing.lexbuf -> Ast.source_file_or_master

Stub that wraps the parsing main loop and handles the Menhir/Sedlex type difference for lexbuf.

API

val parse_source_file : string -> Cli.frontend_lang -> Ast.program

Parses a single source file

val expand_includes : string -> Ast.program_item list -> Cli.frontend_lang -> Ast.program

Expands the include directives in a parsing result, thus parsing new source files