diff options
author | Michel Mauny <Michel.Mauny@ensta.fr> | 2002-07-19 14:53:56 +0000 |
---|---|---|
committer | Michel Mauny <Michel.Mauny@ensta.fr> | 2002-07-19 14:53:56 +0000 |
commit | 8b93d10cfeb9beb3d6b21c1ef6f22db725096039 (patch) | |
tree | bf22ee480ff63ff2288772082d58a718e506a41d /camlp4/ocaml_src | |
parent | 1df36a77965212e7616a0cb351961d56d5745e73 (diff) |
MAJ pour 3.05
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@5007 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
Diffstat (limited to 'camlp4/ocaml_src')
40 files changed, 1184 insertions, 477 deletions
diff --git a/camlp4/ocaml_src/camlp4/.depend b/camlp4/ocaml_src/camlp4/.depend index 43e8e8b14..72c6272bf 100644 --- a/camlp4/ocaml_src/camlp4/.depend +++ b/camlp4/ocaml_src/camlp4/.depend @@ -1,22 +1,19 @@ -ast2pt.cmi: $(OTOP)/parsing/location.cmi $(OTOP)/parsing/longident.cmi mLast.cmi \ +ast2pt.cmi: $(OTOP)/parsing/location.cmi \ + $(OTOP)/parsing/longident.cmi mLast.cmi \ $(OTOP)/parsing/parsetree.cmi pcaml.cmi: mLast.cmi spretty.cmi quotation.cmi: mLast.cmi reloc.cmi: mLast.cmi argl.cmo: ast2pt.cmi mLast.cmi ../odyl/odyl_main.cmi pcaml.cmi argl.cmx: ast2pt.cmx mLast.cmi ../odyl/odyl_main.cmx pcaml.cmx -ast2pt.cmo: $(OTOP)/parsing/asttypes.cmi $(OTOP)/parsing/location.cmi \ - $(OTOP)/parsing/longident.cmi mLast.cmi $(OTOP)/parsing/parsetree.cmi \ - ast2pt.cmi -ast2pt.cmx: $(OTOP)/parsing/asttypes.cmi $(OTOP)/parsing/location.cmx \ - $(OTOP)/parsing/longident.cmx mLast.cmi $(OTOP)/parsing/parsetree.cmi \ - ast2pt.cmi -crc.cmo: $(OTOP)/otherlibs/dynlink/dynlink.cmi -crc.cmx: $(OTOP)/otherlibs/dynlink/dynlink.cmx -pcaml.cmo: ast2pt.cmi $(OTOP)/utils/config.cmi mLast.cmi quotation.cmi \ - reloc.cmi spretty.cmi pcaml.cmi -pcaml.cmx: ast2pt.cmx $(OTOP)/utils/config.cmx mLast.cmi quotation.cmx \ - reloc.cmx spretty.cmx pcaml.cmi +ast2pt.cmo: $(OTOP)/parsing/asttypes.cmi \ + $(OTOP)/parsing/location.cmi $(OTOP)/parsing/longident.cmi \ + mLast.cmi $(OTOP)/parsing/parsetree.cmi ast2pt.cmi +ast2pt.cmx: $(OTOP)/parsing/asttypes.cmi \ + $(OTOP)/parsing/location.cmi $(OTOP)/parsing/longident.cmi \ + mLast.cmi $(OTOP)/parsing/parsetree.cmi ast2pt.cmi +pcaml.cmo: ast2pt.cmi mLast.cmi quotation.cmi reloc.cmi spretty.cmi pcaml.cmi +pcaml.cmx: ast2pt.cmx mLast.cmi quotation.cmx reloc.cmx spretty.cmx pcaml.cmi quotation.cmo: mLast.cmi quotation.cmi quotation.cmx: mLast.cmi quotation.cmi reloc.cmo: mLast.cmi reloc.cmi diff --git a/camlp4/ocaml_src/camlp4/Makefile b/camlp4/ocaml_src/camlp4/Makefile index 39d96b15f..e7efecc97 100644 --- a/camlp4/ocaml_src/camlp4/Makefile +++ b/camlp4/ocaml_src/camlp4/Makefile @@ -7,10 +7,10 @@ SHELL=/bin/sh INCLUDES=-I ../odyl -I ../../boot -I $(OTOP)/utils -I $(OTOP)/parsing -I $(OTOP)/otherlibs/dynlink OCAMLCFLAGS=-warn-error A $(INCLUDES) LINKFLAGS=$(INCLUDES) -INTERFACES=-I $(OLIBDIR) Arg Array Buffer Callback Char Digest Filename Format Gc Genlex Hashtbl Lazy Lexing List Map Marshal Obj Oo Parsing Pervasives Printexc Printf Queue Random Set Sort Stack Stream String Sys Weak -I ../../boot Extfun Fstream Gramext Grammar Plexer Stdpp Token -I $(OTOP)/utils Config Warnings -I $(OTOP)/parsing Asttypes Location Longident Parsetree -I . Ast2pt MLast Pcaml Quotation Spretty +INTERFACES=-I $(OLIBDIR) Arg Array Buffer Callback Char Digest Filename Format Gc Genlex Hashtbl Lazy Lexing List Map Marshal Obj Oo Parsing Pervasives Printexc Printf Queue Random Set Sort Stack Stream String Sys Weak -I ../../boot Extfold Extfun Fstream Gramext Grammar Plexer Stdpp Token -I $(OTOP)/utils Config Warnings -I $(OTOP)/parsing Asttypes Location Longident Parsetree -I . Ast2pt MLast Pcaml Quotation Spretty CAMLP4_INTF=$(OTOP)/utils/config.cmi $(OTOP)/utils/warnings.cmi $(OTOP)/parsing/asttypes.cmi $(OTOP)/parsing/location.cmi $(OTOP)/parsing/longident.cmi $(OTOP)/parsing/parsetree.cmi ast2pt.cmi mLast.cmi pcaml.cmi spretty.cmi quotation.cmi -CAMLP4_OBJS=../../boot/stdpp.cmo ../../boot/token.cmo ../../boot/plexer.cmo ../../boot/gramext.cmo ../../boot/grammar.cmo ../../boot/extfun.cmo ../../boot/fstream.cmo $(OTOP)/utils/config.cmo quotation.cmo ast2pt.cmo spretty.cmo reloc.cmo pcaml.cmo argl.cmo crc.cmo -CAMLP4_XOBJS=../lib/stdpp.cmx ../lib/token.cmx ../lib/plexer.cmx ../lib/gramext.cmx ../lib/grammar.cmx ../lib/extfun.cmx ../lib/fstream.cmx $(OTOP)/utils/config.cmx quotation.cmx ast2pt.cmx spretty.cmx reloc.cmx pcaml.cmx argl.cmx +CAMLP4_OBJS=../../boot/stdpp.cmo ../../boot/token.cmo ../../boot/plexer.cmo ../../boot/gramext.cmo ../../boot/grammar.cmo ../../boot/extfold.cmo ../../boot/extfun.cmo ../../boot/fstream.cmo $(OTOP)/utils/config.cmo quotation.cmo ast2pt.cmo spretty.cmo reloc.cmo pcaml.cmo argl.cmo crc.cmo +CAMLP4_XOBJS=../lib/stdpp.cmx ../lib/token.cmx ../lib/plexer.cmx ../lib/gramext.cmx ../lib/grammar.cmx ../lib/extfold.cmx ../lib/extfun.cmx ../lib/fstream.cmx $(OTOP)/utils/config.cmx quotation.cmx ast2pt.cmx spretty.cmx reloc.cmx pcaml.cmx argl.cmx OBJS=../odyl/odyl.cma camlp4.cma CAMLP4M= diff --git a/camlp4/ocaml_src/camlp4/Makefile.Mac b/camlp4/ocaml_src/camlp4/Makefile.Mac index 09b4de38f..6efc7382c 100644 --- a/camlp4/ocaml_src/camlp4/Makefile.Mac +++ b/camlp4/ocaml_src/camlp4/Makefile.Mac @@ -18,7 +18,7 @@ LINKFLAGS = {INCLUDES} INTERFACES = -I "{OLIBDIR}" Arg Array Buffer Callback Char Digest Filename � Format Gc Genlex Hashtbl Lazy Lexing List Map Marshal Obj Oo � Parsing Pervasives Printexc Printf Queue Random Set Sort Stack � - Stream String Sys Weak -I :::boot: Extfun Fstream � + Stream String Sys Weak -I :::boot: Extfold Extfun Fstream � Gramext Grammar Plexer � Stdpp Token -I "{OTOP}utils:" Config Warnings � -I "{OTOP}parsing:" Asttypes Location Longident Parsetree � @@ -29,7 +29,7 @@ CAMLP4_INTF = "{OTOP}utils:config.cmi" "{OTOP}utils:warnings.cmi" � ast2pt.cmo mLast.cmi pcaml.cmi spretty.cmi � quotation.cmi CAMLP4_OBJS = :::boot:stdpp.cmo :::boot:token.cmo :::boot:plexer.cmo � - :::boot:gramext.cmo :::boot:grammar.cmo :::boot:extfun.cmo � + :::boot:gramext.cmo :::boot:grammar.cmo :::boot:extfold.cmo :::boot:extfun.cmo � :::boot:fstream.cmo "{OTOP}utils:config.cmo" � quotation.cmo ast2pt.cmo spretty.cmo reloc.cmo pcaml.cmo � argl.cmo crc.cmo diff --git a/camlp4/ocaml_src/camlp4/argl.ml b/camlp4/ocaml_src/camlp4/argl.ml index 9060ec67e..220170289 100644 --- a/camlp4/ocaml_src/camlp4/argl.ml +++ b/camlp4/ocaml_src/camlp4/argl.ml @@ -137,7 +137,10 @@ let process_impl () = process !(Pcaml.parse_implem) !(Pcaml.print_implem) gimd ;; -type file_kind = Intf | Impl;; +type file_kind = + Intf + | Impl +;; let file_kind = ref Intf;; let file_kind_of_name name = if Filename.check_suffix name ".mli" then Intf diff --git a/camlp4/ocaml_src/camlp4/ast2pt.ml b/camlp4/ocaml_src/camlp4/ast2pt.ml index fa178ea9a..0571e1846 100644 --- a/camlp4/ocaml_src/camlp4/ast2pt.ml +++ b/camlp4/ocaml_src/camlp4/ast2pt.ml @@ -51,6 +51,11 @@ let mkstr loc d = {pstr_desc = d; pstr_loc = mkloc loc};; let mkfield loc d = {pfield_desc = d; pfield_loc = mkloc loc};; let mkcty loc d = {pcty_desc = d; pcty_loc = mkloc loc};; let mkpcl loc d = {pcl_desc = d; pcl_loc = mkloc loc};; +let mkpolytype t = + match t with + TyPol (_, _, _) -> t + | _ -> TyPol (MLast.loc_of_ctyp t, [], t) +;; let lident s = Lident s;; let ldot l s = Ldot (l, s);; @@ -151,6 +156,7 @@ let rec ctyp = | TyLid (loc, s) -> mktyp loc (Ptyp_constr (lident s, [])) | TyMan (loc, _, _) -> error loc "type manifest not allowed here" | TyOlb (loc, lab, _) -> error loc "labeled type not allowed here" + | TyPol (loc, pl, t) -> mktyp loc (Ptyp_poly (pl, ctyp t)) | TyQuo (loc, s) -> mktyp loc (Ptyp_var s) | TyRec (loc, _) -> error loc "record type not allowed here" | TySum (loc, _) -> error loc "sum type not allowed here" @@ -174,7 +180,8 @@ let rec ctyp = and meth_list loc fl v = match fl with [] -> if v then [mkfield loc Pfield_var] else [] - | (lab, t) :: fl -> mkfield loc (Pfield (lab, ctyp t)) :: meth_list loc fl v + | (lab, t) :: fl -> + mkfield loc (Pfield (lab, ctyp (mkpolytype t))) :: meth_list loc fl v ;; let mktype loc tl cl tk tm = @@ -184,7 +191,7 @@ let mktype loc tl cl tk tm = ;; let mkmutable m = if m then Mutable else Immutable;; let mkprivate m = if m then Private else Public;; -let mktrecord (_, n, m, t) = n, mkmutable m, ctyp t;; +let mktrecord (_, n, m, t) = n, mkmutable m, ctyp (mkpolytype t);; let mkvariant (_, c, tl) = c, List.map ctyp tl;; let type_decl tl cl = function @@ -271,7 +278,7 @@ let mkwithc = ptype_manifest = Some (ctyp ct); ptype_loc = mkloc loc; ptype_variance = variance} | WcMod (loc, id, m) -> - long_id_of_string_list loc id, Pwith_module (module_type_long_id m) + long_id_of_string_list loc id, Pwith_module (module_expr_long_id m) ;; let rec patt_fa al = @@ -426,7 +433,10 @@ let class_info class_expr ci = let rec expr = function - ExAcc (loc, _, _) as e -> + ExAcc (loc, x, ExLid (_, "val")) -> + mkexp loc + (Pexp_apply (mkexp loc (Pexp_ident (Lident "!")), ["", expr x])) + | ExAcc (loc, _, _) as e -> let (e, l) = match sep_expr_acc [] e with (loc, ml, ExUid (_, s)) :: l -> @@ -484,7 +494,10 @@ let rec expr = | ExAss (loc, e, v) -> let e = match e with - ExAcc (loc, _, _) -> + ExAcc (loc, x, ExLid (_, "val")) -> + Pexp_apply + (mkexp loc (Pexp_ident (Lident ":=")), ["", expr x; "", expr v]) + | ExAcc (loc, _, _) -> begin match (expr e).pexp_desc with Pexp_field (e, lab) -> Pexp_setfield (e, lab, expr v) | _ -> error loc "bad record access" @@ -595,6 +608,7 @@ and module_type = | MtFun (loc, n, nt, mt) -> mkmty loc (Pmty_functor (n, module_type nt, module_type mt)) | MtLid (loc, s) -> mkmty loc (Pmty_ident (lident s)) + | MtQuo (loc, _) -> error loc "abstract module type not allowed here" | MtSig (loc, sl) -> mkmty loc (Pmty_signature (List.fold_right sig_item sl [])) | MtUid (loc, s) -> mkmty loc (Pmty_ident (lident s)) @@ -614,7 +628,12 @@ and sig_item s l = | SgInc (loc, mt) -> mksig loc (Psig_include (module_type mt)) :: l | SgMod (loc, n, mt) -> mksig loc (Psig_module (n, module_type mt)) :: l | SgMty (loc, n, mt) -> - mksig loc (Psig_modtype (n, Pmodtype_manifest (module_type mt))) :: l + let si = + match mt with + MtQuo (_, _) -> Pmodtype_abstract + | _ -> Pmodtype_manifest (module_type mt) + in + mksig loc (Psig_modtype (n, si)) :: l | SgOpn (loc, id) -> mksig loc (Psig_open (long_id_of_string_list loc id)) :: l | SgTyp (loc, tdl) -> mksig loc (Psig_type (List.map mktype_decl tdl)) :: l @@ -683,10 +702,11 @@ and class_sig_item c l = | CgDcl (loc, cl) -> List.fold_right class_sig_item cl l | CgInh (loc, ct) -> Pctf_inher (class_type ct) :: l | CgMth (loc, s, pf, t) -> - Pctf_meth (s, mkprivate pf, ctyp t, mkloc loc) :: l + Pctf_meth (s, mkprivate pf, ctyp (mkpolytype t), mkloc loc) :: l | CgVal (loc, s, b, t) -> Pctf_val (s, mkmutable b, Some (ctyp t), mkloc loc) :: l - | CgVir (loc, s, b, t) -> Pctf_virt (s, mkprivate b, ctyp t, mkloc loc) :: l + | CgVir (loc, s, b, t) -> + Pctf_virt (s, mkprivate b, ctyp (mkpolytype t), mkloc loc) :: l and class_expr = function CeApp (loc, _, _) as c -> @@ -724,9 +744,13 @@ and class_str_item c l = | CrDcl (loc, cl) -> List.fold_right class_str_item cl l | CrInh (loc, ce, pb) -> Pcf_inher (class_expr ce, pb) :: l | CrIni (loc, e) -> Pcf_init (expr e) :: l - | CrMth (loc, s, b, e) -> Pcf_meth (s, mkprivate b, expr e, mkloc loc) :: l + | CrMth (loc, s, b, e, t) -> + let t = option (fun t -> ctyp (mkpolytype t)) t in + let e = mkexp loc (Pexp_poly (expr e, t)) in + Pcf_meth (s, mkprivate b, e, mkloc loc) :: l | CrVal (loc, s, b, e) -> Pcf_val (s, mkmutable b, expr e, mkloc loc) :: l - | CrVir (loc, s, b, t) -> Pcf_virt (s, mkprivate b, ctyp t, mkloc loc) :: l + | CrVir (loc, s, b, t) -> + Pcf_virt (s, mkprivate b, ctyp (mkpolytype t), mkloc loc) :: l ;; let interf ast = List.fold_right sig_item ast [];; diff --git a/camlp4/ocaml_src/camlp4/mLast.mli b/camlp4/ocaml_src/camlp4/mLast.mli index 4dbeb46dc..46f541d00 100644 --- a/camlp4/ocaml_src/camlp4/mLast.mli +++ b/camlp4/ocaml_src/camlp4/mLast.mli @@ -28,13 +28,16 @@ type ctyp = | TyMan of loc * ctyp * ctyp | TyObj of loc * (string * ctyp) list * bool | TyOlb of loc * string * ctyp + | TyPol of loc * string list * ctyp | TyQuo of loc * string | TyRec of loc * (loc * string * bool * ctyp) list | TySum of loc * (loc * string * ctyp list) list | TyTup of loc * ctyp list | TyUid of loc * string | TyVrn of loc * row_field list * string list option option -and row_field = RfTag of string * bool * ctyp list | RfInh of ctyp +and row_field = + RfTag of string * bool * ctyp list + | RfInh of ctyp ;; type 'a class_infos = @@ -106,6 +109,7 @@ and module_type = | MtApp of loc * module_type * module_type | MtFun of loc * string * module_type * module_type | MtLid of loc * string + | MtQuo of loc * string | MtSig of loc * sig_item list | MtUid of loc * string | MtWit of loc * module_type * with_constr list @@ -124,7 +128,7 @@ and sig_item = | SgVal of loc * string * ctyp and with_constr = WcTyp of loc * string list * (string * (bool * bool)) list * ctyp - | WcMod of loc * string list * module_type + | WcMod of loc * string list * module_expr and module_expr = MeAcc of loc * module_expr * module_expr | MeApp of loc * module_expr * module_expr @@ -171,7 +175,7 @@ and class_str_item = | CrDcl of loc * class_str_item list | CrInh of loc * class_expr * string option | CrIni of loc * expr - | CrMth of loc * string * bool * expr + | CrMth of loc * string * bool * expr * ctyp option | CrVal of loc * string * bool * expr | CrVir of loc * string * bool * ctyp ;; diff --git a/camlp4/ocaml_src/camlp4/pcaml.ml b/camlp4/ocaml_src/camlp4/pcaml.ml index 36a7589e5..b20c89ddd 100644 --- a/camlp4/ocaml_src/camlp4/pcaml.ml +++ b/camlp4/ocaml_src/camlp4/pcaml.ml @@ -5,21 +5,35 @@ (* *) (* Daniel de Rauglaudre, projet Cristal, INRIA Rocquencourt *) (* *) -(* Copyright 2001 Institut National de Recherche en Informatique et *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) (* Automatique. Distributed only by permission. *) (* *) (***********************************************************************) (* This file has been generated by program: do not edit! *) -let version = Config.version;; +let version = "3.04+15";; + +let ov = Sys.ocaml_version in +try + let oi = String.index ov ' ' in + let ov = String.sub ov 0 oi in + if String.sub version 0 (String.length ov) = ov then () + else failwith "bad version" +with + Not_found | Invalid_argument _ | Failure _ -> + Printf.eprintf "This OCaml and this Camlp4 are incompatible:\n"; + Printf.eprintf "- OCaml version is %s\n" ov; + Printf.eprintf "- Camlp4 version is %s\n" version; + flush stderr; + failwith "bad versions";; let gram = Grammar.gcreate {Token.tok_func = (fun _ -> failwith "no loaded parsing module"); Token.tok_using = (fun _ -> ()); Token.tok_removing = (fun _ -> ()); Token.tok_match = - (fun _ -> raise (Match_failure ("pcaml.ml", 1030, 1036))); + (fun _ -> raise (Match_failure ("pcaml.ml", 1506, 1512))); Token.tok_text = fun _ -> ""} ;; @@ -62,7 +76,10 @@ List.iter (fun (n, f) -> Quotation.add n f) let quotation_dump_file = ref (None : string option);; type err_ctx = - Finding | Expanding | ParsingResult of (int * int) * string | Locating + Finding + | Expanding + | ParsingResult of (int * int) * string + | Locating ;; exception Qerror of string * err_ctx * exn;; @@ -279,9 +296,9 @@ let print_exn = Format.print_int (Obj.magic arg : int) else if Obj.tag arg = 252 then begin - Format.print_char '"'; + Format.print_char '\"'; Format.print_string (Obj.magic arg : string); - Format.print_char '"' + Format.print_char '\"' end else Format.print_char '_' done; @@ -335,19 +352,27 @@ and kont = pretty Stream.t ;; let pr_str_item = - {pr_fun = (fun _ -> raise (Match_failure ("pcaml.ml", 11613, 11619))); + {pr_fun = (fun _ -> raise (Match_failure ("pcaml.ml", 12089, 12095))); pr_levels = []} ;; let pr_sig_item = - {pr_fun = (fun _ -> raise (Match_failure ("pcaml.ml", 11668, 11674))); + {pr_fun = (fun _ -> raise (Match_failure ("pcaml.ml", 12144, 12150))); pr_levels = []} ;; let pr_expr = - {pr_fun = (fun _ -> raise (Match_failure ("pcaml.ml", 11719, 11725))); + {pr_fun = (fun _ -> raise (Match_failure ("pcaml.ml", 12195, 12201))); pr_levels = []} ;; let pr_patt = - {pr_fun = (fun _ -> raise (Match_failure ("pcaml.ml", 11770, 11776))); + {pr_fun = (fun _ -> raise (Match_failure ("pcaml.ml", 12246, 12252))); + pr_levels = []} +;; +let pr_ctyp = + {pr_fun = (fun _ -> raise (Match_failure ("pcaml.ml", 12297, 12303))); + pr_levels = []} +;; +let pr_class_str_item = + {pr_fun = (fun _ -> raise (Match_failure ("pcaml.ml", 12358, 12364))); pr_levels = []} ;; let pr_expr_fun_args = ref Extfun.empty;; @@ -381,6 +406,8 @@ pr_str_item.pr_fun <- pr_fun "str_item" pr_str_item;; pr_sig_item.pr_fun <- pr_fun "sig_item" pr_sig_item;; pr_expr.pr_fun <- pr_fun "expr" pr_expr;; pr_patt.pr_fun <- pr_fun "patt" pr_patt;; +pr_ctyp.pr_fun <- pr_fun "ctyp" pr_ctyp;; +pr_class_str_item.pr_fun <- pr_fun "class_str_item" pr_class_str_item;; let rec find_pr_level lab = function @@ -395,7 +422,7 @@ let print_implem = undef "no printer";; let top_printer pr x = Format.force_newline (); Spretty.print_pretty Format.print_char Format.print_string - Format.print_newline "<< " " " 78 (fun _ -> ()) + Format.print_newline "<< " " " 78 (fun _ _ -> "", 0, 0, 0) 0 (pr.pr_fun "top" x "" Stream.sempty); Format.print_string " >>" ;; diff --git a/camlp4/ocaml_src/camlp4/pcaml.mli b/camlp4/ocaml_src/camlp4/pcaml.mli index a2d63e317..45f72577d 100644 --- a/camlp4/ocaml_src/camlp4/pcaml.mli +++ b/camlp4/ocaml_src/camlp4/pcaml.mli @@ -12,12 +12,12 @@ (* This file has been generated by program: do not edit! *) -(* Module [Pcaml]: language grammar, entries and printers. *) +(** Language grammar, entries and printers. -(* Hold variables to be set by language syntax extensions. Some of them + Hold variables to be set by language syntax extensions. Some of them are provided for quotations management. *) -(* Parsers *) +(** {6 Parsers} *) val parse_interf : (char Stream.t -> (MLast.sig_item * MLast.loc) list * bool) ref;; @@ -41,28 +41,28 @@ val class_sig_item : MLast.class_sig_item Grammar.Entry.e;; val class_str_item : MLast.class_str_item Grammar.Entry.e;; val class_expr : MLast.class_expr Grammar.Entry.e;; val class_type : MLast.class_type Grammar.Entry.e;; - (* Some grammar and entries of the language, set by [pa_o.cmo] and + (** Some grammar and entries of the language, set by [pa_o.cmo] and [pa_r.cmo]. *) val input_file : string ref;; - (* The file currently being parsed. *) + (** The file currently being parsed. *) val output_file : string option ref;; - (* The output file, stdout if None (default) *) + (** The output file, stdout if None (default) *) val report_error : exn -> unit;; - (* Prints an error message, using the module [Format]. *) + (** Prints an error message, using the module [Format]. *) val quotation_dump_file : string option ref;; - (* [quotation_dump_file] optionally tells the compiler to dump the + (** [quotation_dump_file] optionally tells the compiler to dump the result of an expander if this result is syntactically incorrect. If [None] (default), this result is not dumped. If [Some fname], the result is dumped in the file [fname]. *) val version : string;; - (* The current version of Camlp4. *) + (** The current version of Camlp4. *) val add_option : string -> Arg.spec -> string -> unit;; - (* Add an option to the command line options. *) + (** Add an option to the command line options. *) val no_constructors_arity : bool ref;; - (* [True]: dont generate constructor arity. *) + (** [True]: dont generate constructor arity. *) val no_assert : bool ref;; - (* [True]: dont generate assertion checks. *) + (** [True]: dont generate assertion checks. *) val sync : (char Stream.t -> unit) ref;; @@ -75,19 +75,22 @@ val handle_patt_locate : MLast.loc -> int * string -> MLast.patt;; val expr_reloc : (MLast.loc -> MLast.loc) -> int -> MLast.expr -> MLast.expr;; val patt_reloc : (MLast.loc -> MLast.loc) -> int -> MLast.patt -> MLast.patt;; -(* Allow user to catch exceptions in quotations *) +(** Allow user to catch exceptions in quotations *) type err_ctx = - Finding | Expanding | ParsingResult of (int * int) * string | Locating + Finding + | Expanding + | ParsingResult of (int * int) * string + | Locating ;; exception Qerror of string * err_ctx * exn;; -(* Printers *) +(** {6 Printers} *) open Spretty;; val print_interf : ((MLast.sig_item * MLast.loc) list -> unit) ref;; val print_implem : ((MLast.str_item * MLast.loc) list -> unit) ref;; - (* Some printers, set by [pr_dump.cmo], [pr_o.cmo] and [pr_r.cmo]. *) + (** Some printers, set by [pr_dump.cmo], [pr_o.cmo] and [pr_r.cmo]. *) type 'a printer_t = { mutable pr_fun : string -> 'a -> string -> kont -> pretty; @@ -107,6 +110,8 @@ val pr_str_item : MLast.str_item printer_t;; val pr_sig_item : MLast.sig_item printer_t;; val pr_expr : MLast.expr printer_t;; val pr_patt : MLast.patt printer_t;; +val pr_ctyp : MLast.ctyp printer_t;; +val pr_class_str_item : MLast.class_str_item printer_t;; val pr_expr_fun_args : (MLast.expr, (MLast.patt list * MLast.expr)) Extfun.t ref;; @@ -116,6 +121,8 @@ val top_printer : 'a printer_t -> 'a -> unit;; val inter_phrases : string option ref;; +(**/**) + (* for system use *) val warning : (int * int -> string -> unit) ref;; diff --git a/camlp4/ocaml_src/camlp4/quotation.mli b/camlp4/ocaml_src/camlp4/quotation.mli index f997f6557..aba963d70 100644 --- a/camlp4/ocaml_src/camlp4/quotation.mli +++ b/camlp4/ocaml_src/camlp4/quotation.mli @@ -12,21 +12,22 @@ (* This file has been generated by program: do not edit! *) -(* Module [Quotation]: quotation operations *) +(** Quotation operations. *) type expander = ExStr of (bool -> string -> string) | ExAst of ((string -> MLast.expr) * (string -> MLast.patt)) ;; - (* The type for quotation expanders kind: -- * [ExStr exp] for an expander [exp] returning a string which + +(** The type for quotation expanders kind: +- [ExStr exp] for an expander [exp] returning a string which can be parsed to create a syntax tree. Its boolean parameter tells whether the quotation is in position of an expression (True) or in position of a pattern (False). Quotations expanders created with this way may work for some particular language syntax, and not for another one (e.g. may work when used with Revised syntax and not when used with Ocaml syntax, and conversely). -- * [ExAst (expr_exp, patt_exp)] for expanders returning directly +- [ExAst (expr_exp, patt_exp)] for expanders returning directly syntax trees, therefore not necessiting to be parsed afterwards. The function [expr_exp] is called when the quotation is in position of an expression, and [patt_exp] when the quotation is @@ -34,14 +35,14 @@ type expander = way are independant from the language syntax. *) val add : string -> expander -> unit;; - (* [add name exp] adds the quotation [name] associated with the + (** [add name exp] adds the quotation [name] associated with the expander [exp]. *) val find : string -> expander;; - (* [find name] returns the expander of the given quotation name. *) + (** [find name] returns the expander of the given quotation name. *) val default : string ref;; - (* [default] holds the default quotation name. *) + (** [default] holds the default quotation name. *) val translate : (string -> string) ref;; - (* function translating quotation names; default = identity *) + (** function translating quotation names; default = identity *) diff --git a/camlp4/ocaml_src/camlp4/reloc.ml b/camlp4/ocaml_src/camlp4/reloc.ml index 1ba53682b..fb31775e9 100644 --- a/camlp4/ocaml_src/camlp4/reloc.ml +++ b/camlp4/ocaml_src/camlp4/reloc.ml @@ -35,6 +35,7 @@ let rec ctyp floc sh = | TyObj (loc, x1, x2) -> TyObj (floc loc, List.map (fun (x1, x2) -> x1, self x2) x1, x2) | TyOlb (loc, x1, x2) -> TyOlb (floc loc, x1, self x2) + | TyPol (loc, x1, x2) -> TyPol (floc loc, x1, self x2) | TyQuo (loc, x1) -> TyQuo (floc loc, x1) | TyRec (loc, x1) -> TyRec @@ -166,6 +167,7 @@ and module_type floc sh = | MtApp (loc, x1, x2) -> MtApp (floc loc, self x1, self x2) | MtFun (loc, x1, x2, x3) -> MtFun (floc loc, x1, self x2, self x3) | MtLid (loc, x1) -> MtLid (floc loc, x1) + | MtQuo (loc, x1) -> MtQuo (floc loc, x1) | MtSig (loc, x1) -> MtSig (floc loc, List.map (sig_item floc sh) x1) | MtUid (loc, x1) -> MtUid (floc loc, x1) | MtWit (loc, x1, x2) -> @@ -203,7 +205,7 @@ and with_constr floc sh = let rec self = function WcTyp (loc, x1, x2, x3) -> WcTyp (floc loc, x1, x2, ctyp floc sh x3) - | WcMod (loc, x1, x2) -> WcMod (floc loc, x1, module_type floc sh x2) + | WcMod (loc, x1, x2) -> WcMod (floc loc, x1, module_expr floc sh x2) in self and module_expr floc sh = @@ -301,7 +303,9 @@ and class_str_item floc sh = CrDcl (floc loc, List.map (class_str_item floc sh) x1) | CrInh (loc, x1, x2) -> CrInh (floc loc, class_expr floc sh x1, x2) | CrIni (loc, x1) -> CrIni (floc loc, expr floc sh x1) - | CrMth (loc, x1, x2, x3) -> CrMth (floc loc, x1, x2, expr floc sh x3) + | CrMth (loc, x1, x2, x3, x4) -> + CrMth + (floc loc, x1, x2, expr floc sh x3, option_map (ctyp floc sh) x4) | CrVal (loc, x1, x2, x3) -> CrVal (floc loc, x1, x2, expr floc sh x3) | CrVir (loc, x1, x2, x3) -> CrVir (floc loc, x1, x2, ctyp floc sh x3) in diff --git a/camlp4/ocaml_src/camlp4/spretty.ml b/camlp4/ocaml_src/camlp4/spretty.ml index f605f6a30..fc21f7355 100644 --- a/camlp4/ocaml_src/camlp4/spretty.ml +++ b/camlp4/ocaml_src/camlp4/spretty.ml @@ -5,14 +5,19 @@ (* *) (* Daniel de Rauglaudre, projet Cristal, INRIA Rocquencourt *) (* *) -(* Copyright 1998 Institut National de Recherche en Informatique et *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) (* Automatique. Distributed only by permission. *) (* *) (***********************************************************************) (* This file has been generated by program: do not edit! *) -type glue = LO | RO | LR | NO;; +type glue = + LO + | RO + | LR + | NO +;; type pretty = S of glue * string | Hbox of pretty Stream.t @@ -33,29 +38,86 @@ type prettyL = | VL of prettyL list | BE of prettyL list | BV of prettyL list - | LI of (int * int) * prettyL + | LI of (string * int * int) * prettyL ;; -type warnloc = int * int -> unit;; +type getcomm = int -> int -> string * int * int * int;; let quiet = ref true;; let maxl = ref 20;; let dt = ref 2;; let tol = ref 1;; let sp = ref ' ';; -let locf = ref (fun _ -> ());; +let last_ep = ref 0;; +let getcomm = ref (fun _ _ -> "", 0, 0, 0);; let prompt = ref "";; let print_char_fun = ref (output_char stdout);; let print_string_fun = ref (output_string stdout);; let print_newline_fun = ref (fun () -> output_char stdout '\n');; +let lazy_tab = ref (-1);; -let print_char c = !print_char_fun c;; -let print_string s = !print_string_fun s;; -let print_newline () = !print_newline_fun ();; +let flush_tab () = + if !lazy_tab >= 0 then + begin + !print_newline_fun (); + !print_string_fun !prompt; + for i = 1 to !lazy_tab do !print_char_fun !sp done; + lazy_tab := -1 + end +;; +let print_newline_and_tab tab = lazy_tab := tab;; +let print_char c = flush_tab (); !print_char_fun c;; +let print_string s = flush_tab (); !print_string_fun s;; -let rec print_spaces = - function - 0 -> () - | n -> print_char !sp; print_spaces (n - 1) +let rec print_spaces nsp = for i = 1 to nsp do print_char !sp done;; + +let end_with_tab s = + let rec loop i = + if i >= 0 then if s.[i] = ' ' then loop (i - 1) else s.[i] = '\n' + else false + in + loop (String.length s - 1) +;; + +let print_comment tab s nl_bef tab_bef empty_stmt = + if s = "" then () + else + let (tab_aft, i_bef_tab) = + let rec loop tab_aft i = + if i >= 0 && s.[i] = ' ' then loop (tab_aft + 1) (i - 1) + else tab_aft, i + in + loop 0 (String.length s - 1) + in + let tab_bef = if nl_bef > 0 then tab_bef else tab in + let len = if empty_stmt then i_bef_tab else String.length s in + let rec loop i = + if i = len then () + else + begin + !print_char_fun s.[i]; + let i = + if s.[i] = '\n' && (i + 1 = len || s.[i + 1] <> '\n') then + let delta_ind = + if i = i_bef_tab then tab - tab_aft else tab - tab_bef + in + if delta_ind >= 0 then + begin + for i = 1 to delta_ind do !print_char_fun ' ' done; i + 1 + end + else + let rec loop cnt i = + if cnt = 0 then i + else if i = len then i + else if s.[i] = ' ' then loop (cnt + 1) (i + 1) + else i + in + loop delta_ind (i + 1) + else i + 1 + in + loop i + end + in + loop 0 ;; let string_np pos np = pos + np;; @@ -136,26 +198,43 @@ let too_long tab x p = else let (pos, spc) = hnps x p in pos > !maxl ;; -let rec hprint_pretty pos spc = +let rec has_comment = + function + LI ((comm, nl_bef, tab_bef), x) :: pl -> + comm <> "" || has_comment (x :: pl) + | (HL x | BL x | PL x | QL x | VL x | BE x | BV x) :: pl -> + has_comment x || has_comment pl + | SL (_, _, _) :: pl -> has_comment pl + | [] -> false +;; + +let rec hprint_pretty tab pos spc = function SL (np, RO, x) -> h_print_string pos 0 np x, 1 | SL (np, LO, x) -> h_print_string pos spc np x, 0 | SL (np, NO, x) -> h_print_string pos 0 np x, 0 | SL (np, LR, x) -> h_print_string pos spc np x, 1 - | HL x -> hprint_box pos spc x - | BL x -> hprint_box pos spc x - | PL x -> hprint_box pos spc x - | QL x -> hprint_box pos spc x - | VL [x] -> hprint_pretty pos spc x + | HL x -> hprint_box tab pos spc x + | BL x -> hprint_box tab pos spc x + | PL x -> hprint_box tab pos spc x + | QL x -> hprint_box tab pos spc x + | VL [x] -> hprint_pretty tab pos spc x | VL [] -> pos, spc - | VL x -> hprint_box pos spc x - | BE x -> hprint_box pos spc x + | VL x -> hprint_box tab pos spc x + | BE x -> hprint_box tab pos spc x | BV x -> invalid_arg "hprint_pretty" - | LI (loc, x) -> !locf loc; hprint_pretty pos spc x -and hprint_box pos spc = + | LI ((comm, nl_bef, tab_bef), x) -> + if !lazy_tab >= 0 then + begin + for i = 2 to nl_bef do !print_char_fun '\n' done; flush_tab () + end; + print_comment tab comm nl_bef tab_bef false; + hprint_pretty tab pos spc x +and hprint_box tab pos spc = function p :: pl -> - let (pos, spc) = hprint_pretty pos spc p in hprint_box pos spc pl + let (pos, spc) = hprint_pretty tab pos spc p in + hprint_box tab pos spc pl | [] -> pos, spc ;; @@ -172,35 +251,47 @@ let rec print_pretty tab pos spc = | VL x -> print_vertic tab pos spc x | BE x as p -> print_begin_end tab pos spc (too_long tab (pos, spc) p) x | BV x -> print_beg_end tab pos spc x - | LI (loc, x) -> !locf loc; print_pretty tab pos spc x + | LI ((comm, nl_bef, tab_bef), x) -> + if !lazy_tab >= 0 then + begin + for i = 2 to nl_bef do !print_char_fun '\n' done; + if comm <> "" && nl_bef = 0 then + for i = 1 to tab_bef do !print_char_fun ' ' done + else if comm = "" && x = BL [] then lazy_tab := -1 + else flush_tab () + end; + print_comment tab comm nl_bef tab_bef (x = BL []); + if comm <> "" && nl_bef = 0 then + if end_with_tab comm then lazy_tab := -1 else flush_tab (); + print_pretty tab pos spc x and print_horiz tab pos spc = function p :: pl -> let (npos, nspc) = print_pretty tab pos spc p in if match pl with [] -> true - | _ -> false then + | _ -> false + then npos, nspc else print_horiz tab npos nspc pl | [] -> pos, spc and print_horiz_vertic tab pos spc ov pl = - if ov then print_vertic tab pos spc pl else hprint_box pos spc pl + if ov || has_comment pl then print_vertic tab pos spc pl + else hprint_box tab pos spc pl and print_vertic tab pos spc = function p :: pl -> let (npos, nspc) = print_pretty tab pos spc p in if match pl with [] -> true - | _ -> false then + | _ -> false + then npos, nspc else if tolerate tab npos nspc then begin print_spaces nspc; print_vertic_rest (npos + nspc) pl end else begin - print_newline (); - print_string !prompt; - print_spaces (tab + !dt); - print_vertic_rest (tab + !dt) pl + print_newline_and_tab (tab + !dt); print_vertic_rest (tab + !dt) pl end | [] -> pos, spc and print_vertic_rest tab = @@ -209,32 +300,28 @@ and print_vertic_rest tab = let (pos, spc) = print_pretty tab tab 0 p in if match pl with [] -> true - | _ -> false then + | _ -> false + then pos, spc - else - begin - print_newline (); - print_string !prompt; - print_spaces tab; - print_vertic_rest tab pl - end + else begin print_newline_and_tab tab; print_vertic_rest tab pl end | [] -> tab, 0 and print_paragraph tab pos spc ov pl = - if ov then print_parag tab pos spc pl else hprint_box pos spc pl + if has_comment pl then print_vertic tab pos spc pl + else if ov then print_parag tab pos spc pl + else hprint_box tab pos spc pl and print_parag tab pos spc = function p :: pl -> let (npos, nspc) = print_pretty tab pos spc p in if match pl with [] -> true - | _ -> false then + | _ -> false + then npos, nspc else if npos == tab then print_parag_rest tab tab 0 pl else if too_long tab (pos, spc) p then begin - print_newline (); - print_string !prompt; - print_spaces (tab + !dt); + print_newline_and_tab (tab + !dt); print_parag_rest (tab + !dt) (tab + !dt) 0 pl end else if tolerate tab npos nspc then @@ -248,35 +335,35 @@ and print_parag_rest tab pos spc = p :: pl -> let (pos, spc) = if pos > tab && too_long tab (pos, spc) p then - begin - print_newline (); print_string !prompt; print_spaces tab; tab, 0 - end + begin print_newline_and_tab tab; tab, 0 end else pos, spc in let (npos, nspc) = print_pretty tab pos spc p in if match pl with [] -> true - | _ -> false then + | _ -> false + then npos, nspc else let (pos, spc) = if npos > tab && too_long tab (pos, spc) p then - begin - print_newline (); print_string !prompt; print_spaces tab; tab, 0 - end + begin print_newline_and_tab tab; tab, 0 end else npos, nspc in print_parag_rest tab pos spc pl | [] -> pos, spc and print_sparagraph tab pos spc ov pl = - if ov then print_sparag tab pos spc pl else hprint_box pos spc pl + if has_comment pl then print_vertic tab pos spc pl + else if ov then print_sparag tab pos spc pl + else hprint_box tab pos spc pl and print_sparag tab pos spc = function p :: pl -> let (npos, nspc) = print_pretty tab pos spc p in if match pl with [] -> true - | _ -> false then + | _ -> false + then npos, nspc else if tolerate tab npos nspc then begin @@ -290,36 +377,35 @@ and print_sparag_rest tab pos spc = p :: pl -> let (pos, spc) = if pos > tab && too_long tab (pos, spc) p then - begin - print_newline (); print_string !prompt; print_spaces tab; tab, 0 - end + begin print_newline_and_tab tab; tab, 0 end else pos, spc in let (npos, nspc) = print_pretty tab pos spc p in if match pl with [] -> true - | _ -> false then + | _ -> false + then npos, nspc else print_sparag_rest tab npos nspc pl | [] -> pos, spc and print_begin_end tab pos spc ov pl = - if ov then print_beg_end tab pos spc pl else hprint_box pos spc pl + if ov || has_comment pl then print_beg_end tab pos spc pl + else hprint_box tab pos spc pl and print_beg_end tab pos spc = function p :: pl -> let (npos, nspc) = print_pretty tab pos spc p in if match pl with [] -> true - | _ -> false then + | _ -> false + then npos, nspc else if tolerate tab npos nspc then let nspc = if npos == tab then nspc + !dt else nspc in print_spaces nspc; print_beg_end_rest tab (npos + nspc) pl else begin - print_newline (); - print_string !prompt; - print_spaces (tab + !dt); + print_newline_and_tab (tab + !dt); print_beg_end_rest tab (tab + !dt) pl end | [] -> pos, spc @@ -329,15 +415,10 @@ and print_beg_end_rest tab pos = let (pos, spc) = print_pretty (tab + !dt) pos 0 p in if match pl with [] -> true - | _ -> false then + | _ -> false + then pos, spc - else - begin - print_newline (); - print_string !prompt; - print_spaces tab; - print_beg_end_rest tab tab pl - end + else begin print_newline_and_tab tab; print_beg_end_rest tab tab pl end | [] -> pos, 0 ;; @@ -357,20 +438,28 @@ let rec conv = | Vbox x -> VL (conv_stream x) | BEbox x -> BE (conv_stream x) | BEVbox x -> BV (conv_stream x) - | LocInfo (loc, x) -> LI (loc, conv x) + | LocInfo ((bp, ep), x) -> + let (comm, nl_bef, tab_bef, cnt) = + let len = bp - !last_ep in + if len > 0 then !getcomm !last_ep len else "", 0, 0, 0 + in + last_ep := !last_ep + cnt; + let v = conv x in + last_ep := max ep !last_ep; LI ((comm, nl_bef, tab_bef), v) and conv_stream (strm__ : _ Stream.t) = match Stream.peek strm__ with - Some p -> Stream.junk strm__; conv p :: conv_stream strm__ + Some p -> Stream.junk strm__; let x = conv p in x :: conv_stream strm__ | _ -> [] ;; -let print_pretty pr_ch pr_str pr_nl pr pr2 m lf p = +let print_pretty pr_ch pr_str pr_nl pr pr2 m lf bp p = maxl := m; print_char_fun := pr_ch; print_string_fun := pr_str; print_newline_fun := pr_nl; prompt := pr2; - locf := lf; + getcomm := lf; + last_ep := bp; print_string pr; let _ = print_pretty 0 0 0 (conv p) in () ;; diff --git a/camlp4/ocaml_src/camlp4/spretty.mli b/camlp4/ocaml_src/camlp4/spretty.mli index 4a79f4fef..5c62d3f6c 100644 --- a/camlp4/ocaml_src/camlp4/spretty.mli +++ b/camlp4/ocaml_src/camlp4/spretty.mli @@ -27,7 +27,12 @@ by dt.val spaces, except if first element of the box is empty: to not indent, put HVbox [: :] as first element *) -type glue = LO | RO | LR | NO;; +type glue = + LO + | RO + | LR + | NO +;; type pretty = S of glue * string | Hbox of pretty Stream.t @@ -39,11 +44,11 @@ type pretty = | BEVbox of pretty Stream.t | LocInfo of (int * int) * pretty ;; -type warnloc = int * int -> unit;; +type getcomm = int -> int -> string * int * int * int;; val print_pretty : (char -> unit) -> (string -> unit) -> (unit -> unit) -> string -> string -> - int -> warnloc -> pretty -> unit;; + int -> getcomm -> int -> pretty -> unit;; val quiet : bool ref;; val dt : int ref;; diff --git a/camlp4/ocaml_src/lib/.depend b/camlp4/ocaml_src/lib/.depend index 0d7070927..0d5adc691 100644 --- a/camlp4/ocaml_src/lib/.depend +++ b/camlp4/ocaml_src/lib/.depend @@ -1,6 +1,9 @@ +extfold.cmi: gramext.cmi gramext.cmi: token.cmi grammar.cmi: gramext.cmi token.cmi plexer.cmi: token.cmi +extfold.cmo: gramext.cmi grammar.cmi extfold.cmi +extfold.cmx: gramext.cmx grammar.cmx extfold.cmi extfun.cmo: extfun.cmi extfun.cmx: extfun.cmi fstream.cmo: fstream.cmi diff --git a/camlp4/ocaml_src/lib/Makefile b/camlp4/ocaml_src/lib/Makefile index 1d589b1bb..524831704 100644 --- a/camlp4/ocaml_src/lib/Makefile +++ b/camlp4/ocaml_src/lib/Makefile @@ -4,7 +4,7 @@ include ../../config/Makefile INCLUDES= OCAMLCFLAGS=-warn-error A $(INCLUDES) -OBJS=stdpp.cmo token.cmo plexer.cmo gramext.cmo grammar.cmo extfun.cmo fstream.cmo +OBJS=stdpp.cmo token.cmo plexer.cmo gramext.cmo grammar.cmo extfold.cmo extfun.cmo fstream.cmo SHELL=/bin/sh TARGET=gramlib.cma diff --git a/camlp4/ocaml_src/lib/Makefile.Mac b/camlp4/ocaml_src/lib/Makefile.Mac index 9b0f9ef5a..dadf3222e 100644 --- a/camlp4/ocaml_src/lib/Makefile.Mac +++ b/camlp4/ocaml_src/lib/Makefile.Mac @@ -13,8 +13,8 @@ INCLUDES = OCAMLCFLAGS = {INCLUDES} -OBJS = stdpp.cmo token.cmo plexer.cmo gramext.cmo grammar.cmo -INTF = stdpp.cmi token.cmi plexer.cmi gramext.cmi grammar.cmi +OBJS = stdpp.cmo token.cmo plexer.cmo gramext.cmo grammar.cmo extfold.cmo extfun.cmo fstream.cmo +INTF = stdpp.cmi token.cmi plexer.cmi gramext.cmi grammar.cmi extfold.cmi extfun.cmi fstream.cmi TARGETS = gramlib.cma all � {TARGETS} diff --git a/camlp4/ocaml_src/lib/extfold.ml b/camlp4/ocaml_src/lib/extfold.ml new file mode 100644 index 000000000..0411497f0 --- /dev/null +++ b/camlp4/ocaml_src/lib/extfold.ml @@ -0,0 +1,124 @@ +(* camlp4r *) +(* This file has been generated by program: do not edit! *) + +type ('te, 'a, 'b) t = + 'te Gramext.g_entry -> 'te Gramext.g_symbol list -> ('te Stream.t -> 'a) -> + 'te Stream.t -> 'b +;; + +type ('te, 'a, 'b) tsep = + 'te Gramext.g_entry -> 'te Gramext.g_symbol list -> ('te Stream.t -> 'a) -> + ('te Stream.t -> unit) -> 'te Stream.t -> 'b +;; + +let gen_fold0 final f e entry symbl psymb = + let rec fold accu (strm__ : _ Stream.t) = + match + try Some (psymb strm__) with + Stream.Failure -> None + with + Some a -> fold (f a accu) strm__ + | _ -> accu + in + fun (strm__ : _ Stream.t) -> let a = fold e strm__ in final a +;; + +let gen_fold1 final f e entry symbl psymb = + let rec fold accu (strm__ : _ Stream.t) = + match + try Some (psymb strm__) with + Stream.Failure -> None + with + Some a -> fold (f a accu) strm__ + | _ -> accu + in + fun (strm__ : _ Stream.t) -> + let a = psymb strm__ in + let a = + try fold (f a e) strm__ with + Stream.Failure -> raise (Stream.Error "") + in + final a +;; + +let gen_fold0sep final f e entry symbl psymb psep = + let failed = + function + [symb; sep] -> Grammar.symb_failed_txt entry sep symb + | _ -> "failed" + in + let rec kont accu (strm__ : _ Stream.t) = + match + try Some (psep strm__) with + Stream.Failure -> None + with + Some v -> + let a = + try psymb strm__ with + Stream.Failure -> raise (Stream.Error (failed symbl)) + in + kont (f a accu) strm__ + | _ -> accu + in + fun (strm__ : _ Stream.t) -> + match + try Some (psymb strm__) with + Stream.Failure -> None + with + Some a -> final (kont (f a e) strm__) + | _ -> e +;; + +let gen_fold1sep final f e entry symbl psymb psep = + let failed = + function + [symb; sep] -> Grammar.symb_failed_txt entry sep symb + | _ -> "failed" + in + let parse_top = + function + [symb; _] -> Grammar.parse_top_symb entry symb + | _ -> raise Stream.Failure + in + let rec kont accu (strm__ : _ Stream.t) = + match + try Some (psep strm__) with + Stream.Failure -> None + with + Some v -> + let a = + try + try psymb strm__ with + Stream.Failure -> + let a = + try parse_top symbl strm__ with + Stream.Failure -> raise (Stream.Error (failed symbl)) + in + Obj.magic a + with + Stream.Failure -> raise (Stream.Error "") + in + kont (f a accu) strm__ + | _ -> accu + in + fun (strm__ : _ Stream.t) -> + let a = psymb strm__ in final (kont (f a e) strm__) +;; + +let sfold0 f e = gen_fold0 (fun x -> x) f e;; +let sfold1 f e = gen_fold1 (fun x -> x) f e;; +let sfold0sep f e = gen_fold0sep (fun x -> x) f e;; +let sfold1sep f e = gen_fold1sep (fun x -> x) f e;; + +let cons x y = x :: y;; +let nil = [];; + +let slist0 entry = gen_fold0 List.rev cons nil entry;; +let slist1 entry = gen_fold1 List.rev cons nil entry;; +let slist0sep entry = gen_fold0sep List.rev cons nil entry;; +let slist1sep entry = gen_fold1sep List.rev cons nil entry;; + +let sopt entry symbl psymb (strm__ : _ Stream.t) = + try Some (psymb strm__) with + Stream.Failure -> None +;; diff --git a/camlp4/ocaml_src/lib/extfold.mli b/camlp4/ocaml_src/lib/extfold.mli new file mode 100644 index 000000000..cb2824fb1 --- /dev/null +++ b/camlp4/ocaml_src/lib/extfold.mli @@ -0,0 +1,24 @@ +(* camlp4r *) +(* This file has been generated by program: do not edit! *) + +type ('te, 'a, 'b) t = + 'te Gramext.g_entry -> 'te Gramext.g_symbol list -> ('te Stream.t -> 'a) -> + 'te Stream.t -> 'b +;; + +type ('te, 'a, 'b) tsep = + 'te Gramext.g_entry -> 'te Gramext.g_symbol list -> ('te Stream.t -> 'a) -> + ('te Stream.t -> unit) -> 'te Stream.t -> 'b +;; + +val sfold0 : ('a -> 'b -> 'b) -> 'b -> (_, 'a, 'b) t;; +val sfold1 : ('a -> 'b -> 'b) -> 'b -> (_, 'a, 'b) t;; +val sfold0sep : ('a -> 'b -> 'b) -> 'b -> (_, 'a, 'b) tsep;; +val sfold1sep : ('a -> 'b -> 'b) -> 'b -> (_, 'a, 'b) tsep;; + +val slist0 : (_, 'a, 'a list) t;; +val slist1 : (_, 'a, 'a list) t;; +val slist0sep : (_, 'a, 'a list) tsep;; +val slist1sep : (_, 'a, 'a list) tsep;; + +val sopt : (_, 'a, 'a option) t;; diff --git a/camlp4/ocaml_src/lib/extfun.mli b/camlp4/ocaml_src/lib/extfun.mli index fda2f1805..2d42fe2e8 100644 --- a/camlp4/ocaml_src/lib/extfun.mli +++ b/camlp4/ocaml_src/lib/extfun.mli @@ -1,24 +1,25 @@ (* camlp4r *) (* This file has been generated by program: do not edit! *) -(* Module [Extfun]: extensible functions *) +(** Extensible functions. -(* This module implements pattern matching extensible functions. + This module implements pattern matching extensible functions. To extend, use syntax [pa_extfun.cmo]: -- [extfun e with [ pattern_matching ]] *) + + [extfun e with [ pattern_matching ]] *) type ('a, 'b) t;; - (* The type of the extensible functions of type ['a -> 'b] *) + (** The type of the extensible functions of type ['a -> 'b] *) val empty : ('a, 'b) t;; - (* Empty extensible function *) + (** Empty extensible function *) val apply : ('a, 'b) t -> 'a -> 'b;; - (* Apply an extensible function *) + (** Apply an extensible function *) exception Failure;; - (* Match failure while applying an extensible function *) + (** Match failure while applying an extensible function *) val print : ('a, 'b) t -> unit;; - (* Print patterns in the order they are recorded *) + (** Print patterns in the order they are recorded *) -(*--*) +(**/**) type ('a, 'b) matching = { patt : patt; has_when : bool; expr : ('a, 'b) expr } diff --git a/camlp4/ocaml_src/lib/fstream.ml b/camlp4/ocaml_src/lib/fstream.ml index 5f4e6bfda..9ffdb7104 100644 --- a/camlp4/ocaml_src/lib/fstream.ml +++ b/camlp4/ocaml_src/lib/fstream.ml @@ -3,7 +3,10 @@ (* Copyright 2001 INRIA *) type 'a t = { count : int; data : 'a data Lazy.t } -and 'a data = Nil | Cons of 'a * 'a t | App of 'a t * 'a t +and 'a data = + Nil + | Cons of 'a * 'a t + | App of 'a t * 'a t ;; let from f = diff --git a/camlp4/ocaml_src/lib/gramext.ml b/camlp4/ocaml_src/lib/gramext.ml index 9fdd4f4f8..41fdd76c1 100644 --- a/camlp4/ocaml_src/lib/gramext.ml +++ b/camlp4/ocaml_src/lib/gramext.ml @@ -26,15 +26,20 @@ type 'te g_entry = mutable econtinue : int -> int -> Obj.t -> 'te Stream.t -> Obj.t; mutable edesc : 'te g_desc } and 'te g_desc = - Dlevels of 'te g_level list | Dparser of ('te Stream.t -> Obj.t) + Dlevels of 'te g_level list + | Dparser of ('te Stream.t -> Obj.t) and 'te g_level = { assoc : g_assoc; lname : string option; lsuffix : 'te g_tree; lprefix : 'te g_tree } -and g_assoc = NonA | RightA | LeftA +and g_assoc = + NonA + | RightA + | LeftA and 'te g_symbol = - Snterm of 'te g_entry + Smeta of string * 'te g_symbol list * Obj.t + | Snterm of 'te g_entry | Snterml of 'te g_entry * string | Slist0 of 'te g_symbol | Slist0sep of 'te g_symbol * 'te g_symbol @@ -47,13 +52,19 @@ and 'te g_symbol = | Stree of 'te g_tree and g_action = Obj.t and 'te g_tree = - Node of 'te g_node | LocAct of g_action * g_action list | DeadEnd + Node of 'te g_node + | LocAct of g_action * g_action list + | DeadEnd and 'te g_node = { node : 'te g_symbol; son : 'te g_tree; brother : 'te g_tree } ;; type position = - First | Last | Before of string | After of string | Level of string + First + | Last + | Before of string + | After of string + | Level of string ;; let warning_verbose = ref true;; @@ -64,13 +75,15 @@ let rec derive_eps = | Slist0sep (_, _) -> true | Sopt _ -> true | Stree t -> tree_derive_eps t - | _ -> false + | Smeta (_, _, _) | Slist1 _ | Slist1sep (_, _) | Snterm _ | + Snterml (_, _) | Snext | Sself | Stoken _ -> + false and tree_derive_eps = function LocAct (_, _) -> true | Node {node = s; brother = bro; son = son} -> derive_eps s && tree_derive_eps son || tree_derive_eps bro - | _ -> false + | DeadEnd -> false ;; let rec eq_symbol s1 s2 = @@ -139,7 +152,7 @@ let insert_tree entry_name gsymbols action tree = let t = Node {node = s1; son = son; brother = bro} in Some t | None -> None end - | _ -> None + | LocAct (_, _) | DeadEnd -> None and insert_new = function s :: sl -> Node {node = s; son = insert_new sl; brother = DeadEnd} @@ -201,7 +214,7 @@ let change_lev lev n lname assoc = Some n -> if lname <> lev.lname && !warning_verbose then begin eprintf "<W> Level label \"%s\" ignored\n" n; flush stderr end - | _ -> () + | None -> () end; {assoc = a; lname = lev.lname; lsuffix = lev.lsuffix; lprefix = lev.lprefix} ;; @@ -278,18 +291,19 @@ Error: entries \"%s\" and \"%s\" do not belong to the same grammar.\n" flush stderr; failwith "Grammar.extend error" end + | Smeta (_, sl, _) -> List.iter (check_gram entry) sl | Slist0sep (s, t) -> check_gram entry t; check_gram entry s | Slist1sep (s, t) -> check_gram entry t; check_gram entry s | Slist0 s -> check_gram entry s | Slist1 s -> check_gram entry s | Sopt s -> check_gram entry s | Stree t -> tree_check_gram entry t - | _ -> () + | Snext | Sself | Stoken _ -> () and tree_check_gram entry = function Node {node = n; brother = bro; son = son} -> check_gram entry n; tree_check_gram entry bro; tree_check_gram entry son - | _ -> () + | LocAct (_, _) | DeadEnd -> () ;; let change_to_self entry = @@ -307,7 +321,8 @@ let get_initial entry = let insert_tokens gram symbols = let rec insert = function - Slist0 s -> insert s + Smeta (_, sl, _) -> List.iter insert sl + | Slist0 s -> insert s | Slist1 s -> insert s | Slist0sep (s, t) -> insert s; insert t | Slist1sep (s, t) -> insert s; insert t @@ -321,12 +336,12 @@ let insert_tokens gram symbols = Not_found -> let r = ref 0 in Hashtbl.add gram.gtokens tok r; r in incr r - | _ -> () + | Snterm _ | Snterml (_, _) | Snext | Sself -> () and tinsert = function Node {node = s; brother = bro; son = son} -> insert s; tinsert bro; tinsert son - | _ -> () + | LocAct (_, _) | DeadEnd -> () in List.iter insert symbols ;; @@ -442,13 +457,14 @@ let rec decr_keyw_use gram = begin Hashtbl.remove gram.gtokens tok; gram.glexer.Token.tok_removing tok end + | Smeta (_, sl, _) -> List.iter (decr_keyw_use gram) sl | Slist0 s -> decr_keyw_use gram s | Slist1 s -> decr_keyw_use gram s | Slist0sep (s1, s2) -> decr_keyw_use gram s1; decr_keyw_use gram s2 | Slist1sep (s1, s2) -> decr_keyw_use gram s1; decr_keyw_use gram s2 | Sopt s -> decr_keyw_use gram s | Stree t -> decr_keyw_use_in_tree gram t - | _ -> () + | Sself | Snext | Snterm _ | Snterml (_, _) -> () and decr_keyw_use_in_tree gram = function DeadEnd | LocAct (_, _) -> () diff --git a/camlp4/ocaml_src/lib/gramext.mli b/camlp4/ocaml_src/lib/gramext.mli index da9eb4596..bd275ae8e 100644 --- a/camlp4/ocaml_src/lib/gramext.mli +++ b/camlp4/ocaml_src/lib/gramext.mli @@ -24,15 +24,20 @@ type 'te g_entry = mutable econtinue : int -> int -> Obj.t -> 'te Stream.t -> Obj.t; mutable edesc : 'te g_desc } and 'te g_desc = - Dlevels of 'te g_level list | Dparser of ('te Stream.t -> Obj.t) + Dlevels of 'te g_level list + | Dparser of ('te Stream.t -> Obj.t) and 'te g_level = { assoc : g_assoc; lname : string option; lsuffix : 'te g_tree; lprefix : 'te g_tree } -and g_assoc = NonA | RightA | LeftA +and g_assoc = + NonA + | RightA + | LeftA and 'te g_symbol = - Snterm of 'te g_entry + Smeta of string * 'te g_symbol list * Obj.t + | Snterm of 'te g_entry | Snterml of 'te g_entry * string | Slist0 of 'te g_symbol | Slist0sep of 'te g_symbol * 'te g_symbol @@ -45,13 +50,19 @@ and 'te g_symbol = | Stree of 'te g_tree and g_action = Obj.t and 'te g_tree = - Node of 'te g_node | LocAct of g_action * g_action list | DeadEnd + Node of 'te g_node + | LocAct of g_action * g_action list + | DeadEnd and 'te g_node = { node : 'te g_symbol; son : 'te g_tree; brother : 'te g_tree } ;; type position = - First | Last | Before of string | After of string | Level of string + First + | Last + | Before of string + | After of string + | Level of string ;; val levels_of_rules : diff --git a/camlp4/ocaml_src/lib/grammar.ml b/camlp4/ocaml_src/lib/grammar.ml index 623f0d3b0..66e7d3580 100644 --- a/camlp4/ocaml_src/lib/grammar.ml +++ b/camlp4/ocaml_src/lib/grammar.ml @@ -28,7 +28,8 @@ let print_str ppf s = fprintf ppf "\"%s\"" (String.escaped s);; let rec print_symbol ppf = function - Slist0 s -> fprintf ppf "LIST0 %a" print_symbol1 s + Smeta (n, sl, _) -> print_meta ppf n sl + | Slist0 s -> fprintf ppf "LIST0 %a" print_symbol1 s | Slist0sep (s, t) -> fprintf ppf "LIST0 %a SEP %a" print_symbol1 s print_symbol1 t | Slist1 s -> fprintf ppf "LIST1 %a" print_symbol1 s @@ -38,7 +39,22 @@ let rec print_symbol ppf = | Stoken (con, prm) when con <> "" && prm <> "" -> fprintf ppf "%s@ %a" con print_str prm | Snterml (e, l) -> fprintf ppf "%s@ LEVEL@ %a" e.ename print_str l - | s -> print_symbol1 ppf s + | Snterm _ | Snext | Sself | Stoken _ | Stree _ as s -> print_symbol1 ppf s +and print_meta ppf n sl = + let rec loop i = + function + [] -> () + | s :: sl -> + let j = + try String.index_from n i ' ' with + Not_found -> String.length n + in + fprintf ppf "%s %a" (String.sub n i (j - i)) print_symbol1 s; + if sl = [] then () + else + begin fprintf ppf " "; loop (min (j + 1) (String.length n)) sl end + in + loop 0 sl and print_symbol1 ppf = function Snterm e -> pp_print_string ppf e.ename @@ -47,7 +63,9 @@ and print_symbol1 ppf = | Stoken ("", s) -> print_str ppf s | Stoken (con, "") -> pp_print_string ppf con | Stree t -> print_level ppf pp_print_space (flatten_tree t) - | s -> fprintf ppf "(%a)" print_symbol s + | Smeta (_, _, _) | Snterml (_, _) | Slist0 _ | Slist0sep (_, _) | + Slist1 _ | Slist1sep (_, _) | Sopt _ | Stoken _ as s -> + fprintf ppf "(%a)" print_symbol s and print_rule ppf symbols = fprintf ppf "@[<hov 0>"; let _ = @@ -81,7 +99,7 @@ let print_levels ppf elev = fprintf ppf "%t@[<hov 2>" sep; begin match lev.lname with Some n -> fprintf ppf "%a@;<1 2>" print_str n - | _ -> () + | None -> () end; begin match lev.assoc with LeftA -> fprintf ppf "LEFTA" @@ -165,7 +183,7 @@ and name_of_tree_failed entry = let txt = match bro with DeadEnd | LocAct (_, _) -> txt - | _ -> txt ^ " or " ^ name_of_tree_failed entry bro + | Node _ -> txt ^ " or " ^ name_of_tree_failed entry bro in txt | Some (tokl, last_tok, son) -> @@ -206,7 +224,7 @@ let search_tree_in_entry prev_symb tree = Some (Node {node = n.node; son = t; brother = DeadEnd}) | None -> search_tree n.brother end - | _ -> None + | LocAct (_, _) | DeadEnd -> None and search_symbol symb = match symb with Snterm _ | Snterml (_, _) | Slist0 _ | Slist0sep (_, _) | Slist1 _ | @@ -252,7 +270,7 @@ let search_tree_in_entry prev_symb tree = | _ -> None in search_levels levels - | _ -> tree + | Dparser _ -> tree ;; let error_verbose = ref false;; @@ -349,7 +367,7 @@ let top_tree entry = function Node {node = s; brother = bro; son = son} -> Node {node = top_symb entry s; brother = bro; son = son} - | _ -> raise Stream.Failure + | LocAct (_, _) | DeadEnd -> raise Stream.Failure ;; let skip_if_empty bp p strm = @@ -366,17 +384,8 @@ let continue entry bp a s son p1 (strm__ : _ Stream.t) = Gramext.action (fun _ -> app act a) ;; -let - do_recover - parser_of_tree - entry - nlevn - alevn - bp - a - s - son - (strm__ : _ Stream.t) = +let do_recover + parser_of_tree entry nlevn alevn bp a s son (strm__ : _ Stream.t) = try parser_of_tree entry nlevn alevn (top_tree entry son) strm__ with Stream.Failure -> try @@ -395,8 +404,11 @@ let recover parser_of_tree entry nlevn alevn bp a s son strm = else do_recover parser_of_tree entry nlevn alevn bp a s son strm ;; +let token_count = ref 0;; + let peek_nth n strm = let list = Stream.npeek n strm in + token_count := Stream.count strm + n; let rec loop list n = match list, n with x :: _, 1 -> Some x @@ -496,7 +508,7 @@ and parser_of_token_list gram p1 tokl = Some tok -> let r = tematch tok in for i = 1 to n do Stream.junk strm done; Obj.repr r - | _ -> raise Stream.Failure + | None -> raise Stream.Failure in (fun (strm__ : _ Stream.t) -> let bp = Stream.count strm__ in @@ -521,7 +533,13 @@ and parser_of_token_list gram p1 tokl = loop 1 tokl and parser_of_symbol entry nlevn = function - Slist0 s -> + Smeta (_, symbl, act) -> + let act = Obj.magic act entry symbl in + Obj.magic + (List.fold_left + (fun act symb -> Obj.magic act (parser_of_symbol entry nlevn symb)) + act symbl) + | Slist0 s -> let ps = parser_of_symbol entry nlevn s in let rec loop al (strm__ : _ Stream.t) = match @@ -581,9 +599,7 @@ and parser_of_symbol entry nlevn = let a = try ps strm__ with Stream.Failure -> - try - parser_of_symbol entry nlevn (top_symb entry symb) strm__ - with + try parse_top_symb entry symb strm__ with Stream.Failure -> raise (Stream.Error (symb_failed entry v sep symb)) in @@ -619,8 +635,12 @@ and parser_of_symbol entry nlevn = match Stream.peek strm with Some tok -> let r = f tok in Stream.junk strm; Obj.repr r | None -> raise Stream.Failure +and parse_top_symb entry symb = + parser_of_symbol entry 0 (top_symb entry symb) ;; +let symb_failed_txt e s1 s2 = symb_failed e 0 s1 s2;; + let rec continue_parser_of_levels entry clevn = function [] -> (fun levn bp a (strm__ : _ Stream.t) -> raise Stream.Failure) @@ -709,22 +729,29 @@ let start_parser_of_entry entry = ;; let parse_parsable entry efun (cs, (ts, fun_loc)) = - let restore = let old_floc = !floc in fun () -> floc := old_floc in + let restore = + let old_floc = !floc in + let old_tc = !token_count in + fun () -> floc := old_floc; token_count := old_tc + in + let get_loc () = + try + let cnt = Stream.count ts in + let loc = fun_loc cnt in + if !token_count - 1 <= cnt then loc + else fst loc, snd (fun_loc (!token_count - 1)) + with + _ -> Stream.count cs, Stream.count cs + 1 + in floc := fun_loc; + token_count := 0; try let r = efun ts in restore (); r with Stream.Failure -> - let loc = - try fun_loc (Stream.count ts) with - _ -> Stream.count cs, Stream.count cs + 1 - in + let loc = get_loc () in restore (); raise_with_loc loc (Stream.Error ("illegal begin of " ^ entry.ename)) | Stream.Error _ as exc -> - let loc = - try fun_loc (Stream.count ts) with - _ -> Stream.count cs, Stream.count cs + 1 - in - restore (); raise_with_loc loc exc + let loc = get_loc () in restore (); raise_with_loc loc exc | exc -> let loc = Stream.count cs, Stream.count cs + 1 in restore (); raise_with_loc loc exc @@ -805,7 +832,7 @@ let delete_rule entry sl = (fun lev bp a strm -> let f = continue_parser_of_entry entry in entry.econtinue <- f; f lev bp a strm) - | _ -> () + | Dparser _ -> () ;; (* Unsafe *) @@ -846,13 +873,22 @@ let find_entry e s = function Snterm e -> if e.ename = s then Some e else None | Snterml (e, _) -> if e.ename = s then Some e else None + | Smeta (_, sl, _) -> find_symbol_list sl | Slist0 s -> find_symbol s | Slist0sep (s, _) -> find_symbol s | Slist1 s -> find_symbol s | Slist1sep (s, _) -> find_symbol s | Sopt s -> find_symbol s | Stree t -> find_tree t - | _ -> None + | Sself | Snext | Stoken _ -> None + and find_symbol_list = + function + s :: sl -> + begin match find_symbol s with + None -> find_symbol_list sl + | x -> x + end + | [] -> None and find_tree = function Node {node = s; brother = bro; son = son} -> @@ -864,7 +900,7 @@ let find_entry e s = end | x -> x end - | _ -> None + | LocAct (_, _) | DeadEnd -> None in match e.edesc with Dlevels levs -> @@ -1001,20 +1037,17 @@ module GGMake (R : ReinitType) (L : GLexerType) = module GMake (L : GLexerType) = GGMake - ( (struct let reinit_gram _ _ = failwith "call of deprecated reinit_gram in grammar built by GMake" ;; - end)) - ( - L) + end) + (L) ;; module type LexerType = sig val lexer : Token.lexer;; end;; module Make (L : LexerType) = - GGMake ((struct let reinit_gram = reinit_gram;; end)) - ( - (struct type te = Token.t;; let lexer = glexer_of_lexer L.lexer;; end)) + GGMake (struct let reinit_gram = reinit_gram;; end) + (struct type te = Token.t;; let lexer = glexer_of_lexer L.lexer;; end) ;; diff --git a/camlp4/ocaml_src/lib/grammar.mli b/camlp4/ocaml_src/lib/grammar.mli index 4db01844f..c29e8f8a7 100644 --- a/camlp4/ocaml_src/lib/grammar.mli +++ b/camlp4/ocaml_src/lib/grammar.mli @@ -12,19 +12,19 @@ (* This file has been generated by program: do not edit! *) -(* Module [Grammar]: extensible grammars *) +(** Extensible grammars. -(* This module implements the Camlp4 extensible grammars system. - Grammars entries can be extended using the [EXTEND] statement, - added by loading the Camlp4 [pa_extend.cmo] file. *) + This module implements the Camlp4 extensible grammars system. + Grammars entries can be extended using the [EXTEND] statement, + added by loading the Camlp4 [pa_extend.cmo] file. *) type g;; - (* The type for grammars, holding entries. *) + (** The type for grammars, holding entries. *) val gcreate : Token.t Token.glexer -> g;; - (* Create a new grammar, without keywords, using the lexer given + (** Create a new grammar, without keywords, using the lexer given as parameter. *) val tokens : g -> string -> (string * int) list;; - (* Given a grammar and a token pattern constructor, returns the list of + (** Given a grammar and a token pattern constructor, returns the list of the corresponding values currently used in all entries of this grammar. The integer is the number of times this pattern value is used. @@ -49,66 +49,50 @@ module Entry : external obj : 'a e -> Token.t Gramext.g_entry = "%identity";; end ;; - (* Module to handle entries. -- * [Entry.e] is the type for entries returning values of type ['a]. -- * [Entry.create g n] creates a new entry named [n] in the grammar [g]. -- * [Entry.parse e] returns the stream parser of the entry [e]. -- * [Entry.parse_token e] returns the token parser of the entry [e]. -- * [Entry.name e] returns the name of the entry [e]. -- * [Entry.of_parser g n p] makes an entry from a token stream parser. -- * [Entry.print e] displays the entry [e] using [Format]. -- * [Entry.find e s] finds the entry named [s] in [e]'s rules. -- * [Entry.obj e] converts an entry into a [Gramext.g_entry] allowing -- to see what it holds ([Gramext] is visible, but not documented). *) + (** Module to handle entries. +- [Entry.e] is the type for entries returning values of type ['a]. +- [Entry.create g n] creates a new entry named [n] in the grammar [g]. +- [Entry.parse e] returns the stream parser of the entry [e]. +- [Entry.parse_token e] returns the token parser of the entry [e]. +- [Entry.name e] returns the name of the entry [e]. +- [Entry.of_parser g n p] makes an entry from a token stream parser. +- [Entry.print e] displays the entry [e] using [Format]. +- [Entry.find e s] finds the entry named [s] in [e]'s rules. +- [Entry.obj e] converts an entry into a [Gramext.g_entry] allowing +- to see what it holds ([Gramext] is visible, but not documented). *) val of_entry : 'a Entry.e -> g;; - (* Return the grammar associated with an entry. *) + (** Return the grammar associated with an entry. *) -val error_verbose : bool ref;; - (* Flag for displaying more information in case of parsing error; - default = [False] *) - -val warning_verbose : bool ref;; - (* Flag for displaying warnings while extension; default = [True] *) - -val strict_parsing : bool ref;; - (* Flag to apply strict parsing, without trying to recover errors; - default = [False] *) - -(*** Clearing grammars and entries *) +(** {6 Clearing grammars and entries} *) module Unsafe : sig val gram_reinit : g -> Token.t Token.glexer -> unit;; val clear_entry : 'a Entry.e -> unit;; - (* deprecated since version 3.04+6; use rather function gram_reinit *) val reinit_gram : g -> Token.lexer -> unit;; end ;; - (* Module for clearing grammars and entries. To be manipulated with + (** Module for clearing grammars and entries. To be manipulated with care, because: 1) reinitializing a grammar destroys all tokens and there may have problems with the associated lexer if it has a notion of keywords; 2) clearing an entry does not destroy the tokens used only by itself. -- * [Unsafe.reinit_gram g lex] removes the tokens of the grammar -- and sets [lex] as a new lexer for [g]. Warning: the lexer -- itself is not reinitialized. -- * [Unsafe.clear_entry e] removes all rules of the entry [e]. *) +- [Unsafe.reinit_gram g lex] removes the tokens of the grammar +- and sets [lex] as a new lexer for [g]. Warning: the lexer +- itself is not reinitialized. +- [Unsafe.clear_entry e] removes all rules of the entry [e]. *) -(*** Functorial interface *) +(** {6 Functorial interface} *) - (* Alternative for grammars use. Grammars are no more Ocaml values: + (** Alternative for grammars use. Grammars are no more Ocaml values: there is no type for them. Modules generated preserve the rule "an entry cannot call an entry of another grammar" by - normal Ocaml typing. *) + normal OCaml typing. *) module type GLexerType = sig type te;; val lexer : te Token.glexer;; end;; - (* The input signature for the functor [Grammar.GMake]: [te] is the - type of the tokens, [tematch] is the way a token is matched against - a pattern. Must raise [Stream.Failure] if not matched. Warning: - write the function [tematch] as a function of pattern returning - a function to each pattern case, not a function of two parameters: - it may have some performance importance. *) + (** The input signature for the functor [Grammar.GMake]: [te] is the + type of the tokens. *) module type S = sig @@ -132,12 +116,10 @@ module type S = sig val gram_reinit : te Token.glexer -> unit;; val clear_entry : 'a Entry.e -> unit;; - (* deprecated since version 3.04+6; use rather gram_reinit *) val reinit_gram : Token.lexer -> unit;; end ;; - (* warning: reinit_gram fails if used with GMake *) - val extend : + val extend : 'a Entry.e -> Gramext.position option -> (string option * Gramext.g_assoc option * (te Gramext.g_symbol list * Gramext.g_action) list) @@ -146,27 +128,40 @@ module type S = val delete_rule : 'a Entry.e -> te Gramext.g_symbol list -> unit;; end ;; - (* Signature type of the functor [Grammar.Make]. The types and + (** Signature type of the functor [Grammar.GMake]. The types and functions are almost the same than in generic interface, but: -- * Grammars are not values. Functions holding a grammar as parameter -- do not have this parameter yet. -- * The type [parsable] is used in function [parse] instead of -- the char stream, avoiding the possible loss of tokens. -- * The type of tokens (expressions and patterns) can be any -- type (instead of (string * string)); the module parameter -- must specify a way to show them as (string * string) *) +- Grammars are not values. Functions holding a grammar as parameter + do not have this parameter yet. +- The type [parsable] is used in function [parse] instead of + the char stream, avoiding the possible loss of tokens. +- The type of tokens (expressions and patterns) can be any + type (instead of (string * string)); the module parameter + must specify a way to show them as (string * string) *) module GMake (L : GLexerType) : S with type te = L.te;; +(** {6 Miscellaneous} *) + +val error_verbose : bool ref;; + (** Flag for displaying more information in case of parsing error; + default = [False] *) + +val warning_verbose : bool ref;; + (** Flag for displaying warnings while extension; default = [True] *) + +val strict_parsing : bool ref;; + (** Flag to apply strict parsing, without trying to recover errors; + default = [False] *) + val print_entry : Format.formatter -> 'te Gramext.g_entry -> unit;; - (* General printer for all kinds of entries (obj entries) *) + (** General printer for all kinds of entries (obj entries) *) -(*--*) +(**/**) -(*** deprecated since version 3.04+6; use rather the functor GMake *) +(*** deprecated since version 3.05; use rather the functor GMake *) module type LexerType = sig val lexer : Token.lexer;; end;; module Make (L : LexerType) : S with type te = Token.t;; -(*** deprecated since version 3.04+6; use rather the function gcreate *) +(*** deprecated since version 3.05; use rather the function gcreate *) val create : Token.lexer -> g;; (*** For system use *) @@ -180,3 +175,9 @@ val extend : list -> unit;; val delete_rule : 'a Entry.e -> Token.t Gramext.g_symbol list -> unit;; + +val parse_top_symb : + 'te Gramext.g_entry -> 'te Gramext.g_symbol -> 'te Stream.t -> Obj.t;; +val symb_failed_txt : + 'te Gramext.g_entry -> 'te Gramext.g_symbol -> 'te Gramext.g_symbol -> + string;; diff --git a/camlp4/ocaml_src/lib/plexer.ml b/camlp4/ocaml_src/lib/plexer.ml index 11ba6b887..2f1bf5b82 100644 --- a/camlp4/ocaml_src/lib/plexer.ml +++ b/camlp4/ocaml_src/lib/plexer.ml @@ -162,13 +162,13 @@ let next_token_fun dfa find_kwd = let s = strm__ in begin match Stream.npeek 2 s with [_; '\''] | ['\\'; _] -> - let tok = "CHAR", char bp 0 s in + let tok = "CHAR", get_buff (char bp 0 s) in let loc = bp, Stream.count s in tok, loc | _ -> keyword_or_error (bp, Stream.count s) "'" end - | Some '"' -> + | Some '\"' -> Stream.junk strm__; - let tok = "STRING", string bp 0 strm__ in + let tok = "STRING", get_buff (string bp 0 strm__) in let loc = bp, Stream.count strm__ in tok, loc | Some '$' -> Stream.junk strm__; @@ -327,7 +327,7 @@ let next_token_fun dfa find_kwd = let id = get_buff len in keyword_or_error (bp, ep) id and string bp len (strm__ : _ Stream.t) = match Stream.peek strm__ with - Some '"' -> Stream.junk strm__; get_buff len + Some '\"' -> Stream.junk strm__; len | Some '\\' -> Stream.junk strm__; begin match Stream.peek strm__ with @@ -342,8 +342,7 @@ let next_token_fun dfa find_kwd = match Stream.peek strm__ with Some '\'' -> Stream.junk strm__; - let s = strm__ in - if len = 0 then char bp (store len '\'') s else get_buff len + let s = strm__ in if len = 0 then char bp (store len '\'') s else len | Some '\\' -> Stream.junk strm__; begin match Stream.peek strm__ with @@ -506,9 +505,44 @@ let next_token_fun dfa find_kwd = match Stream.peek strm__ with Some '(' -> Stream.junk strm__; left_paren_in_comment bp strm__ | Some '*' -> Stream.junk strm__; star_in_comment bp strm__ + | Some '\"' -> + Stream.junk strm__; + let _ = + try string bp 0 strm__ with + Stream.Failure -> raise (Stream.Error "") + in + comment bp strm__ + | Some '\'' -> Stream.junk strm__; quote_in_comment bp strm__ | Some c -> Stream.junk strm__; comment bp strm__ | _ -> let ep = Stream.count strm__ in err (bp, ep) "comment not terminated" + and quote_in_comment bp (strm__ : _ Stream.t) = + match Stream.peek strm__ with + Some '\'' -> Stream.junk strm__; comment bp strm__ + | Some '\\' -> Stream.junk strm__; quote_antislash_in_comment bp 0 strm__ + | Some _ -> Stream.junk strm__; quote_any_in_comment bp strm__ + | _ -> comment bp strm__ + and quote_any_in_comment bp (strm__ : _ Stream.t) = + match Stream.peek strm__ with + Some '\'' -> Stream.junk strm__; comment bp strm__ + | _ -> comment bp strm__ + and quote_antislash_in_comment bp len (strm__ : _ Stream.t) = + match Stream.peek strm__ with + Some '\'' -> Stream.junk strm__; comment bp strm__ + | Some ('\\' | '\"' | 'n' | 't' | 'b' | 'r') -> + Stream.junk strm__; quote_any_in_comment bp strm__ + | Some ('0'..'9') -> + Stream.junk strm__; quote_antislash_digit_in_comment bp strm__ + | _ -> comment bp strm__ + and quote_antislash_digit_in_comment bp (strm__ : _ Stream.t) = + match Stream.peek strm__ with + Some ('0'..'9') -> + Stream.junk strm__; quote_antislash_digit2_in_comment bp strm__ + | _ -> comment bp strm__ + and quote_antislash_digit2_in_comment bp (strm__ : _ Stream.t) = + match Stream.peek strm__ with + Some ('0'..'9') -> Stream.junk strm__; quote_any_in_comment bp strm__ + | _ -> comment bp strm__ and left_paren_in_comment bp (strm__ : _ Stream.t) = match Stream.peek strm__ with Some '*' -> @@ -531,7 +565,7 @@ let next_token_fun dfa find_kwd = Stream.Failure -> raise (Stream.Error "") in begin match Stream.peek strm__ with - Some '"' -> + Some '\"' -> Stream.junk strm__; let _ = try any_to_nl strm__ with diff --git a/camlp4/ocaml_src/lib/plexer.mli b/camlp4/ocaml_src/lib/plexer.mli index 31c5be4d5..d682f83ae 100644 --- a/camlp4/ocaml_src/lib/plexer.mli +++ b/camlp4/ocaml_src/lib/plexer.mli @@ -12,10 +12,10 @@ (* This file has been generated by program: do not edit! *) -(* Module [Plexer]: a lexical analyzer *) +(** A lexical analyzer. *) val gmake : unit -> Token.t Token.glexer;; - (* Some lexer provided. See the module [Token]. The tokens returned + (** Some lexer provided. See the module [Token]. The tokens returned follow the Objective Caml and the Revised syntax lexing rules. The meaning of the tokens are: @@ -35,20 +35,31 @@ val gmake : unit -> Token.t Token.glexer;; same names than the first string (constructor name) of the tokens expressions above. + Warning: the string associated with the constructor [STRING] is + the string found in the source without any interpretation. In + particular, the backslashes are not interpreted. For example, if + the input is ["\n"] the string is *not* a string with one + element containing the character "return", but a string of two + elements: the backslash and the character ["n"]. To interpret + a string use the function [Token.eval_string]. Same thing for + the constructor [CHAR]: to get the character, don't get the + first character of the string, but use the function + [Token.eval_char]. + The lexer do not use global (mutable) variables: instantiations of [Plexer.gmake ()] do not perturb each other. *) val dollar_for_antiquotation : bool ref;; - (* When True (default), the next call to [Plexer.make ()] returns a + (** When True (default), the next call to [Plexer.make ()] returns a lexer where the dollar sign is used for antiquotations. If False, the dollar sign can be used as token. *) val no_quotations : bool ref;; - (* When True, all lexers built by [Plexer.make ()] do not lex the + (** When True, all lexers built by [Plexer.make ()] do not lex the quotation syntax any more. Default is False (quotations are lexed). *) -(*--*) +(**/**) -(* deprecated since version 3.04+6; use rather function gmake *) +(* deprecated since version 3.05; use rather function gmake *) val make : unit -> Token.lexer;; diff --git a/camlp4/ocaml_src/lib/stdpp.mli b/camlp4/ocaml_src/lib/stdpp.mli index 7ce86bc01..5afd1b2db 100644 --- a/camlp4/ocaml_src/lib/stdpp.mli +++ b/camlp4/ocaml_src/lib/stdpp.mli @@ -12,24 +12,24 @@ (* This file has been generated by program: do not edit! *) -(* Module [Stdpp]: standard definitions *) +(** Standard definitions. *) exception Exc_located of (int * int) * exn;; - (* [Exc_located loc e] is an encapsulation of the exception [e] with + (** [Exc_located loc e] is an encapsulation of the exception [e] with the input location [loc]. To be used in quotation expanders and in grammars to specify some input location for an error. Do not raise this exception directly: rather use the following function [raise_with_loc]. *) val raise_with_loc : int * int -> exn -> 'a;; - (* [raise_with_loc loc e], if [e] is already the exception [Exc_located], + (** [raise_with_loc loc e], if [e] is already the exception [Exc_located], re-raise it, else raise the exception [Exc_located loc e]. *) val line_of_loc : string -> int * int -> int * int * int;; - (* [line_of_loc fname loc] reads the file [fname] up to the + (** [line_of_loc fname loc] reads the file [fname] up to the location [loc] and returns the line number and the characters location in the line *) val loc_name : string ref;; - (* Name of the location variable used in grammars and in the predefined + (** Name of the location variable used in grammars and in the predefined quotations for OCaml syntax trees. Default: [loc] *) diff --git a/camlp4/ocaml_src/lib/token.ml b/camlp4/ocaml_src/lib/token.ml index 274a4751e..99bbd2f21 100644 --- a/camlp4/ocaml_src/lib/token.ml +++ b/camlp4/ocaml_src/lib/token.ml @@ -120,6 +120,8 @@ let rec backslash s i = | 't' -> '\t', i + 1 | 'b' -> '\b', i + 1 | '\\' -> '\\', i + 1 + | '\"' -> '\"', i + 1 + | '\'' -> '\'', i + 1 | '0'..'9' as c -> backslash1 (valch c) s (i + 1) | _ -> raise Not_found and backslash1 cod s i = @@ -170,7 +172,7 @@ let eval_string s = if s.[i] = '\\' then let i = i + 1 in if i = String.length s then failwith "invalid string token" - else if s.[i] = '"' then store len '"', i + 1 + else if s.[i] = '\"' then store len '\"', i + 1 else match s.[i] with '\010' -> len, skip_indent s (i + 1) diff --git a/camlp4/ocaml_src/lib/token.mli b/camlp4/ocaml_src/lib/token.mli index 1b5882c53..4e14469d6 100644 --- a/camlp4/ocaml_src/lib/token.mli +++ b/camlp4/ocaml_src/lib/token.mli @@ -12,37 +12,33 @@ (* This file has been generated by program: do not edit! *) -(* Module [Token]: lexers for Camlp4 grammars *) +(** Lexers for Camlp4 grammars. -(* This module defines the Camlp4 lexer type to be used in extensible + This module defines the Camlp4 lexer type to be used in extensible grammars (see module [Grammar]). It also provides some useful functions to create lexers (this module should be renamed [Glexer] one day). *) -(*** Token type *) - -type t = string * string;; type pattern = string * string;; - (* Token and token patterns. Token are build by the lexer. Token - patterns come from the EXTEND statement. + (** Token patterns come from the EXTEND statement. - The first string is the constructor name (must start with an uppercase character). When it is empty, the second string is supposed to be a keyword. - The second string is the constructor parameter. Empty if it has no parameter. -- The way tokens pattern are interpreted to parse tokens is - done by the lexer, function [tparse] below. *) +- The way tokens patterns are interpreted to parse tokens is + done by the lexer, function [tok_match] below. *) exception Error of string;; - (* An lexing error exception to be used by lexers. *) + (** An lexing error exception to be used by lexers. *) -(*** Lexer type *) +(** {6 Lexer type} *) type location = int * int;; type location_function = int -> location;; - (* The type for a function associating a number of a token in a stream + (** The type for a function associating a number of a token in a stream (starting from 0) to its source location. *) type 'te lexer_func = char Stream.t -> 'te Stream.t * location_function;; - (* The type for a lexer function. The character stream is the input + (** The type for a lexer function. The character stream is the input stream to be lexed. The result is a pair of a token stream and a location function for this tokens stream. *) @@ -53,7 +49,7 @@ type 'te glexer = tok_match : pattern -> 'te -> string; tok_text : pattern -> string } ;; - (* The type for a lexer used by Camlp4 grammars. + (** The type for a lexer used by Camlp4 grammars. - The field [tok_func] is the main lexer function. See [lexer_func] type above. This function may be created from a [char stream parser] or for an [ocamllex] function using the functions below. @@ -73,21 +69,24 @@ type 'te glexer = used in error messages. *) val lexer_text : pattern -> string;; - (* A simple [tok_text] function for lexers *) + (** A simple [tok_text] function for lexers *) -val default_match : pattern -> t -> string;; - (* A simple [tok_match] function for lexers, appling to type [t] *) +val default_match : pattern -> string * string -> string;; + (** A simple [tok_match] function for lexers, appling to token type + [(string * string)] *) -(*** Lexer from char stream parsers or ocamllex function *) +(** {6 Lexers from char stream parsers or ocamllex function} -(* The functions below create lexer functions either from a [char stream] + The functions below create lexer functions either from a [char stream] parser or for an [ocamllex] function. With the returned function [f], the simplest [Token.lexer] can be written: -- [ { Token.tok_func = f; ] -- [ Token.tok_using = (fun _ -> ()); ] -- [ Token.tok_removing = (fun _ -> ()); ] -- [ Token.tok_match = Token.default_match; ] -- [ Token.tok_text = Token.lexer_text } ] + {[ + { Token.tok_func = f; + Token.tok_using = (fun _ -> ()); + Token.tok_removing = (fun _ -> ()); + Token.tok_match = Token.default_match; + Token.tok_text = Token.lexer_text } + ]} Note that a better [tok_using] function should check the used tokens and raise [Token.Error] for incorrect ones. The other functions [tok_removing], [tok_match] and [tok_text] may have other implementations @@ -95,26 +94,28 @@ val default_match : pattern -> t -> string;; val lexer_func_of_parser : (char Stream.t -> 'te * location) -> 'te lexer_func;; - (* A lexer function from a lexer written as a char stream parser + (** A lexer function from a lexer written as a char stream parser returning the next token and its location. *) val lexer_func_of_ocamllex : (Lexing.lexbuf -> 'te) -> 'te lexer_func;; - (* A lexer function from a lexer created by [ocamllex] *) + (** A lexer function from a lexer created by [ocamllex] *) val make_stream_and_location : (unit -> 'te * location) -> 'te Stream.t * location_function;; + (** General function *) -(*** Useful functions *) +(** {6 Useful functions} *) val eval_char : string -> char;; val eval_string : string -> string;; - (* Convert a char or a string token, where the backslashes have not + (** Convert a char or a string token, where the backslashes had not been interpreted into a real char or string; raise [Failure] if bad backslash sequence found; [Token.eval_char (Char.escaped c)] returns [c] and [Token.eval_string (String.escaped s)] returns [s] *) -(*--*) +(**/**) -(* deprecated since version 3.04+6; use rather type glexer *) +(* deprecated since version 3.05; use rather type glexer *) +type t = string * string;; type lexer = { func : t lexer_func; using : pattern -> unit; diff --git a/camlp4/ocaml_src/meta/.depend b/camlp4/ocaml_src/meta/.depend index c29792f15..b78fbcd10 100644 --- a/camlp4/ocaml_src/meta/.depend +++ b/camlp4/ocaml_src/meta/.depend @@ -1,14 +1,16 @@ pa_extend.cmo: ../camlp4/mLast.cmi ../camlp4/pcaml.cmi pa_extend.cmx: ../camlp4/mLast.cmi ../camlp4/pcaml.cmx -pa_extend_m.cmo: ../camlp4/mLast.cmi pa_extend.cmo -pa_extend_m.cmx: ../camlp4/mLast.cmi pa_extend.cmx +pa_extend_m.cmo: pa_extend.cmo +pa_extend_m.cmx: pa_extend.cmx pa_ifdef.cmo: ../camlp4/mLast.cmi ../camlp4/pcaml.cmi pa_ifdef.cmx: ../camlp4/mLast.cmi ../camlp4/pcaml.cmx pa_r.cmo: ../camlp4/mLast.cmi ../camlp4/pcaml.cmi pa_r.cmx: ../camlp4/mLast.cmi ../camlp4/pcaml.cmx pa_rp.cmo: ../camlp4/mLast.cmi ../camlp4/pcaml.cmi pa_rp.cmx: ../camlp4/mLast.cmi ../camlp4/pcaml.cmx -pr_dump.cmo: ../camlp4/ast2pt.cmi $(OTOP)/utils/config.cmi ../camlp4/pcaml.cmi -pr_dump.cmx: ../camlp4/ast2pt.cmx $(OTOP)/utils/config.cmx ../camlp4/pcaml.cmx +pr_dump.cmo: ../camlp4/ast2pt.cmi ../camlp4/pcaml.cmi \ + $(OTOP)/utils/config.cmo +pr_dump.cmx: ../camlp4/ast2pt.cmx ../camlp4/pcaml.cmx \ + $(OTOP)/utils/config.cmx q_MLast.cmo: ../camlp4/mLast.cmi ../camlp4/pcaml.cmi ../camlp4/quotation.cmi q_MLast.cmx: ../camlp4/mLast.cmi ../camlp4/pcaml.cmx ../camlp4/quotation.cmx diff --git a/camlp4/ocaml_src/meta/Makefile b/camlp4/ocaml_src/meta/Makefile index 6a4f4a7de..aac0f0abd 100644 --- a/camlp4/ocaml_src/meta/Makefile +++ b/camlp4/ocaml_src/meta/Makefile @@ -34,7 +34,7 @@ depend: done promote: - cp $(COUT) ../../boot/. + cp $(COUT) pa_extend.cmi ../../boot/. compare: @for j in $(COUT); do \ @@ -44,7 +44,7 @@ compare: install: -$(MKDIR) $(LIBDIR)/camlp4 $(BINDIR) cp $(OBJS) $(LIBDIR)/camlp4/. - cp pa_ifdef.cmi $(LIBDIR)/camlp4/. + cp pa_ifdef.cmi pa_extend.cmi $(LIBDIR)/camlp4/. cp camlp4r$(EXE) $(BINDIR)/. if test -f $(COPT); then cp $(COPT) $(BINDIR)/.; fi diff --git a/camlp4/ocaml_src/meta/Makefile.Mac b/camlp4/ocaml_src/meta/Makefile.Mac index 0d3a3bd84..b62b945c1 100644 --- a/camlp4/ocaml_src/meta/Makefile.Mac +++ b/camlp4/ocaml_src/meta/Makefile.Mac @@ -32,7 +32,7 @@ clean �� {dependrule} promote � - duplicate -y {OUT} :::boot: + duplicate -y {OUT} pa_extend.cmi :::boot: compare � for i in {OUT} diff --git a/camlp4/ocaml_src/meta/pa_extend.ml b/camlp4/ocaml_src/meta/pa_extend.ml index 111dcbd68..ea822c6b3 100644 --- a/camlp4/ocaml_src/meta/pa_extend.ml +++ b/camlp4/ocaml_src/meta/pa_extend.ml @@ -28,13 +28,15 @@ type 'e name = { expr : 'e; tvar : string; loc : int * int };; type styp = STlid of loc * string - | STapp of loc * string * styp + | STapp of loc * styp * styp | STquo of loc * string - | STprm of loc * string + | STself of loc * string + | STtyp of MLast.ctyp ;; type 'e text = - TXlist of loc * bool * 'e text * 'e text option + TXmeta of loc * string * 'e text list * 'e * styp + | TXlist of loc * bool * 'e text * 'e text option | TXnext of loc | TXnterm of loc * 'e name * string option | TXopt of loc * 'e text @@ -49,14 +51,18 @@ and ('e, 'p) level = { label : string option; assoc : 'e option; rules : ('e, 'p) rule list } and ('e, 'p) rule = { prod : ('e, 'p) psymbol list; action : 'e option } and ('e, 'p) psymbol = { pattern : 'p option; symbol : ('e, 'p) symbol } -and ('e, 'p) symbol = { used : 'e name list; text : 'e text; styp : styp } +and ('e, 'p) symbol = { used : string list; text : 'e text; styp : styp } ;; -type used = Unused | UsedScanned | UsedNotScanned;; +type used = + Unused + | UsedScanned + | UsedNotScanned +;; let mark_used modif ht n = try - let rll = Hashtbl.find_all ht n.tvar in + let rll = Hashtbl.find_all ht n in List.iter (fun (r, _) -> if !r == Unused then begin r := UsedNotScanned; modif := true end) @@ -819,19 +825,47 @@ let quotify_action psl act = let rec make_ctyp styp tvar = match styp with STlid (loc, s) -> MLast.TyLid (loc, s) - | STapp (loc, s, t) -> - MLast.TyApp (loc, MLast.TyLid (loc, s), make_ctyp t tvar) + | STapp (loc, t1, t2) -> + MLast.TyApp (loc, make_ctyp t1 tvar, make_ctyp t2 tvar) | STquo (loc, s) -> MLast.TyQuo (loc, s) - | STprm (loc, x) -> + | STself (loc, x) -> if tvar = "" then Stdpp.raise_with_loc loc (Stream.Error ("'" ^ x ^ "' illegal in anonymous entry level")) else MLast.TyQuo (loc, tvar) + | STtyp t -> t ;; let rec make_expr gmod tvar = function - TXlist (loc, min, t, ts) -> + TXmeta (loc, n, tl, e, t) -> + let el = + List.fold_right + (fun t el -> + MLast.ExApp + (loc, + MLast.ExApp + (loc, MLast.ExUid (loc, "::"), make_expr gmod "" t), + el)) + tl (MLast.ExUid (loc, "[]")) + in + MLast.ExApp + (loc, + MLast.ExApp + (loc, + MLast.ExApp + (loc, + MLast.ExAcc + (loc, MLast.ExUid (loc, "Gramext"), + MLast.ExUid (loc, "Smeta")), + MLast.ExStr (loc, n)), + el), + MLast.ExApp + (loc, + MLast.ExAcc + (loc, MLast.ExUid (loc, "Obj"), MLast.ExLid (loc, "repr")), + MLast.ExTyc (loc, e, make_ctyp t tvar))) + | TXlist (loc, min, t, ts) -> let txt = make_expr gmod "" t in begin match min, ts with false, None -> @@ -1073,7 +1107,7 @@ let mk_psymbol p s t = {pattern = Some p; symbol = symb} ;; -let sslist_aux loc min sep s = +let sslist loc min sep s = let rl = let r1 = let prod = @@ -1086,7 +1120,7 @@ let sslist_aux loc min sep s = let r2 = let prod = [mk_psymbol (MLast.PaLid (loc, "a")) (slist loc min sep s) - (STapp (loc, "list", s.styp))] + (STapp (loc, STlid (loc, "list"), s.styp))] in let act = MLast.ExApp @@ -1099,13 +1133,14 @@ let sslist_aux loc min sep s = in [r1; r2] in - TXrules (loc, srules loc "a_list" rl "") -;; - -let sslist loc min sep s = - match s.text with - TXself _ | TXnext _ -> slist loc min sep s - | _ -> sslist_aux loc min sep s + let used = + match sep with + Some symb -> symb.used @ s.used + | None -> s.used + in + let used = "a_list" :: used in + let text = TXrules (loc, srules loc "a_list" rl "") in + let styp = STquo (loc, "a_list") in {used = used; text = text; styp = styp} ;; let ssopt loc s = @@ -1141,7 +1176,7 @@ let ssopt loc s = in let prod = [mk_psymbol (MLast.PaLid (loc, "a")) (TXopt (loc, s.text)) - (STapp (loc, "option", s.styp))] + (STapp (loc, STlid (loc, "option"), s.styp))] in let act = MLast.ExApp @@ -1154,7 +1189,9 @@ let ssopt loc s = in [r1; r2] in - TXrules (loc, srules loc "a_opt" rl "") + let used = "a_opt" :: s.used in + let text = TXrules (loc, srules loc "a_opt" rl "") in + let styp = STquo (loc, "a_opt") in {used = used; text = text; styp = styp} ;; let text_of_entry loc gmod e = @@ -1732,7 +1769,7 @@ Grammar.extend (let name = mk_name loc (MLast.ExLid (loc, i)) in let text = TXnterm (loc, name, lev) in let styp = STquo (loc, i) in - let symb = {used = [name]; text = text; styp = styp} in + let symb = {used = [i]; text = text; styp = styp} in {pattern = None; symbol = symb} : 'psymbol)); [Gramext.Stoken ("LIDENT", ""); Gramext.Stoken ("", "="); @@ -1746,11 +1783,11 @@ Grammar.extend [[Gramext.Stoken ("UIDENT", "OPT"); Gramext.Sself], Gramext.action (fun (s : 'symbol) _ (loc : int * int) -> - (let styp = STapp (loc, "option", s.styp) in - let text = - if !quotify then ssopt loc s else TXopt (loc, s.text) - in - {used = s.used; text = text; styp = styp} : + (if !quotify then ssopt loc s + else + let styp = STapp (loc, STlid (loc, "option"), s.styp) in + let text = TXopt (loc, s.text) in + {used = s.used; text = text; styp = styp} : 'symbol)); [Gramext.Stoken ("UIDENT", "LIST1"); Gramext.Sself; Gramext.Sopt @@ -1762,16 +1799,16 @@ Grammar.extend (fun (t : 'symbol) _ (loc : int * int) -> (t : 'e__5))])], Gramext.action (fun (sep : 'e__5 option) (s : 'symbol) _ (loc : int * int) -> - (let used = - match sep with - Some symb -> symb.used @ s.used - | None -> s.used - in - let styp = STapp (loc, "list", s.styp) in - let text = - if !quotify then sslist loc true sep s else slist loc true sep s - in - {used = used; text = text; styp = styp} : + (if !quotify then sslist loc true sep s + else + let used = + match sep with + Some symb -> symb.used @ s.used + | None -> s.used + in + let styp = STapp (loc, STlid (loc, "list"), s.styp) in + let text = slist loc true sep s in + {used = used; text = text; styp = styp} : 'symbol)); [Gramext.Stoken ("UIDENT", "LIST0"); Gramext.Sself; Gramext.Sopt @@ -1783,17 +1820,16 @@ Grammar.extend (fun (t : 'symbol) _ (loc : int * int) -> (t : 'e__4))])], Gramext.action (fun (sep : 'e__4 option) (s : 'symbol) _ (loc : int * int) -> - (let used = - match sep with - Some symb -> symb.used @ s.used - | None -> s.used - in - let styp = STapp (loc, "list", s.styp) in - let text = - if !quotify then sslist loc false sep s - else slist loc false sep s - in - {used = used; text = text; styp = styp} : + (if !quotify then sslist loc false sep s + else + let used = + match sep with + Some symb -> symb.used @ s.used + | None -> s.used + in + let styp = STapp (loc, STlid (loc, "list"), s.styp) in + let text = slist loc false sep s in + {used = used; text = text; styp = styp} : 'symbol))]; None, None, [[Gramext.Stoken ("", "("); Gramext.Sself; Gramext.Stoken ("", ")")], @@ -1808,7 +1844,7 @@ Grammar.extend (fun (s : string) _ (loc : int * int) -> (s : 'e__7))])], Gramext.action (fun (lev : 'e__7 option) (n : 'name) (loc : int * int) -> - ({used = [n]; text = TXnterm (loc, n, lev); + ({used = [n.tvar]; text = TXnterm (loc, n, lev); styp = STquo (loc, n.tvar)} : 'symbol)); [Gramext.Stoken ("UIDENT", ""); Gramext.Stoken ("", "."); @@ -1825,7 +1861,7 @@ Grammar.extend (let n = mk_name loc (MLast.ExAcc (loc, MLast.ExUid (loc, i), e)) in - {used = [n]; text = TXnterm (loc, n, lev); + {used = [n.tvar]; text = TXnterm (loc, n, lev); styp = STquo (loc, n.tvar)} : 'symbol)); [Gramext.Snterm (Grammar.Entry.obj (string : 'string Grammar.Entry.e))], @@ -1866,12 +1902,12 @@ Grammar.extend [Gramext.Stoken ("UIDENT", "NEXT")], Gramext.action (fun _ (loc : int * int) -> - ({used = []; text = TXnext loc; styp = STprm (loc, "NEXT")} : + ({used = []; text = TXnext loc; styp = STself (loc, "NEXT")} : 'symbol)); [Gramext.Stoken ("UIDENT", "SELF")], Gramext.action (fun _ (loc : int * int) -> - ({used = []; text = TXself loc; styp = STprm (loc, "SELF")} : + ({used = []; text = TXself loc; styp = STself (loc, "SELF")} : 'symbol))]]; Grammar.Entry.obj (pattern : 'pattern Grammar.Entry.e), None, [None, None, diff --git a/camlp4/ocaml_src/meta/pa_extend_m.ml b/camlp4/ocaml_src/meta/pa_extend_m.ml index f93734935..11fd07f58 100644 --- a/camlp4/ocaml_src/meta/pa_extend_m.ml +++ b/camlp4/ocaml_src/meta/pa_extend_m.ml @@ -5,7 +5,7 @@ (* *) (* Daniel de Rauglaudre, projet Cristal, INRIA Rocquencourt *) (* *) -(* Copyright 2001 Institut National de Recherche en Informatique et *) +(* Copyright 2002 Institut National de Recherche en Informatique et *) (* Automatique. Distributed only by permission. *) (* *) (***********************************************************************) @@ -20,10 +20,7 @@ Grammar.extend [None, Some Gramext.NonA, [[Gramext.Stoken ("UIDENT", "SOPT"); Gramext.Sself], Gramext.action - (fun (s : 'symbol) _ (loc : int * int) -> - (let used = mk_name loc (MLast.ExLid (loc, "a_opt")) :: s.used in - {used = used; text = ssopt loc s; styp = STquo (loc, "a_opt")} : - 'symbol)); + (fun (s : 'symbol) _ (loc : int * int) -> (ssopt loc s : 'symbol)); [Gramext.srules [[Gramext.Stoken ("UIDENT", "SLIST1")], Gramext.action (fun _ (loc : int * int) -> (true : 'e__1)); @@ -40,12 +37,4 @@ Grammar.extend Gramext.action (fun (sep : 'e__2 option) (s : 'symbol) (min : 'e__1) (loc : int * int) -> - (let used = - match sep with - Some symb -> symb.used @ s.used - | None -> s.used - in - let used = mk_name loc (MLast.ExLid (loc, "a_list")) :: used in - {used = used; text = sslist loc min sep s; - styp = STquo (loc, "a_list")} : - 'symbol))]]];; + (sslist loc min sep s : 'symbol))]]];; diff --git a/camlp4/ocaml_src/meta/pa_ifdef.ml b/camlp4/ocaml_src/meta/pa_ifdef.ml index 1ae61965a..6384d6be1 100644 --- a/camlp4/ocaml_src/meta/pa_ifdef.ml +++ b/camlp4/ocaml_src/meta/pa_ifdef.ml @@ -1,7 +1,11 @@ (* camlp4r pa_extend.cmo q_MLast.cmo *) (* This file has been generated by program: do not edit! *) -type 'a item_or_def = SdStr of 'a | SdDef of string | SdUnd of string | SdNop +type 'a item_or_def = + SdStr of 'a + | SdDef of string + | SdUnd of string + | SdNop ;; let list_remove x l = diff --git a/camlp4/ocaml_src/meta/pa_r.ml b/camlp4/ocaml_src/meta/pa_r.ml index 419a2c92c..b491fb788 100644 --- a/camlp4/ocaml_src/meta/pa_r.ml +++ b/camlp4/ocaml_src/meta/pa_r.ml @@ -173,15 +173,24 @@ Pcaml.sync.val := sync; let ipatt = Grammar.Entry.create gram "ipatt";; +let not_yet_warned_variant = ref true;; +let warn_variant () = + if !not_yet_warned_variant then + begin + not_yet_warned_variant := false; + Printf.eprintf "\ +*** warning: use of syntax of variants types deprecated since version 3.05\n"; + flush stderr + end +;; + let not_yet_warned = ref true;; -let warning_seq () = +let warn_sequence () = if !not_yet_warned then begin not_yet_warned := false; Printf.eprintf "\ -*** warning: use of old syntax -*** type \"camlp4r -help_seq\" in a shell for explanations -"; +*** warning: use of syntax of sequences deprecated since version 3.01.1\n"; flush stderr end ;; @@ -280,6 +289,7 @@ Grammar.extend and meth_list : 'meth_list Grammar.Entry.e = grammar_entry_create "meth_list" and field : 'field Grammar.Entry.e = grammar_entry_create "field" + and typevar : 'typevar Grammar.Entry.e = grammar_entry_create "typevar" and clty_longident : 'clty_longident Grammar.Entry.e = grammar_entry_create "clty_longident" and class_longident : 'class_longident Grammar.Entry.e = @@ -296,6 +306,8 @@ Grammar.extend grammar_entry_create "mutable_flag" and virtual_flag : 'virtual_flag Grammar.Entry.e = grammar_entry_create "virtual_flag" + and warning_variant : 'warning_variant Grammar.Entry.e = + grammar_entry_create "warning_variant" and warning_sequence : 'warning_sequence Grammar.Entry.e = grammar_entry_create "warning_sequence" in @@ -514,6 +526,11 @@ Grammar.extend Gramext.action (fun _ (mt : 'module_type) _ (loc : int * int) -> (mt : 'module_type)); + [Gramext.Stoken ("", "'"); + Gramext.Snterm (Grammar.Entry.obj (ident : 'ident Grammar.Entry.e))], + Gramext.action + (fun (i : 'ident) _ (loc : int * int) -> + (MLast.MtQuo (loc, i) : 'module_type)); [Gramext.Stoken ("LIDENT", "")], Gramext.action (fun (i : string) (loc : int * int) -> @@ -620,10 +637,10 @@ Grammar.extend (Grammar.Entry.obj (mod_ident : 'mod_ident Grammar.Entry.e)); Gramext.Stoken ("", "="); Gramext.Snterm - (Grammar.Entry.obj (module_type : 'module_type Grammar.Entry.e))], + (Grammar.Entry.obj (module_expr : 'module_expr Grammar.Entry.e))], Gramext.action - (fun (mt : 'module_type) _ (i : 'mod_ident) _ (loc : int * int) -> - (MLast.WcMod (loc, i, mt) : 'with_constr)); + (fun (me : 'module_expr) _ (i : 'mod_ident) _ (loc : int * int) -> + (MLast.WcMod (loc, i, me) : 'with_constr)); [Gramext.Stoken ("", "type"); Gramext.Snterm (Grammar.Entry.obj (mod_ident : 'mod_ident Grammar.Entry.e)); @@ -1443,6 +1460,15 @@ Grammar.extend Gramext.action (fun (t2 : 'ctyp) _ (t1 : 'ctyp) (loc : int * int) -> (MLast.TyAli (loc, t1, t2) : 'ctyp))]; + None, Some Gramext.LeftA, + [[Gramext.Stoken ("", "!"); + Gramext.Slist1 + (Gramext.Snterm + (Grammar.Entry.obj (typevar : 'typevar Grammar.Entry.e))); + Gramext.Stoken ("", "."); Gramext.Sself], + Gramext.action + (fun (t : 'ctyp) _ (pl : 'typevar list) _ (loc : int * int) -> + (MLast.TyPol (loc, pl, t) : 'ctyp))]; Some "arrow", Some Gramext.RightA, [[Gramext.Sself; Gramext.Stoken ("", "->"); Gramext.Sself], Gramext.action @@ -1791,14 +1817,32 @@ Grammar.extend (Grammar.Entry.obj (fun_binding : 'fun_binding Grammar.Entry.e))], Gramext.action (fun (fb : 'fun_binding) (l : 'label) _ (loc : int * int) -> - (MLast.CrMth (loc, l, false, fb) : 'class_str_item)); + (MLast.CrMth (loc, l, false, fb, None) : 'class_str_item)); + [Gramext.Stoken ("", "method"); + Gramext.Snterm (Grammar.Entry.obj (label : 'label Grammar.Entry.e)); + Gramext.Stoken ("", ":"); + Gramext.Snterm (Grammar.Entry.obj (ctyp : 'ctyp Grammar.Entry.e)); + Gramext.Stoken ("", "="); + Gramext.Snterm (Grammar.Entry.obj (expr : 'expr Grammar.Entry.e))], + Gramext.action + (fun (e : 'expr) _ (t : 'ctyp) _ (l : 'label) _ (loc : int * int) -> + (MLast.CrMth (loc, l, false, e, Some t) : 'class_str_item)); [Gramext.Stoken ("", "method"); Gramext.Stoken ("", "private"); Gramext.Snterm (Grammar.Entry.obj (label : 'label Grammar.Entry.e)); Gramext.Snterm (Grammar.Entry.obj (fun_binding : 'fun_binding Grammar.Entry.e))], Gramext.action (fun (fb : 'fun_binding) (l : 'label) _ _ (loc : int * int) -> - (MLast.CrMth (loc, l, true, fb) : 'class_str_item)); + (MLast.CrMth (loc, l, true, fb, None) : 'class_str_item)); + [Gramext.Stoken ("", "method"); Gramext.Stoken ("", "private"); + Gramext.Snterm (Grammar.Entry.obj (label : 'label Grammar.Entry.e)); + Gramext.Stoken ("", ":"); + Gramext.Snterm (Grammar.Entry.obj (ctyp : 'ctyp Grammar.Entry.e)); + Gramext.Stoken ("", "="); + Gramext.Snterm (Grammar.Entry.obj (expr : 'expr Grammar.Entry.e))], + Gramext.action + (fun (e : 'expr) _ (t : 'ctyp) _ (l : 'label) _ _ (loc : int * int) -> + (MLast.CrMth (loc, l, true, e, Some t) : 'class_str_item)); [Gramext.Stoken ("", "method"); Gramext.Stoken ("", "virtual"); Gramext.Snterm (Grammar.Entry.obj (label : 'label Grammar.Entry.e)); Gramext.Stoken ("", ":"); @@ -2170,6 +2214,12 @@ Grammar.extend Gramext.action (fun (t : 'ctyp) _ (lab : string) (loc : int * int) -> (lab, t : 'field))]]; + Grammar.Entry.obj (typevar : 'typevar Grammar.Entry.e), None, + [None, None, + [[Gramext.Stoken ("", "'"); + Gramext.Snterm (Grammar.Entry.obj (ident : 'ident Grammar.Entry.e))], + Gramext.action + (fun (i : 'ident) _ (loc : int * int) -> (i : 'typevar))]]; Grammar.Entry.obj (clty_longident : 'clty_longident Grammar.Entry.e), None, [None, None, @@ -2208,7 +2258,7 @@ Grammar.extend Grammar.Entry.obj (ctyp : 'ctyp Grammar.Entry.e), Some (Gramext.Level "simple"), [None, None, - [[Gramext.Stoken ("", "[|"); Gramext.Stoken ("", "<"); + [[Gramext.Stoken ("", "["); Gramext.Stoken ("", "<"); Gramext.Snterm (Grammar.Entry.obj (row_field_list : 'row_field_list Grammar.Entry.e)); @@ -2216,40 +2266,39 @@ Grammar.extend Gramext.Slist1 (Gramext.Snterm (Grammar.Entry.obj (name_tag : 'name_tag Grammar.Entry.e))); - Gramext.Stoken ("", "|]")], + Gramext.Stoken ("", "]")], Gramext.action (fun _ (ntl : 'name_tag list) _ (rfl : 'row_field_list) _ _ (loc : int * int) -> (MLast.TyVrn (loc, rfl, Some (Some ntl)) : 'ctyp)); - [Gramext.Stoken ("", "[|"); Gramext.Stoken ("", "<"); + [Gramext.Stoken ("", "["); Gramext.Stoken ("", "<"); Gramext.Snterm (Grammar.Entry.obj (row_field_list : 'row_field_list Grammar.Entry.e)); - Gramext.Stoken ("", "|]")], + Gramext.Stoken ("", "]")], Gramext.action (fun _ (rfl : 'row_field_list) _ _ (loc : int * int) -> (MLast.TyVrn (loc, rfl, Some (Some [])) : 'ctyp)); - [Gramext.Stoken ("", "[|"); Gramext.Stoken ("", ">"); + [Gramext.Stoken ("", "["); Gramext.Stoken ("", ">"); Gramext.Snterm (Grammar.Entry.obj (row_field_list : 'row_field_list Grammar.Entry.e)); - Gramext.Stoken ("", "|]")], + Gramext.Stoken ("", "]")], Gramext.action (fun _ (rfl : 'row_field_list) _ _ (loc : int * int) -> (MLast.TyVrn (loc, rfl, Some None) : 'ctyp)); - [Gramext.Stoken ("", "[|"); - Gramext.Slist0sep - (Gramext.Snterm - (Grammar.Entry.obj (row_field : 'row_field Grammar.Entry.e)), - Gramext.Stoken ("", "|")); - Gramext.Stoken ("", "|]")], + [Gramext.Stoken ("", "["); Gramext.Stoken ("", "="); + Gramext.Snterm + (Grammar.Entry.obj + (row_field_list : 'row_field_list Grammar.Entry.e)); + Gramext.Stoken ("", "]")], Gramext.action - (fun _ (rfl : 'row_field list) _ (loc : int * int) -> + (fun _ (rfl : 'row_field_list) _ _ (loc : int * int) -> (MLast.TyVrn (loc, rfl, None) : 'ctyp))]]; Grammar.Entry.obj (row_field_list : 'row_field_list Grammar.Entry.e), None, [None, None, - [[Gramext.Slist1sep + [[Gramext.Slist0sep (Gramext.Snterm (Grammar.Entry.obj (row_field : 'row_field Grammar.Entry.e)), Gramext.Stoken ("", "|"))], @@ -2473,6 +2522,67 @@ Grammar.extend [[], Gramext.action (fun (loc : int * int) -> (false : 'virtual_flag)); [Gramext.Stoken ("", "virtual")], Gramext.action (fun _ (loc : int * int) -> (true : 'virtual_flag))]]; + Grammar.Entry.obj (ctyp : 'ctyp Grammar.Entry.e), + Some (Gramext.Level "simple"), + [None, None, + [[Gramext.Stoken ("", "[|"); + Gramext.Snterm + (Grammar.Entry.obj + (warning_variant : 'warning_variant Grammar.Entry.e)); + Gramext.Stoken ("", "<"); + Gramext.Snterm + (Grammar.Entry.obj + (row_field_list : 'row_field_list Grammar.Entry.e)); + Gramext.Stoken ("", ">"); + Gramext.Slist1 + (Gramext.Snterm + (Grammar.Entry.obj (name_tag : 'name_tag Grammar.Entry.e))); + Gramext.Stoken ("", "|]")], + Gramext.action + (fun _ (ntl : 'name_tag list) _ (rfl : 'row_field_list) _ _ _ + (loc : int * int) -> + (MLast.TyVrn (loc, rfl, Some (Some ntl)) : 'ctyp)); + [Gramext.Stoken ("", "[|"); + Gramext.Snterm + (Grammar.Entry.obj + (warning_variant : 'warning_variant Grammar.Entry.e)); + Gramext.Stoken ("", "<"); + Gramext.Snterm + (Grammar.Entry.obj + (row_field_list : 'row_field_list Grammar.Entry.e)); + Gramext.Stoken ("", "|]")], + Gramext.action + (fun _ (rfl : 'row_field_list) _ _ _ (loc : int * int) -> + (MLast.TyVrn (loc, rfl, Some (Some [])) : 'ctyp)); + [Gramext.Stoken ("", "[|"); + Gramext.Snterm + (Grammar.Entry.obj + (warning_variant : 'warning_variant Grammar.Entry.e)); + Gramext.Stoken ("", ">"); + Gramext.Snterm + (Grammar.Entry.obj + (row_field_list : 'row_field_list Grammar.Entry.e)); + Gramext.Stoken ("", "|]")], + Gramext.action + (fun _ (rfl : 'row_field_list) _ _ _ (loc : int * int) -> + (MLast.TyVrn (loc, rfl, Some None) : 'ctyp)); + [Gramext.Stoken ("", "[|"); + Gramext.Snterm + (Grammar.Entry.obj + (warning_variant : 'warning_variant Grammar.Entry.e)); + Gramext.Snterm + (Grammar.Entry.obj + (row_field_list : 'row_field_list Grammar.Entry.e)); + Gramext.Stoken ("", "|]")], + Gramext.action + (fun _ (rfl : 'row_field_list) _ _ (loc : int * int) -> + (MLast.TyVrn (loc, rfl, None) : 'ctyp))]]; + Grammar.Entry.obj (warning_variant : 'warning_variant Grammar.Entry.e), + None, + [None, None, + [[], + Gramext.action + (fun (loc : int * int) -> (warn_variant () : 'warning_variant))]]; Grammar.Entry.obj (expr : 'expr Grammar.Entry.e), Some (Gramext.Level "top"), [None, None, @@ -2533,7 +2643,8 @@ Grammar.extend [None, None, [[], Gramext.action - (fun (loc : int * int) -> (warning_seq () : 'warning_sequence))]]]);; + (fun (loc : int * int) -> + (warn_sequence () : 'warning_sequence))]]]);; Grammar.extend (let _ = (interf : 'interf Grammar.Entry.e) diff --git a/camlp4/ocaml_src/meta/pa_rp.ml b/camlp4/ocaml_src/meta/pa_rp.ml index ebe7715f8..ad743e870 100644 --- a/camlp4/ocaml_src/meta/pa_rp.ml +++ b/camlp4/ocaml_src/meta/pa_rp.ml @@ -20,7 +20,8 @@ type spat_comp = | SpStr of MLast.loc * MLast.patt ;; type sexp_comp = - SeTrm of MLast.loc * MLast.expr | SeNtr of MLast.loc * MLast.expr + SeTrm of MLast.loc * MLast.expr + | SeNtr of MLast.loc * MLast.expr ;; let strm_n = "strm__";; @@ -159,7 +160,8 @@ let stream_pattern_component skont ckont = MLast.ExLet (loc, false, [p, e], skont) else if pattern_eq_expression - (MLast.PaApp (loc, MLast.PaUid (loc, "Some"), p)) skont then + (MLast.PaApp (loc, MLast.PaUid (loc, "Some"), p)) skont + then MLast.ExTry (loc, MLast.ExApp (loc, MLast.ExUid (loc, "Some"), e), [MLast.PaAcc diff --git a/camlp4/ocaml_src/meta/q_MLast.ml b/camlp4/ocaml_src/meta/q_MLast.ml index b23473bf8..82f1966f1 100644 --- a/camlp4/ocaml_src/meta/q_MLast.ml +++ b/camlp4/ocaml_src/meta/q_MLast.ml @@ -283,14 +283,24 @@ let mkassert _ e = let append_elem el e = Qast.Apply ("@", [el; Qast.List [e]]);; +let not_yet_warned_variant = ref true;; +let warn_variant () = + if !not_yet_warned_variant then + begin + not_yet_warned_variant := false; + Printf.eprintf "\ +*** warning: use of syntax of variants types deprecated since version 3.05\n"; + flush stderr + end +;; + let not_yet_warned = ref true;; -let warning_seq () = +let warn_sequence () = if !not_yet_warned then begin not_yet_warned := false; - Printf.eprintf - "\ -*** warning: use of old syntax for sequences in expr quotation\n"; + Printf.eprintf "\ +*** warning: use of syntax of sequences deprecated since version 3.01.1\n"; flush stderr end ;; @@ -372,11 +382,14 @@ Grammar.extend and field_expr_list : 'field_expr_list Grammar.Entry.e = grammar_entry_create "field_expr_list" and field : 'field Grammar.Entry.e = grammar_entry_create "field" + and typevar : 'typevar Grammar.Entry.e = grammar_entry_create "typevar" and row_field_list : 'row_field_list Grammar.Entry.e = grammar_entry_create "row_field_list" and row_field : 'row_field Grammar.Entry.e = grammar_entry_create "row_field" and name_tag : 'name_tag Grammar.Entry.e = grammar_entry_create "name_tag" + and warning_variant : 'warning_variant Grammar.Entry.e = + grammar_entry_create "warning_variant" and warning_sequence : 'warning_sequence Grammar.Entry.e = grammar_entry_create "warning_sequence" and sequence : 'sequence Grammar.Entry.e = grammar_entry_create "sequence" @@ -577,7 +590,7 @@ Grammar.extend Qast.Tuple [xx1; xx2; xx3] -> xx1, xx2, xx3 | _ -> match () with - _ -> raise (Match_failure ("q_MLast.ml", 9785, 9801)) + _ -> raise (Match_failure ("q_MLast.ml", 10073, 10089)) in Qast.Node ("StExc", [Qast.Loc; c; tl; b]) : 'str_item)); @@ -708,6 +721,11 @@ Grammar.extend Gramext.action (fun _ (mt : 'module_type) _ (loc : int * int) -> (mt : 'module_type)); + [Gramext.Stoken ("", "'"); + Gramext.Snterm (Grammar.Entry.obj (ident : 'ident Grammar.Entry.e))], + Gramext.action + (fun (i : 'ident) _ (loc : int * int) -> + (Qast.Node ("MtQuo", [Qast.Loc; i]) : 'module_type)); [Gramext.Snterm (Grammar.Entry.obj (a_LIDENT : 'a_LIDENT Grammar.Entry.e))], Gramext.action @@ -808,7 +826,7 @@ Grammar.extend Qast.Tuple [xx1; xx2; xx3] -> xx1, xx2, xx3 | _ -> match () with - _ -> raise (Match_failure ("q_MLast.ml", 11998, 12014)) + _ -> raise (Match_failure ("q_MLast.ml", 12344, 12360)) in Qast.Node ("SgExc", [Qast.Loc; c; tl]) : 'sig_item)); @@ -862,10 +880,10 @@ Grammar.extend (Grammar.Entry.obj (mod_ident : 'mod_ident Grammar.Entry.e)); Gramext.Stoken ("", "="); Gramext.Snterm - (Grammar.Entry.obj (module_type : 'module_type Grammar.Entry.e))], + (Grammar.Entry.obj (module_expr : 'module_expr Grammar.Entry.e))], Gramext.action - (fun (mt : 'module_type) _ (i : 'mod_ident) _ (loc : int * int) -> - (Qast.Node ("WcMod", [Qast.Loc; i; mt]) : 'with_constr)); + (fun (me : 'module_expr) _ (i : 'mod_ident) _ (loc : int * int) -> + (Qast.Node ("WcMod", [Qast.Loc; i; me]) : 'with_constr)); [Gramext.Stoken ("", "type"); Gramext.Snterm (Grammar.Entry.obj (mod_ident : 'mod_ident Grammar.Entry.e)); @@ -2096,6 +2114,23 @@ Grammar.extend Gramext.action (fun (t2 : 'ctyp) _ (t1 : 'ctyp) (loc : int * int) -> (Qast.Node ("TyAli", [Qast.Loc; t1; t2]) : 'ctyp))]; + None, Some Gramext.LeftA, + [[Gramext.Stoken ("", "!"); + Gramext.srules + [[Gramext.Slist1 + (Gramext.Snterm + (Grammar.Entry.obj (typevar : 'typevar Grammar.Entry.e)))], + Gramext.action + (fun (a : 'typevar list) (loc : int * int) -> + (Qast.List a : 'a_list)); + [Gramext.Snterm + (Grammar.Entry.obj (a_list : 'a_list Grammar.Entry.e))], + Gramext.action + (fun (a : 'a_list) (loc : int * int) -> (a : 'a_list))]; + Gramext.Stoken ("", "."); Gramext.Sself], + Gramext.action + (fun (t : 'ctyp) _ (pl : 'a_list) _ (loc : int * int) -> + (Qast.Node ("TyPol", [Qast.Loc; pl; t]) : 'ctyp))]; Some "arrow", Some Gramext.RightA, [[Gramext.Sself; Gramext.Stoken ("", "->"); Gramext.Sself], Gramext.action @@ -2565,7 +2600,21 @@ Grammar.extend (Grammar.Entry.obj (fun_binding : 'fun_binding Grammar.Entry.e))], Gramext.action (fun (fb : 'fun_binding) (l : 'label) _ (loc : int * int) -> - (Qast.Node ("CrMth", [Qast.Loc; l; Qast.Bool false; fb]) : + (Qast.Node + ("CrMth", + [Qast.Loc; l; Qast.Bool false; fb; Qast.Option None]) : + 'class_str_item)); + [Gramext.Stoken ("", "method"); + Gramext.Snterm (Grammar.Entry.obj (label : 'label Grammar.Entry.e)); + Gramext.Stoken ("", ":"); + Gramext.Snterm (Grammar.Entry.obj (ctyp : 'ctyp Grammar.Entry.e)); + Gramext.Stoken ("", "="); + Gramext.Snterm (Grammar.Entry.obj (expr : 'expr Grammar.Entry.e))], + Gramext.action + (fun (e : 'expr) _ (t : 'ctyp) _ (l : 'label) _ (loc : int * int) -> + (Qast.Node + ("CrMth", + [Qast.Loc; l; Qast.Bool false; e; Qast.Option (Some t)]) : 'class_str_item)); [Gramext.Stoken ("", "method"); Gramext.Stoken ("", "private"); Gramext.Snterm (Grammar.Entry.obj (label : 'label Grammar.Entry.e)); @@ -2573,7 +2622,20 @@ Grammar.extend (Grammar.Entry.obj (fun_binding : 'fun_binding Grammar.Entry.e))], Gramext.action (fun (fb : 'fun_binding) (l : 'label) _ _ (loc : int * int) -> - (Qast.Node ("CrMth", [Qast.Loc; l; Qast.Bool true; fb]) : + (Qast.Node + ("CrMth", [Qast.Loc; l; Qast.Bool true; fb; Qast.Option None]) : + 'class_str_item)); + [Gramext.Stoken ("", "method"); Gramext.Stoken ("", "private"); + Gramext.Snterm (Grammar.Entry.obj (label : 'label Grammar.Entry.e)); + Gramext.Stoken ("", ":"); + Gramext.Snterm (Grammar.Entry.obj (ctyp : 'ctyp Grammar.Entry.e)); + Gramext.Stoken ("", "="); + Gramext.Snterm (Grammar.Entry.obj (expr : 'expr Grammar.Entry.e))], + Gramext.action + (fun (e : 'expr) _ (t : 'ctyp) _ (l : 'label) _ _ (loc : int * int) -> + (Qast.Node + ("CrMth", + [Qast.Loc; l; Qast.Bool true; e; Qast.Option (Some t)]) : 'class_str_item)); [Gramext.Stoken ("", "method"); Gramext.Stoken ("", "virtual"); Gramext.Snterm (Grammar.Entry.obj (label : 'label Grammar.Entry.e)); @@ -2601,7 +2663,7 @@ Grammar.extend Qast.Tuple [xx1; xx2; xx3] -> xx1, xx2, xx3 | _ -> match () with - _ -> raise (Match_failure ("q_MLast.ml", 32764, 32780)) + _ -> raise (Match_failure ("q_MLast.ml", 33221, 33237)) in Qast.Node ("CrVal", [Qast.Loc; lab; mf; e]) : 'class_str_item)); @@ -2996,7 +3058,7 @@ Grammar.extend Qast.Tuple [xx1; xx2] -> xx1, xx2 | _ -> match () with - _ -> raise (Match_failure ("q_MLast.ml", 37331, 37347)) + _ -> raise (Match_failure ("q_MLast.ml", 38172, 38188)) in Qast.Node ("TyObj", [Qast.Loc; ml; v]) : 'ctyp)); @@ -3031,7 +3093,7 @@ Grammar.extend Qast.Tuple [xx1; xx2] -> xx1, xx2 | _ -> match () with - _ -> raise (Match_failure ("q_MLast.ml", 37678, 37694)) + _ -> raise (Match_failure ("q_MLast.ml", 38519, 38535)) in Qast.Tuple [Qast.Cons (f, ml); v] : 'meth_list))]]; @@ -3044,6 +3106,12 @@ Grammar.extend Gramext.action (fun (t : 'ctyp) _ (lab : 'a_LIDENT) (loc : int * int) -> (Qast.Tuple [lab; t] : 'field))]]; + Grammar.Entry.obj (typevar : 'typevar Grammar.Entry.e), None, + [None, None, + [[Gramext.Stoken ("", "'"); + Gramext.Snterm (Grammar.Entry.obj (ident : 'ident Grammar.Entry.e))], + Gramext.action + (fun (i : 'ident) _ (loc : int * int) -> (i : 'typevar))]]; Grammar.Entry.obj (clty_longident : 'clty_longident Grammar.Entry.e), None, [None, None, @@ -3091,7 +3159,7 @@ Grammar.extend Grammar.Entry.obj (ctyp : 'ctyp Grammar.Entry.e), Some (Gramext.Level "simple"), [None, None, - [[Gramext.Stoken ("", "[|"); Gramext.Stoken ("", "<"); + [[Gramext.Stoken ("", "["); Gramext.Stoken ("", "<"); Gramext.Snterm (Grammar.Entry.obj (row_field_list : 'row_field_list Grammar.Entry.e)); @@ -3107,7 +3175,7 @@ Grammar.extend (Grammar.Entry.obj (a_list : 'a_list Grammar.Entry.e))], Gramext.action (fun (a : 'a_list) (loc : int * int) -> (a : 'a_list))]; - Gramext.Stoken ("", "|]")], + Gramext.Stoken ("", "]")], Gramext.action (fun _ (ntl : 'a_list) _ (rfl : 'row_field_list) _ _ (loc : int * int) -> @@ -3115,11 +3183,11 @@ Grammar.extend ("TyVrn", [Qast.Loc; rfl; Qast.Option (Some (Qast.Option (Some ntl)))]) : 'ctyp)); - [Gramext.Stoken ("", "[|"); Gramext.Stoken ("", "<"); + [Gramext.Stoken ("", "["); Gramext.Stoken ("", "<"); Gramext.Snterm (Grammar.Entry.obj (row_field_list : 'row_field_list Grammar.Entry.e)); - Gramext.Stoken ("", "|]")], + Gramext.Stoken ("", "]")], Gramext.action (fun _ (rfl : 'row_field_list) _ _ (loc : int * int) -> (Qast.Node @@ -3127,40 +3195,31 @@ Grammar.extend [Qast.Loc; rfl; Qast.Option (Some (Qast.Option (Some (Qast.List []))))]) : 'ctyp)); - [Gramext.Stoken ("", "[|"); Gramext.Stoken ("", ">"); + [Gramext.Stoken ("", "["); Gramext.Stoken ("", ">"); Gramext.Snterm (Grammar.Entry.obj (row_field_list : 'row_field_list Grammar.Entry.e)); - Gramext.Stoken ("", "|]")], + Gramext.Stoken ("", "]")], Gramext.action (fun _ (rfl : 'row_field_list) _ _ (loc : int * int) -> (Qast.Node ("TyVrn", [Qast.Loc; rfl; Qast.Option (Some (Qast.Option None))]) : 'ctyp)); - [Gramext.Stoken ("", "[|"); - Gramext.srules - [[Gramext.Slist0sep - (Gramext.Snterm - (Grammar.Entry.obj (row_field : 'row_field Grammar.Entry.e)), - Gramext.Stoken ("", "|"))], - Gramext.action - (fun (a : 'row_field list) (loc : int * int) -> - (Qast.List a : 'a_list)); - [Gramext.Snterm - (Grammar.Entry.obj (a_list : 'a_list Grammar.Entry.e))], - Gramext.action - (fun (a : 'a_list) (loc : int * int) -> (a : 'a_list))]; - Gramext.Stoken ("", "|]")], + [Gramext.Stoken ("", "["); Gramext.Stoken ("", "="); + Gramext.Snterm + (Grammar.Entry.obj + (row_field_list : 'row_field_list Grammar.Entry.e)); + Gramext.Stoken ("", "]")], Gramext.action - (fun _ (rfl : 'a_list) _ (loc : int * int) -> + (fun _ (rfl : 'row_field_list) _ _ (loc : int * int) -> (Qast.Node ("TyVrn", [Qast.Loc; rfl; Qast.Option None]) : 'ctyp))]]; Grammar.Entry.obj (row_field_list : 'row_field_list Grammar.Entry.e), None, [None, None, [[Gramext.srules - [[Gramext.Slist1sep + [[Gramext.Slist0sep (Gramext.Snterm (Grammar.Entry.obj (row_field : 'row_field Grammar.Entry.e)), Gramext.Stoken ("", "|"))], @@ -3525,6 +3584,86 @@ Grammar.extend [Gramext.Stoken ("", "virtual")], Gramext.action (fun _ (loc : int * int) -> (Qast.Bool true : 'virtual_flag))]]; + Grammar.Entry.obj (ctyp : 'ctyp Grammar.Entry.e), + Some (Gramext.Level "simple"), + [None, None, + [[Gramext.Stoken ("", "[|"); + Gramext.Snterm + (Grammar.Entry.obj + (warning_variant : 'warning_variant Grammar.Entry.e)); + Gramext.Stoken ("", "<"); + Gramext.Snterm + (Grammar.Entry.obj + (row_field_list : 'row_field_list Grammar.Entry.e)); + Gramext.Stoken ("", ">"); + Gramext.srules + [[Gramext.Slist1 + (Gramext.Snterm + (Grammar.Entry.obj (name_tag : 'name_tag Grammar.Entry.e)))], + Gramext.action + (fun (a : 'name_tag list) (loc : int * int) -> + (Qast.List a : 'a_list)); + [Gramext.Snterm + (Grammar.Entry.obj (a_list : 'a_list Grammar.Entry.e))], + Gramext.action + (fun (a : 'a_list) (loc : int * int) -> (a : 'a_list))]; + Gramext.Stoken ("", "|]")], + Gramext.action + (fun _ (ntl : 'a_list) _ (rfl : 'row_field_list) _ _ _ + (loc : int * int) -> + (Qast.Node + ("TyVrn", + [Qast.Loc; rfl; Qast.Option (Some (Qast.Option (Some ntl)))]) : + 'ctyp)); + [Gramext.Stoken ("", "[|"); + Gramext.Snterm + (Grammar.Entry.obj + (warning_variant : 'warning_variant Grammar.Entry.e)); + Gramext.Stoken ("", "<"); + Gramext.Snterm + (Grammar.Entry.obj + (row_field_list : 'row_field_list Grammar.Entry.e)); + Gramext.Stoken ("", "|]")], + Gramext.action + (fun _ (rfl : 'row_field_list) _ _ _ (loc : int * int) -> + (Qast.Node + ("TyVrn", + [Qast.Loc; rfl; + Qast.Option (Some (Qast.Option (Some (Qast.List []))))]) : + 'ctyp)); + [Gramext.Stoken ("", "[|"); + Gramext.Snterm + (Grammar.Entry.obj + (warning_variant : 'warning_variant Grammar.Entry.e)); + Gramext.Stoken ("", ">"); + Gramext.Snterm + (Grammar.Entry.obj + (row_field_list : 'row_field_list Grammar.Entry.e)); + Gramext.Stoken ("", "|]")], + Gramext.action + (fun _ (rfl : 'row_field_list) _ _ _ (loc : int * int) -> + (Qast.Node + ("TyVrn", + [Qast.Loc; rfl; Qast.Option (Some (Qast.Option None))]) : + 'ctyp)); + [Gramext.Stoken ("", "[|"); + Gramext.Snterm + (Grammar.Entry.obj + (warning_variant : 'warning_variant Grammar.Entry.e)); + Gramext.Snterm + (Grammar.Entry.obj + (row_field_list : 'row_field_list Grammar.Entry.e)); + Gramext.Stoken ("", "|]")], + Gramext.action + (fun _ (rfl : 'row_field_list) _ _ (loc : int * int) -> + (Qast.Node ("TyVrn", [Qast.Loc; rfl; Qast.Option None]) : + 'ctyp))]]; + Grammar.Entry.obj (warning_variant : 'warning_variant Grammar.Entry.e), + None, + [None, None, + [[], + Gramext.action + (fun (loc : int * int) -> (warn_variant () : 'warning_variant))]]; Grammar.Entry.obj (expr : 'expr Grammar.Entry.e), Some (Gramext.Level "top"), [None, None, @@ -3611,7 +3750,7 @@ Grammar.extend [None, None, [[], Gramext.action - (fun (loc : int * int) -> (warning_seq () : 'warning_sequence))]]; + (fun (loc : int * int) -> (warn_sequence () : 'warning_sequence))]]; Grammar.Entry.obj (sequence : 'sequence Grammar.Entry.e), None, [None, None, [[Gramext.Stoken ("ANTIQUOT", "list")], diff --git a/camlp4/ocaml_src/odyl/.depend b/camlp4/ocaml_src/odyl/.depend index b63c10b0b..c09099d3e 100644 --- a/camlp4/ocaml_src/odyl/.depend +++ b/camlp4/ocaml_src/odyl/.depend @@ -1,6 +1,4 @@ -odyl_main.cmo: $(OTOP)/otherlibs/dynlink/dynlink.cmi odyl_config.cmo \ - odyl_main.cmi -odyl_main.cmx: odyl_config.cmx \ - odyl_main.cmi +odyl_main.cmo: odyl_config.cmo odyl_main.cmi +odyl_main.cmx: odyl_config.cmx odyl_main.cmi odyl.cmo: odyl_config.cmo odyl_main.cmi odyl.cmx: odyl_config.cmx odyl_main.cmx diff --git a/camlp4/ocaml_src/odyl/odyl.ml b/camlp4/ocaml_src/odyl/odyl.ml index 4a6749503..096e13eeb 100644 --- a/camlp4/ocaml_src/odyl/odyl.ml +++ b/camlp4/ocaml_src/odyl/odyl.ml @@ -30,7 +30,8 @@ let apply_load () = else if s = "--" then begin incr i; stop := true; () end else if String.length s > 0 && s.[0] == '-' then stop := true else if - Filename.check_suffix s ".cmo" || Filename.check_suffix s ".cma" then + Filename.check_suffix s ".cmo" || Filename.check_suffix s ".cma" + then begin Odyl_main.loadfile s; incr i end else stop := true done diff --git a/camlp4/ocaml_src/odyl/odyl_main.ml b/camlp4/ocaml_src/odyl/odyl_main.ml index 0d6bc968b..6fbdb1490 100644 --- a/camlp4/ocaml_src/odyl/odyl_main.ml +++ b/camlp4/ocaml_src/odyl/odyl_main.ml @@ -24,8 +24,8 @@ let first_arg_no_load () = | "-where" -> loop (i + 1) | "--" -> i + 1 | s -> - if Filename.check_suffix s ".cmo" || - Filename.check_suffix s ".cma" then + if Filename.check_suffix s ".cmo" || Filename.check_suffix s ".cma" + then loop (i + 1) else i else i |