<commit_before>(* elpi: embedded lambda prolog interpreter                                  *)
(* license: GNU Lesser General Public License Version 2.1 or later           *)
(* ------------------------------------------------------------------------- *)

(** This module is the API for clients of the ELPI library.
    
    The modules {!module:Setup}, {!module:Parse}, {!module:Compile} and
    {!module:Execute} let one run code, and {!module:Pp} print the result.
    Modules {!module:Ast} and {!module:Data} mostly contain opaque data types
    declarations.

    The sub module {!module:Extend} groups the APIs to extend ELPI.
    It provides richer {!module:Ast} and {!module:Data} submodules where the
    data types are made transparent.
    Module {!module:Extend.Compile} lets one register new \{\{quotations\}\}.
    Modules {!module:Extend.BuiltInPredicate} and
    {!module:Extend.CustomState} let one register built-in predicates and
    custom state. *)

(* ************************************************************************* *)
(* *************************** Basic API *********************************** *)
(* ************************************************************************* *)


module Setup : sig

  (* Built-in predicates, see {!module:Extend.BuiltInPredicate} *)
  type builtins
  type program_header

  (** Initialize ELPI.
      [init] must be called before invoking the parser.
      [silent] (default [true]) to avoid printing files being loaded.
      [builtins] the set of built-in predicates, eg [Elpi_builtin.std_builtins] 
      [basedir] current working directory (used to make paths absolute);
      [argv] is list of options, see the {!val:usage} string;
      It returns part of [argv] not relevant to ELPI and a [program_header]
      that contains the declaration of builtins. *)
  val init :
    ?silent:bool ->
    builtins:builtins ->
    basedir:string ->
    string list -> program_header * string list

  (** Usage string *)
  val usage : string

  (** Set tracing options.
      [trace argv] can be called before {!module:Execute}.
      [argv] is expected to only contain options relevant for
      the tracing facility. *)
  val trace : string list -> unit

  (** Override default error functions (they call exit) *)
  val set_warn : (string -> unit) -> unit
  val set_error : (string -> 'a) -> unit
  val set_anomaly : (string -> 'a) -> unit
  val set_type_error : (string -> 'a) -> unit
  val set_std_formatter : Format.formatter -> unit
  val set_err_formatter : Format.formatter -> unit
end

module Ast : sig
  type program
  type query
end

module Parse : sig

  (** [program file_list] parses a list of files *)
  val program : string list -> Ast.program
  val program_from_stream : char Stream.t -> Ast.program

  (** [goal file_list] parses the query *)
  val goal : string -> Ast.query
  val goal_from_stream : char Stream.t -> Ast.query

end

module Data : sig
  
  module StrMap : Map.S with type key = string

  (* what is assigned to the query variables *)
  type term

  (* goals suspended via the declare_constraint built-in *)
  type syntactic_constraints

  (* user defined state (not goals) *)
  type custom_state

  (* a solution is an assignment map from query variables (name) to terms,
   * plus the goals that were suspended and the user defined constraints *)
  type solution = {
    assignments : term StrMap.t;
    constraints : syntactic_constraints;
    state : custom_state;
  }

end

module Compile : sig

  module StrSet : Set.S with type elt = string
  type flags = {
    (* variables used in conditional compilation, that is :if clauses *)
    defined_variables : StrSet.t;
    (* disable check that all built-in must come with a type declaration *)
    allow_untyped_builtin : bool;
  }
  val default_flags : flags

  type program
  type query
  type executable

  (* Warning: this API will change to support separate compilation of
   * Ast.program, esp the [link] one *)

  (* compile all program files *)<commit_msg>API: StrMap and StrSet come with pp and show<commit_after>(* elpi: embedded lambda prolog interpreter                                  *)
(* license: GNU Lesser General Public License Version 2.1 or later           *)
(* ------------------------------------------------------------------------- *)

(** This module is the API for clients of the ELPI library.
    
    The modules {!module:Setup}, {!module:Parse}, {!module:Compile} and
    {!module:Execute} let one run code, and {!module:Pp} print the result.
    Modules {!module:Ast} and {!module:Data} mostly contain opaque data types
    declarations.

    The sub module {!module:Extend} groups the APIs to extend ELPI.
    It provides richer {!module:Ast} and {!module:Data} submodules where the
    data types are made transparent.
    Module {!module:Extend.Compile} lets one register new \{\{quotations\}\}.
    Modules {!module:Extend.BuiltInPredicate} and
    {!module:Extend.CustomState} let one register built-in predicates and
    custom state. *)

(* ************************************************************************* *)
(* *************************** Basic API *********************************** *)
(* ************************************************************************* *)


module Setup : sig

  (* Built-in predicates, see {!module:Extend.BuiltInPredicate} *)
  type builtins
  type program_header

  (** Initialize ELPI.
      [init] must be called before invoking the parser.
      [silent] (default [true]) to avoid printing files being loaded.
      [builtins] the set of built-in predicates, eg [Elpi_builtin.std_builtins] 
      [basedir] current working directory (used to make paths absolute);
      [argv] is list of options, see the {!val:usage} string;
      It returns part of [argv] not relevant to ELPI and a [program_header]
      that contains the declaration of builtins. *)
  val init :
    ?silent:bool ->
    builtins:builtins ->
    basedir:string ->
    string list -> program_header * string list

  (** Usage string *)
  val usage : string

  (** Set tracing options.
      [trace argv] can be called before {!module:Execute}.
      [argv] is expected to only contain options relevant for
      the tracing facility. *)
  val trace : string list -> unit

  (** Override default error functions (they call exit) *)
  val set_warn : (string -> unit) -> unit
  val set_error : (string -> 'a) -> unit
  val set_anomaly : (string -> 'a) -> unit
  val set_type_error : (string -> 'a) -> unit
  val set_std_formatter : Format.formatter -> unit
  val set_err_formatter : Format.formatter -> unit
end

module Ast : sig
  type program
  type query
end

module Parse : sig

  (** [program file_list] parses a list of files *)
  val program : string list -> Ast.program
  val program_from_stream : char Stream.t -> Ast.program

  (** [goal file_list] parses the query *)
  val goal : string -> Ast.query
  val goal_from_stream : char Stream.t -> Ast.query

end

module Data : sig
  
  module StrMap : sig
   include Map.S with type key = string
   val show : (Format.formatter -> 'a -> unit) -> 'a t -> string
   val pp : (Format.formatter -> 'a -> unit) -> Format.formatter -> 'a t -> unit
  end

  (* what is assigned to the query variables *)
  type term

  (* goals suspended via the declare_constraint built-in *)
  type syntactic_constraints

  (* user defined state (not goals) *)
  type custom_state

  (* a solution is an assignment map from query variables (name) to terms,
   * plus the goals that were suspended and the user defined constraints *)
  type solution = {
    assignments : term StrMap.t;
    constraints : syntactic_constraints;
    state : custom_state;
  }

end

module Compile : sig

  module StrSet : sig
   include Set.S with type elt = string
   val show : t -> string
   val pp : Format.formatter -> t -> unit
  end

  type flags = {
    (* variables used in conditional compilation, that is :if clauses *)
    defined_variables : StrSet.t;
    (* disable check that all built-in must come with a type declaration *)
    allow_untyped_builtin : bool;
  }
  val default_flags : flags

  type program
  type query
  type executable

  (* Warning: this API will change to support separate compilation of
   * Ast.program, esp the [link] one *)

  (* compile all program files *)
{'fraction_non_alphanumeric': 0.15812890812890812, 'fraction_numerical': 0.000481000481000481, 'mean_word_length': 3.049172346640701, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 53, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3693704', 'n_tokens_mistral': 2317, 'n_tokens_neox': 2215, 'n_words': 888}