ocaml/parsing/ast_helper.mli

302 lines
15 KiB
OCaml
Raw Normal View History

(***********************************************************************)
(* *)
(* OCaml *)
(* *)
(* Alain Frisch, LexiFi *)
(* *)
(* Copyright 2012 Institut National de Recherche en Informatique et *)
(* en Automatique. All rights reserved. This file is distributed *)
(* under the terms of the Q Public License version 1.0. *)
(* *)
(***********************************************************************)
(** Helpers to produce Parsetree fragments *)
open Parsetree
open Asttypes
type lid = Longident.t loc
type str = string loc
type loc = Location.t
type attrs = attribute list
val default_loc: loc ref
(** Default value for all optional location arguments. *)
val with_default_loc: loc -> (unit -> 'a) -> 'a
(** Set the [default_loc] within the scope of the execution
of the provided function. *)
module Typ :
sig
val mk: ?loc:loc -> ?attrs:attrs -> core_type_desc -> core_type
val attr: core_type -> attribute -> core_type
val any: ?loc:loc -> ?attrs:attrs -> unit -> core_type
val var: ?loc:loc -> ?attrs:attrs -> string -> core_type
val arrow: ?loc:loc -> ?attrs:attrs -> label -> core_type -> core_type -> core_type
val tuple: ?loc:loc -> ?attrs:attrs -> core_type list -> core_type
val constr: ?loc:loc -> ?attrs:attrs -> lid -> core_type list -> core_type
val object_: ?loc:loc -> ?attrs:attrs -> (string * core_type) list -> closed_flag -> core_type
val class_: ?loc:loc -> ?attrs:attrs -> lid -> core_type list -> label list -> core_type
val alias: ?loc:loc -> ?attrs:attrs -> core_type -> string -> core_type
val variant: ?loc:loc -> ?attrs:attrs -> row_field list -> closed_flag -> label list option -> core_type
val poly: ?loc:loc -> ?attrs:attrs -> string list -> core_type -> core_type
val package: ?loc:loc -> ?attrs:attrs -> lid -> (lid * core_type) list -> core_type
val extension: ?loc:loc -> ?attrs:attrs -> extension -> core_type
val force_poly: core_type -> core_type
end
module Pat:
sig
val mk: ?loc:loc -> ?attrs:attrs -> pattern_desc -> pattern
val attr:pattern -> attribute -> pattern
val any: ?loc:loc -> ?attrs:attrs -> unit -> pattern
val var: ?loc:loc -> ?attrs:attrs -> str -> pattern
val alias: ?loc:loc -> ?attrs:attrs -> pattern -> str -> pattern
val constant: ?loc:loc -> ?attrs:attrs -> constant -> pattern
val tuple: ?loc:loc -> ?attrs:attrs -> pattern list -> pattern
val construct: ?loc:loc -> ?attrs:attrs -> lid -> pattern option -> bool -> pattern
val variant: ?loc:loc -> ?attrs:attrs -> label -> pattern option -> pattern
val record: ?loc:loc -> ?attrs:attrs -> (lid * pattern) list -> closed_flag -> pattern
val array: ?loc:loc -> ?attrs:attrs -> pattern list -> pattern
val or_: ?loc:loc -> ?attrs:attrs -> pattern -> pattern -> pattern
val constraint_: ?loc:loc -> ?attrs:attrs -> pattern -> core_type -> pattern
val type_: ?loc:loc -> ?attrs:attrs -> lid -> pattern
val lazy_: ?loc:loc -> ?attrs:attrs -> pattern -> pattern
val unpack: ?loc:loc -> ?attrs:attrs -> str -> pattern
val extension: ?loc:loc -> ?attrs:attrs -> extension -> pattern
end
module Exp:
sig
val mk: ?loc:loc -> ?attrs:attrs -> expression_desc -> expression
val attr: expression -> attribute -> expression
val ident: ?loc:loc -> ?attrs:attrs -> lid -> expression
val constant: ?loc:loc -> ?attrs:attrs -> constant -> expression
val let_: ?loc:loc -> ?attrs:attrs -> rec_flag -> (pattern * expression) list -> expression -> expression
val function_: ?loc:loc -> ?attrs:attrs -> label -> expression option -> case list -> expression
val apply: ?loc:loc -> ?attrs:attrs -> expression -> (label * expression) list -> expression
val match_: ?loc:loc -> ?attrs:attrs -> expression -> case list -> expression
val try_: ?loc:loc -> ?attrs:attrs -> expression -> case list -> expression
val tuple: ?loc:loc -> ?attrs:attrs -> expression list -> expression
val construct: ?loc:loc -> ?attrs:attrs -> lid -> expression option -> bool -> expression
val variant: ?loc:loc -> ?attrs:attrs -> label -> expression option -> expression
val record: ?loc:loc -> ?attrs:attrs -> (lid * expression) list -> expression option -> expression
val field: ?loc:loc -> ?attrs:attrs -> expression -> lid -> expression
val setfield: ?loc:loc -> ?attrs:attrs -> expression -> lid -> expression -> expression
val array: ?loc:loc -> ?attrs:attrs -> expression list -> expression
val ifthenelse: ?loc:loc -> ?attrs:attrs -> expression -> expression -> expression option -> expression
val sequence: ?loc:loc -> ?attrs:attrs -> expression -> expression -> expression
val while_: ?loc:loc -> ?attrs:attrs -> expression -> expression -> expression
val for_: ?loc:loc -> ?attrs:attrs -> str -> expression -> expression -> direction_flag -> expression -> expression
val constraint_: ?loc:loc -> ?attrs:attrs -> expression -> core_type option -> core_type option -> expression
val send: ?loc:loc -> ?attrs:attrs -> expression -> string -> expression
val new_: ?loc:loc -> ?attrs:attrs -> lid -> expression
val setinstvar: ?loc:loc -> ?attrs:attrs -> str -> expression -> expression
val override: ?loc:loc -> ?attrs:attrs -> (str * expression) list -> expression
val letmodule: ?loc:loc -> ?attrs:attrs -> str -> module_expr -> expression -> expression
val assert_: ?loc:loc -> ?attrs:attrs -> expression -> expression
val assertfalse: ?loc:loc -> ?attrs:attrs -> unit -> expression
val lazy_: ?loc:loc -> ?attrs:attrs -> expression -> expression
val poly: ?loc:loc -> ?attrs:attrs -> expression -> core_type option -> expression
val object_: ?loc:loc -> ?attrs:attrs -> class_structure -> expression
val newtype: ?loc:loc -> ?attrs:attrs -> string -> expression -> expression
val pack: ?loc:loc -> ?attrs:attrs -> module_expr -> expression
val open_: ?loc:loc -> ?attrs:attrs -> lid -> expression -> expression
val extension: ?loc:loc -> ?attrs:attrs -> extension -> expression
val case: pattern -> ?guard:expression -> expression -> case
end
module Mty:
sig
val mk: ?loc:loc -> ?attrs:attrs -> module_type_desc -> module_type
val attr: module_type -> attribute -> module_type
val ident: ?loc:loc -> ?attrs:attrs -> lid -> module_type
val signature: ?loc:loc -> ?attrs:attrs -> signature -> module_type
val functor_: ?loc:loc -> ?attrs:attrs -> str -> module_type -> module_type -> module_type
val with_: ?loc:loc -> ?attrs:attrs -> module_type -> (lid * with_constraint) list -> module_type
val typeof_: ?loc:loc -> ?attrs:attrs -> module_expr -> module_type
val extension: ?loc:loc -> ?attrs:attrs -> extension -> module_type
end
module Mod:
sig
val mk: ?loc:loc -> ?attrs:attrs -> module_expr_desc -> module_expr
val attr: module_expr -> attribute -> module_expr
val ident: ?loc:loc -> ?attrs:attrs -> lid -> module_expr
val structure: ?loc:loc -> ?attrs:attrs -> structure -> module_expr
val functor_: ?loc:loc -> ?attrs:attrs -> str -> module_type -> module_expr -> module_expr
val apply: ?loc:loc -> ?attrs:attrs -> module_expr -> module_expr -> module_expr
val constraint_: ?loc:loc -> ?attrs:attrs -> module_expr -> module_type -> module_expr
val unpack: ?loc:loc -> ?attrs:attrs -> expression -> module_expr
val extension: ?loc:loc -> ?attrs:attrs -> extension -> module_expr
end
module Sig:
sig
val mk: ?loc:loc -> signature_item_desc -> signature_item
val value: ?loc:loc -> value_description -> signature_item
val type_: ?loc:loc -> type_declaration list -> signature_item
val exception_: ?loc:loc -> constructor_declaration -> signature_item
val module_: ?loc:loc -> module_declaration -> signature_item
val rec_module: ?loc:loc -> module_declaration list -> signature_item
val modtype: ?loc:loc -> module_type_declaration -> signature_item
val open_: ?loc:loc -> ?attrs:attrs -> lid -> signature_item
val include_: ?loc:loc -> ?attrs:attrs -> module_type -> signature_item
val class_: ?loc:loc -> class_description list -> signature_item
val class_type: ?loc:loc -> class_type_declaration list -> signature_item
val extension: ?loc:loc -> ?attrs:attrs -> extension -> signature_item
val attribute: ?loc:loc -> attribute -> signature_item
end
module Str:
sig
val mk: ?loc:loc -> structure_item_desc -> structure_item
val eval: ?loc:loc -> ?attrs:attributes -> expression -> structure_item
val value: ?loc:loc -> ?attrs:attributes -> rec_flag -> (pattern * expression) list -> structure_item
val primitive: ?loc:loc -> value_description -> structure_item
val type_: ?loc:loc -> type_declaration list -> structure_item
val exception_: ?loc:loc -> constructor_declaration -> structure_item
val exn_rebind: ?loc:loc -> ?attrs:attrs -> str -> lid -> structure_item
val module_: ?loc:loc -> module_binding -> structure_item
val rec_module: ?loc:loc -> module_binding list -> structure_item
val modtype: ?loc:loc -> module_type_binding -> structure_item
val open_: ?loc:loc -> ?attrs:attrs -> lid -> structure_item
val class_: ?loc:loc -> class_declaration list -> structure_item
val class_type: ?loc:loc -> class_type_declaration list -> structure_item
val include_: ?loc:loc -> ?attrs:attrs -> module_expr -> structure_item
val extension: ?loc:loc -> ?attrs:attrs -> extension -> structure_item
val attribute: ?loc:loc -> attribute -> structure_item
end
module Cl:
sig
val mk: ?loc:loc -> ?attrs:attrs -> class_expr_desc -> class_expr
val attr: class_expr -> attribute -> class_expr
val constr: ?loc:loc -> ?attrs:attrs -> lid -> core_type list -> class_expr
val structure: ?loc:loc -> ?attrs:attrs -> class_structure -> class_expr
val fun_: ?loc:loc -> ?attrs:attrs -> label -> expression option -> pattern -> class_expr -> class_expr
val apply: ?loc:loc -> ?attrs:attrs -> class_expr -> (label * expression) list -> class_expr
val let_: ?loc:loc -> ?attrs:attrs -> rec_flag -> (pattern * expression) list -> class_expr -> class_expr
val constraint_: ?loc:loc -> ?attrs:attrs -> class_expr -> class_type -> class_expr
val extension: ?loc:loc -> ?attrs:attrs -> extension -> class_expr
end
module Cty:
sig
val mk: ?loc:loc -> ?attrs:attrs -> class_type_desc -> class_type
val attr: class_type -> attribute -> class_type
val constr: ?loc:loc -> ?attrs:attrs -> lid -> core_type list -> class_type
val signature: ?loc:loc -> ?attrs:attrs -> class_signature -> class_type
val fun_: ?loc:loc -> ?attrs:attrs -> label -> core_type -> class_type -> class_type
val extension: ?loc:loc -> ?attrs:attrs -> extension -> class_type
end
module Ctf:
sig
val mk: ?loc:loc -> ?attrs:attrs -> class_type_field_desc -> class_type_field
val attr: class_type_field -> attribute -> class_type_field
val inherit_: ?loc:loc -> ?attrs:attrs -> class_type -> class_type_field
val val_: ?loc:loc -> ?attrs:attrs -> string -> mutable_flag -> virtual_flag -> core_type -> class_type_field
val method_: ?loc:loc -> ?attrs:attrs -> string -> private_flag -> virtual_flag -> core_type -> class_type_field
val constraint_: ?loc:loc -> ?attrs:attrs -> core_type -> core_type -> class_type_field
val extension: ?loc:loc -> ?attrs:attrs -> extension -> class_type_field
end
module Cf:
sig
val mk: ?loc:loc -> ?attrs:attrs -> class_field_desc -> class_field
val attr: class_field -> attribute -> class_field
val inherit_: ?loc:loc -> ?attrs:attrs -> override_flag -> class_expr -> string option -> class_field
val val_: ?loc:loc -> ?attrs:attrs -> str -> mutable_flag -> class_field_kind -> class_field
val method_: ?loc:loc -> ?attrs:attrs -> str -> private_flag -> class_field_kind -> class_field
val constraint_: ?loc:loc -> ?attrs:attrs -> core_type -> core_type -> class_field
val initializer_: ?loc:loc -> ?attrs:attrs -> expression -> class_field
val extension: ?loc:loc -> ?attrs:attrs -> extension -> class_field
val virtual_: core_type -> class_field_kind
val concrete: override_flag -> expression -> class_field_kind
end
module Val:
sig
val mk: ?loc:loc -> ?attrs:attrs -> ?prim:string list -> str -> core_type -> value_description
end
module Mtb:
sig
val mk: ?attrs:attrs -> str -> module_type -> module_type_binding
end
module Md:
sig
val mk: ?attrs:attrs -> str -> module_type -> module_declaration
end
module Mtd:
sig
val mk: ?attrs:attrs -> ?typ:module_type -> str -> module_type_declaration
end
module Mb:
sig
val mk: ?attrs:attrs -> str -> module_expr -> module_binding
end
module Ci:
sig
val mk: ?loc:loc -> ?attrs:attrs -> ?virt:virtual_flag -> ?params:(str * variance) list -> str -> 'a -> 'a class_infos
end
module Type:
sig
val mk: ?loc:loc -> ?attrs:attrs -> ?params:(str option * variance) list -> ?cstrs:(core_type * core_type * loc) list -> ?kind:type_kind -> ?priv:private_flag -> ?manifest:core_type -> str -> type_declaration
end
module Cd:
sig
val mk: ?loc:loc -> ?attrs:attrs -> ?args:core_type list -> ?res:core_type -> str -> constructor_declaration
end
module Ld:
sig
val mk: ?loc:loc -> ?attrs:attrs -> ?mut:mutable_flag -> str -> core_type -> label_declaration
end
module Csig:
sig
val mk: ?loc:loc -> core_type -> class_type_field list -> class_signature
end
module Convenience :
sig
(** Convenience function to help build and deconstruct AST fragments. *)
val lid: string -> lid
val evar: string -> expression
val let_in: ?recursive:bool -> (pattern * expression) list -> expression -> expression
val constr: string -> expression list -> expression
val record: ?over:expression -> (string * expression) list -> expression
val tuple: expression list -> expression
val nil: unit -> expression
val cons: expression -> expression -> expression
val list: expression list -> expression
val unit: unit -> expression
val func: (pattern * expression) list -> expression
val lam: ?label:string -> ?default:expression -> pattern -> expression -> expression
val app: expression -> expression list -> expression
val str: string -> expression
val int: int -> expression
val char: char -> expression
val float: float -> expression
val pvar: string -> pattern
val pconstr: string -> pattern list -> pattern
val punit: unit -> pattern
val get_str: expression -> string option
val get_lid: expression -> string option
val has_attr: string -> attributes -> bool
val find_attr: string -> attributes -> expression option
end