HongboZhang avatar HongboZhang committed 8154b59

make Register a functor, and put it nested in PreCast

Comments (0)

Files changed (8)

camlp4/Camlp4/PreCast.ml

   module DumpCamlp4Ast = Printers.DumpCamlp4Ast.Make Syntax;
   module Null = Printers.Null.Make Syntax;
 end;
+module FilterSyntax = struct
+  include Syntax;
+  module AstFilters = AstFilters;
+end ;
+module Register = Register.Make FilterSyntax;

camlp4/Camlp4/PreCast.mli

   : Sig.Grammar.Static with module Loc = Loc and module Token = Lexer.Token;
 
 module MakeSyntax (U : sig end) : Sig.Syntax;
+
+module FilterSyntax: Sig.FilterSyntax;  
+module Register:(Sig.Register FilterSyntax).S;

camlp4/Camlp4/Register.ml

  * - Nicolas Pouillard: refactoring
  *)
 
+module Make (Syntax:Sig.FilterSyntax) = struct
 module PP = Printers;
-open PreCast;
+(* open PreCast; *)
 
 type parser_fun 'a =
-  ?directive_handler:('a -> option 'a) -> PreCast.Loc.t -> Stream.t char -> 'a;
+  ?directive_handler:('a -> option 'a) -> Syntax.Loc.t -> Stream.t char -> 'a;
 
 type printer_fun 'a =
   ?input_file:string -> ?output_file:string -> 'a -> unit;
   declare_dyn_module Id.name (fun _ -> let module M = Maker Syntax in ());
 end;
 
-module Printer
+module PrinterPlugin
   (Id : Sig.Id) (Maker : functor (Syn : Sig.Syntax)
                                 -> (Sig.Printer Syn.Ast).S) =
 struct
 end;
 
 module OCamlPreCastPrinter
-  (Id : Sig.Id) (P : (Sig.Printer PreCast.Ast).S) =
+  (Id : Sig.Id) (P : (Sig.Printer Syntax.Ast).S) =
 struct
   declare_dyn_module Id.name (fun _ ->
     register_printer P.print_implem P.print_interf);
 end;
 
-module Parser
+module ParserPlugin
   (Id : Sig.Id) (Maker : functor (Ast : Sig.Ast)
                                 -> (Sig.Parser Ast).S) =
 struct
   declare_dyn_module Id.name (fun _ ->
-    let module M = Maker PreCast.Ast in
+    let module M = Maker Syntax.Ast in
     register_parser M.parse_implem M.parse_interf);
 end;
 
                                 -> (Sig.Parser Ast).S) =
 struct
   declare_dyn_module Id.name (fun _ ->
-    let module M = Maker PreCast.Ast in
+    let module M = Maker Syntax.Ast in
     register_parser M.parse_implem M.parse_interf);
 end;
 
 module OCamlPreCastParser
-  (Id : Sig.Id) (P : (Sig.Parser PreCast.Ast).S) =
+  (Id : Sig.Id) (P : (Sig.Parser Syntax.Ast).S) =
 struct
   declare_dyn_module Id.name (fun _ ->
     register_parser P.parse_implem P.parse_interf);
 module AstFilter
   (Id : Sig.Id) (Maker : functor (F : Sig.AstFilters) -> sig end) =
 struct
-  declare_dyn_module Id.name (fun _ -> let module M = Maker AstFilters in ());
+  declare_dyn_module Id.name (fun _ -> let module M = Maker Syntax.AstFilters in ());
 end;
 
 sig_item_parser.val := Syntax.parse_interf;
 str_item_parser.val := Syntax.parse_implem;
 
 module CurrentParser = struct
-  module Ast = Ast;
+  module Ast = Syntax.Ast;
   value parse_interf ?directive_handler loc strm =
     sig_item_parser.val ?directive_handler loc strm;
   value parse_implem ?directive_handler loc strm =
 end;
 
 module CurrentPrinter = struct
-  module Ast = Ast;
+  module Ast = Syntax.Ast;
   value print_interf ?input_file ?output_file ast =
     sig_item_printer.val ?input_file ?output_file ast;
   value print_implem ?input_file ?output_file ast =
   let module M = OCamlPrinter PP.DumpOCamlAst.Id PP.DumpOCamlAst.Make in ();
 
 value enable_dump_camlp4_ast_printer () =
-  let module M = Printer PP.DumpCamlp4Ast.Id PP.DumpCamlp4Ast.Make in ();
+  let module M = PrinterPlugin PP.DumpCamlp4Ast.Id PP.DumpCamlp4Ast.Make in ();
 
 value enable_null_printer () =
-  let module M = Printer PP.Null.Id PP.Null.Make in ();
+  let module M = PrinterPlugin PP.Null.Id PP.Null.Make in ();
+end;

camlp4/Camlp4/Register.mli

-(****************************************************************************)
-(*                                                                          *)
-(*                                   OCaml                                  *)
-(*                                                                          *)
-(*                            INRIA Rocquencourt                            *)
-(*                                                                          *)
-(*  Copyright  2006   Institut National de Recherche  en  Informatique et   *)
-(*  en Automatique.  All rights reserved.  This file is distributed under   *)
-(*  the terms of the GNU Library General Public License, with the special   *)
-(*  exception on linking described in LICENSE at the top of the OCaml       *)
-(*  source tree.                                                            *)
-(*                                                                          *)
-(****************************************************************************)
 
-(* Authors:
- * - Daniel de Rauglaudre: initial version
- * - Nicolas Pouillard: refactoring
- *)
-
-module Plugin
-  (Id : Sig.Id) (Plugin : functor (Unit : sig end) -> sig end) : sig end;
-
-module SyntaxPlugin
-  (Id : Sig.Id) (SyntaxPlugin : functor (Syn : Sig.Syntax) -> sig end) :
-    sig end;
-
-module SyntaxExtension
-  (Id : Sig.Id) (SyntaxExtension : Sig.SyntaxExtension) : sig end;
-
-module OCamlSyntaxExtension
-  (Id : Sig.Id)
-  (SyntaxExtension : functor (Syntax : Sig.Camlp4Syntax) -> Sig.Camlp4Syntax)
-  : sig end;
-
-(** {6 Registering Parsers} *)
-
-type parser_fun 'a =
-  ?directive_handler:('a -> option 'a) -> PreCast.Loc.t -> Stream.t char -> 'a;
-
-value register_str_item_parser : parser_fun PreCast.Ast.str_item -> unit;
-value register_sig_item_parser : parser_fun PreCast.Ast.sig_item -> unit;
-value register_parser : parser_fun PreCast.Ast.str_item -> parser_fun PreCast.Ast.sig_item -> unit;
-value current_parser : unit -> (parser_fun PreCast.Ast.str_item * parser_fun PreCast.Ast.sig_item);
-
-module Parser
-  (Id : Sig.Id) (Maker : functor (Ast : Sig.Ast) -> (Sig.Parser Ast).S) : sig end;
-
-module OCamlParser
-  (Id : Sig.Id) (Maker : functor (Ast : Sig.Camlp4Ast) -> (Sig.Parser Ast).S) : sig end;
-
-module OCamlPreCastParser
-  (Id : Sig.Id) (Parser : (Sig.Parser PreCast.Ast).S) : sig end;
-
-(** {6 Registering Printers} *)
-
-type printer_fun 'a =
-  ?input_file:string -> ?output_file:string -> 'a -> unit;
-
-value register_str_item_printer : printer_fun PreCast.Ast.str_item -> unit;
-value register_sig_item_printer : printer_fun PreCast.Ast.sig_item -> unit;
-value register_printer : printer_fun PreCast.Ast.str_item -> printer_fun PreCast.Ast.sig_item -> unit;
-value current_printer : unit -> (printer_fun PreCast.Ast.str_item * printer_fun PreCast.Ast.sig_item);
-
-module Printer
-  (Id : Sig.Id)
-  (Maker : functor (Syn : Sig.Syntax) -> (Sig.Printer Syn.Ast).S) :
-    sig end;
-
-module OCamlPrinter
-  (Id : Sig.Id)
-  (Maker : functor (Syn : Sig.Camlp4Syntax) -> (Sig.Printer Syn.Ast).S) :
-    sig end;
-
-module OCamlPreCastPrinter
-  (Id : Sig.Id) (Printer : (Sig.Printer PreCast.Ast).S) :
-    sig end;
-
-(** {6 Registering Filters} *)
-
-module AstFilter
-  (Id : Sig.Id) (Maker : functor (F : Sig.AstFilters) -> sig end) : sig end;
-
-value declare_dyn_module : string -> (unit -> unit) -> unit;
-value iter_and_take_callbacks : ((string * (unit -> unit)) -> unit) -> unit;
-value loaded_modules : ref (list string);
-
-module CurrentParser : (Sig.Parser PreCast.Ast).S;
-module CurrentPrinter : (Sig.Printer PreCast.Ast).S;
-
-value enable_ocaml_printer : unit -> unit;
-value enable_ocamlr_printer : unit -> unit;
-(* value enable_ocamlrr_printer : unit -> unit; *)
-value enable_null_printer : unit -> unit;
-value enable_dump_ocaml_ast_printer : unit -> unit;
-value enable_dump_camlp4_ast_printer : unit -> unit;
+module Make (Syntax:Sig.FilterSyntax): (Sig.Register Syntax).S;

camlp4/Camlp4/Sig.ml

     module Action : Action;
     module Token  : Token with module Loc = Loc;
 
-    type gram;
+    type gram =
+        { gfilter         : Token.Filter.t;
+          gkeywords       : Hashtbl.t string (ref int);
+          glexer          : Loc.t -> Stream.t char -> Stream.t (Token.t * Loc.t);
+          warning_verbose : ref bool;
+          error_verbose   : ref bool };
+      
     type internal_entry;
     type tree;
 
     include Structure;
 
     (** Whether trace parser or not *)
-    value trace_parser : ref bool;    
+    value trace_parser: ref bool;
+
+    value gram: gram;
 
     module Entry : sig
       (** The abstract type of grammar entries. The type parameter is the type
                                 and module Token          = Syn.Token
                                 and module Gram           = Syn.Gram
                                 and module Quotation      = Syn.Quotation);
+module type FilterSyntax = sig
+  include Camlp4Syntax;
+  module AstFilters:AstFilters with module Ast = Ast; 
+end ;
+  
+module Register (Syntax:FilterSyntax)= struct
+  module type S = sig
+    module Plugin
+  (Id : Id) (Plugin : functor (Unit : sig end) -> sig end) : sig end;
+
+module SyntaxPlugin
+  (Id : Id) (SyntaxPlugin : functor (Syn : Syntax) -> sig end) :
+    sig end;
+
+module SyntaxExtension
+  (Id : Id) (SyntaxExtension : SyntaxExtension) : sig end;
+
+module OCamlSyntaxExtension
+  (Id : Id)
+  (SyntaxExtension : functor (Syntax : Camlp4Syntax) -> Camlp4Syntax)
+  : sig end;
+
+(** {6 Registering Parsers} *)
+
+type parser_fun 'a =
+  ?directive_handler:('a -> option 'a) -> Syntax.Loc.t -> Stream.t char -> 'a;
+
+value register_str_item_parser : parser_fun Syntax.Ast.str_item -> unit;
+value register_sig_item_parser : parser_fun Syntax.Ast.sig_item -> unit;
+value register_parser : parser_fun Syntax.Ast.str_item -> parser_fun Syntax.Ast.sig_item -> unit;
+value current_parser : unit -> (parser_fun Syntax.Ast.str_item * parser_fun Syntax.Ast.sig_item);
+
+module ParserPlugin
+  (Id : Id) (Maker : functor (Ast : Ast) -> (Parser Ast).S) : sig end;
+
+module OCamlParser
+  (Id : Id) (Maker : functor (Ast : Camlp4Ast) -> (Parser Ast).S) : sig end;
+
+module OCamlPreCastParser
+  (Id : Id) (Parser : (Parser Syntax.Ast).S) : sig end;
+
+(** {6 Registering Printers} *)
+
+type printer_fun 'a =
+  ?input_file:string -> ?output_file:string -> 'a -> unit;
+
+value register_str_item_printer : printer_fun Syntax.Ast.str_item -> unit;
+value register_sig_item_printer : printer_fun Syntax.Ast.sig_item -> unit;
+value register_printer : printer_fun Syntax.Ast.str_item -> printer_fun Syntax.Ast.sig_item -> unit;
+value current_printer : unit -> (printer_fun Syntax.Ast.str_item * printer_fun Syntax.Ast.sig_item);
+
+module PrinterPlugin
+  (Id : Id)
+  (Maker : functor (Syn : Syntax) -> (Printer Syn.Ast).S) :
+    sig end;
+
+module OCamlPrinter
+  (Id : Id)
+  (Maker : functor (Syn : Camlp4Syntax) -> (Printer Syn.Ast).S) :
+    sig end;
+
+module OCamlPreCastPrinter
+  (Id : Id) (Printer : (Printer Syntax.Ast).S) :
+    sig end;
+
+(** {6 Registering Filters} *)
+
+module AstFilter
+  (Id : Id) (Maker : functor (F : AstFilters) -> sig end) : sig end;
+
+value declare_dyn_module : string -> (unit -> unit) -> unit;
+value iter_and_take_callbacks : ((string * (unit -> unit)) -> unit) -> unit;
+value loaded_modules : ref (list string);
+
+module CurrentParser : (Parser Syntax.Ast).S;
+module CurrentPrinter : (Printer Syntax.Ast).S;
+
+value enable_ocaml_printer : unit -> unit;
+value enable_ocamlr_printer : unit -> unit;
+(* value enable_ocamlrr_printer : unit -> unit; *)
+value enable_null_printer : unit -> unit;
+value enable_dump_ocaml_ast_printer : unit -> unit;
+value enable_dump_camlp4_ast_printer : unit -> unit;
+  end;
+end ;

camlp4/Camlp4/Struct/Lexer.mll

     | "<<" (symbolchar as p)? (quotchar* as beginning)
       { if quotations c
         then (move_start_p (-String.length beginning);
+              (* FIXME: partial application *)
               Stack.push p opt_char;
               let len = 2 + opt_char_len p in 
               mk_quotation quotation c "" "" len len;

camlp4/Camlp4Parsers/Camlp4AstLoader.ml

 
 end;
 
-let module M = Camlp4.Register.Parser Id Make in ();
+let module M = Camlp4.PreCast.Register.ParserPlugin Id Make in ();
 # -*- Mode:Shell-script -*-
 ocamlbuild -docflags '-I bytecomp, -keep-code' typing.docdir/index.html
+ocamlbuild -docflags '-I bytecomp' typing.docdir/index.dot
 # ocamlbuild -docflags '-keep-code' parsing.docdir/index.html
+
+ocamlbuild -docflags '-I toplevel, -keep-code' camlp4.docdir/index.html
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.