Skip to content

Commit c0f8627

Browse files
committed
Remove Ast_helper.Convenience submodule. This is better located in the ppx_tools package.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@14664 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
1 parent 07bc0e6 commit c0f8627

File tree

2 files changed

+0
-139
lines changed

2 files changed

+0
-139
lines changed

parsing/ast_helper.ml

-71
Original file line numberDiff line numberDiff line change
@@ -404,74 +404,3 @@ module Exrb = struct
404404
pexrb_loc = loc;
405405
}
406406
end
407-
408-
module Convenience = struct
409-
open Location
410-
411-
let may_tuple tup = function
412-
| [] -> None
413-
| [x] -> Some x
414-
| l -> Some (tup ?loc:None ?attrs:None l)
415-
416-
let lid s = mkloc (Longident.parse s) !default_loc
417-
let tuple l = Exp.tuple l
418-
let constr s args = Exp.construct (lid s) (may_tuple Exp.tuple args)
419-
let nil () = constr "[]" []
420-
let unit () = constr "()" []
421-
let cons hd tl = constr "::" [hd; tl]
422-
let list l = List.fold_right cons l (nil ())
423-
let str s = Exp.constant (Const_string (s, None))
424-
let int x = Exp.constant (Const_int x)
425-
let char x = Exp.constant (Const_char x)
426-
let float x = Exp.constant (Const_float (string_of_float x))
427-
let record ?over l =
428-
Exp.record (List.map (fun (s, e) -> (lid s, e)) l) over
429-
let func l = Exp.function_ (List.map (fun (p, e) -> Exp.case p e) l)
430-
let lam ?(label = "") ?default pat exp = Exp.fun_ label default pat exp
431-
let app f l = Exp.apply f (List.map (fun a -> "", a) l)
432-
let evar s = Exp.ident (lid s)
433-
let let_in ?(recursive = false) b body =
434-
Exp.let_ (if recursive then Recursive else Nonrecursive) b body
435-
436-
let pvar s = Pat.var (mkloc s !default_loc)
437-
let pconstr s args = Pat.construct (lid s) (may_tuple Pat.tuple args)
438-
let precord ?(closed = Open) l =
439-
Pat.record (List.map (fun (s, e) -> (lid s, e)) l) closed
440-
let pnil () = pconstr "[]" []
441-
let pcons hd tl = pconstr "::" [hd; tl]
442-
let punit () = pconstr "()" []
443-
let plist l = List.fold_right pcons l (pnil ())
444-
let ptuple l = Pat.tuple l
445-
446-
let pstr s = Pat.constant (Const_string (s, None))
447-
let pint x = Pat.constant (Const_int x)
448-
let pchar x = Pat.constant (Const_char x)
449-
let pfloat x = Pat.constant (Const_float (string_of_float x))
450-
451-
let tconstr c l = Typ.constr (lid c) l
452-
453-
let get_str = function
454-
| {pexp_desc=Pexp_constant (Const_string (s, _)); _} -> Some s
455-
| e -> None
456-
457-
let get_lid = function
458-
| {pexp_desc=Pexp_ident{txt=id;_};_} ->
459-
Some (String.concat "." (Longident.flatten id))
460-
| _ -> None
461-
462-
let find_attr s attrs =
463-
try Some (snd (List.find (fun (x, _) -> x.txt = s) attrs))
464-
with Not_found -> None
465-
466-
let expr_of_payload = function
467-
| PStr [{pstr_desc=Pstr_eval(e, _)}] -> Some e
468-
| _ -> None
469-
470-
let find_attr_expr s attrs =
471-
match find_attr s attrs with
472-
| Some e -> expr_of_payload e
473-
| None -> None
474-
475-
let has_attr s attrs =
476-
find_attr s attrs <> None
477-
end

parsing/ast_helper.mli

-68
Original file line numberDiff line numberDiff line change
@@ -340,71 +340,3 @@ module Exrb:
340340
sig
341341
val mk: ?loc:loc -> ?attrs:attrs -> str -> lid -> exception_rebind
342342
end
343-
344-
345-
(** {2 Convenience functions} *)
346-
347-
(** Convenience functions to help build and deconstruct AST fragments. *)
348-
module Convenience :
349-
sig
350-
351-
(** {2 Misc} *)
352-
353-
val lid: string -> lid
354-
355-
(** {2 Expressions} *)
356-
357-
val evar: string -> expression
358-
val let_in: ?recursive:bool -> value_binding list -> expression -> expression
359-
360-
val constr: string -> expression list -> expression
361-
val record: ?over:expression -> (string * expression) list -> expression
362-
val tuple: expression list -> expression
363-
364-
val nil: unit -> expression
365-
val cons: expression -> expression -> expression
366-
val list: expression list -> expression
367-
368-
val unit: unit -> expression
369-
370-
val func: (pattern * expression) list -> expression
371-
val lam: ?label:string -> ?default:expression -> pattern -> expression -> expression
372-
val app: expression -> expression list -> expression
373-
374-
val str: string -> expression
375-
val int: int -> expression
376-
val char: char -> expression
377-
val float: float -> expression
378-
379-
(** {2 Patterns} *)
380-
381-
val pvar: string -> pattern
382-
val pconstr: string -> pattern list -> pattern
383-
val precord: ?closed:closed_flag -> (string * pattern) list -> pattern
384-
val ptuple: pattern list -> pattern
385-
386-
val pnil: unit -> pattern
387-
val pcons: pattern -> pattern -> pattern
388-
val plist: pattern list -> pattern
389-
390-
val pstr: string -> pattern
391-
val pint: int -> pattern
392-
val pchar: char -> pattern
393-
val pfloat: float -> pattern
394-
395-
val punit: unit -> pattern
396-
397-
398-
(** {2 Types} *)
399-
400-
val tconstr: string -> core_type list -> core_type
401-
402-
(** {2 AST deconstruction} *)
403-
404-
val get_str: expression -> string option
405-
val get_lid: expression -> string option
406-
407-
val has_attr: string -> attributes -> bool
408-
val find_attr: string -> attributes -> payload option
409-
val find_attr_expr: string -> attributes -> expression option
410-
end

0 commit comments

Comments
 (0)